From d80486abd0e4b79b1d1bb9206fe74149f61a9bae Mon Sep 17 00:00:00 2001 From: Philipp Grathwohl Date: Sat, 4 Dec 2021 11:45:53 +0100 Subject: [PATCH 1/4] Revert to python v3.7 to increase build time on gh actions --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 639e820..fa4c692 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ RUN apk --no-cache add curl && mkdir /downloads # Download installation files RUN curl https://github.com/avollkopf/craftbeerpi4-ui/archive/main.zip -L -o ./downloads/cbpi-ui.zip -FROM python:3.9 +FROM python:3.7 as base # Install dependencies RUN apt-get update \ From 47271620025f997b9a1aafa1c0bccb84532f9946 Mon Sep 17 00:00:00 2001 From: Philipp Grathwohl Date: Sat, 4 Dec 2021 12:09:46 +0100 Subject: [PATCH 2/4] Increase caching potential of docker image --- .dockerignore | 50 +++++++++++++++++++++++++++++++++++++ .github/workflows/build.yml | 1 + Dockerfile | 1 + 3 files changed, 52 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..615f5ad --- /dev/null +++ b/.dockerignore @@ -0,0 +1,50 @@ +# Docker +docker-compose.yml +.docker + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg +**/__pycache__ +**/*.py[cod] + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.cache +nosetests.xml +coverage.xml + +# Virtual environment +.env/ +.venv/ +venv/ +venv3/ + +*.cover +*.log +.git +.mypy_cache +.pytest_cache +.hypothesis +.idea + +**/*.swp \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0de6dcb..abf5443 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -91,6 +91,7 @@ jobs: context: . file: ./Dockerfile platforms: linux/amd64,linux/arm64 + target: deploy push: ${{ steps.prep.outputs.publish_image }} tags: ${{ steps.prep.outputs.tags }} labels: | diff --git a/Dockerfile b/Dockerfile index fa4c692..bc14714 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,6 +36,7 @@ RUN python3 -m pip install --no-cache-dir --upgrade pip setuptools wheel COPY --chown=craftbeerpi ./requirements.txt /cbpi-src/ RUN pip3 install --no-cache-dir -r /cbpi-src/requirements.txt +FROM base as deploy # Install craftbeerpi from source COPY --chown=craftbeerpi . /cbpi-src RUN pip3 install --no-cache-dir /cbpi-src From 4faea7ed2072cda675c596412bf71c69b39ccaa6 Mon Sep 17 00:00:00 2001 From: Philipp Grathwohl Date: Sat, 4 Dec 2021 12:23:56 +0100 Subject: [PATCH 3/4] Determin the proper image for caching for the build --- .github/workflows/build.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index abf5443..77c7091 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -54,11 +54,17 @@ jobs: PUBLISH_IMAGE=false TAGS="${{ env.image-name }}:dev" + # Define the image that will be used as a cached image + # to speed up the build process + BUILD_CACHE_IMAGE_NAME=${TAGS} + if [[ $GITHUB_REF_NAME == master ]] || [[ $GITHUB_REF_NAME == main ]]; then # when building master/main use :latest tag and the version number # from the cbpi/__init__.py file VERSION=$(grep -o -E "(([0-9]{1,2}[.]?){3}[0-9]+)" cbpi/__init__.py) - TAGS="${{ env.image-name }}:latest,${{ env.image-name }}:v${VERSION}" + LATEST_IMAGE=${{ env.image-name }}:latest + BUILD_CACHE_IMAGE_NAME=${LATEST_IMAGE} + TAGS="${LATEST_IMAGE},${{ env.image-name }}:v${VERSION}" PUBLISH_IMAGE=true elif [[ $GITHUB_REF_NAME == development ]]; then PUBLISH_IMAGE=true @@ -67,6 +73,7 @@ jobs: # Set output parameters. echo ::set-output name=tags::${TAGS} echo ::set-output name=publish_image::${PUBLISH_IMAGE} + echo ::set-output name=build_cache_image_name::${BUILD_CACHE_IMAGE_NAME} - name: Set up QEMU uses: docker/setup-qemu-action@master From 48df3cdffa50ff3df50f63f80a9bb3eb0232f269 Mon Sep 17 00:00:00 2001 From: Philipp Grathwohl Date: Sat, 4 Dec 2021 12:26:48 +0100 Subject: [PATCH 4/4] Use cache to increase build performance --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 77c7091..7dbc85d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -101,6 +101,8 @@ jobs: target: deploy push: ${{ steps.prep.outputs.publish_image }} tags: ${{ steps.prep.outputs.tags }} + cache-from: type=registry,ref=${{ steps.prep.outputs.build_cache_image_name }} + cache-to: type=inline labels: | org.opencontainers.image.title=${{ github.event.repository.name }} org.opencontainers.image.description=${{ github.event.repository.description }}