mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-28 17:54:15 +01:00
Merge pull request #17 from papauorg/feature/use-cache-to-increase-build-perf
Reduce build time for docker image on GitHub actions by using a cache
This commit is contained in:
commit
59a20fdccb
3 changed files with 63 additions and 2 deletions
50
.dockerignore
Normal file
50
.dockerignore
Normal file
|
@ -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
|
12
.github/workflows/build.yml
vendored
12
.github/workflows/build.yml
vendored
|
@ -54,11 +54,17 @@ jobs:
|
||||||
PUBLISH_IMAGE=false
|
PUBLISH_IMAGE=false
|
||||||
TAGS="${{ env.image-name }}:dev"
|
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
|
if [[ $GITHUB_REF_NAME == master ]] || [[ $GITHUB_REF_NAME == main ]]; then
|
||||||
# when building master/main use :latest tag and the version number
|
# when building master/main use :latest tag and the version number
|
||||||
# from the cbpi/__init__.py file
|
# from the cbpi/__init__.py file
|
||||||
VERSION=$(grep -o -E "(([0-9]{1,2}[.]?){3}[0-9]+)" cbpi/__init__.py)
|
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
|
PUBLISH_IMAGE=true
|
||||||
elif [[ $GITHUB_REF_NAME == development ]]; then
|
elif [[ $GITHUB_REF_NAME == development ]]; then
|
||||||
PUBLISH_IMAGE=true
|
PUBLISH_IMAGE=true
|
||||||
|
@ -67,6 +73,7 @@ jobs:
|
||||||
# Set output parameters.
|
# Set output parameters.
|
||||||
echo ::set-output name=tags::${TAGS}
|
echo ::set-output name=tags::${TAGS}
|
||||||
echo ::set-output name=publish_image::${PUBLISH_IMAGE}
|
echo ::set-output name=publish_image::${PUBLISH_IMAGE}
|
||||||
|
echo ::set-output name=build_cache_image_name::${BUILD_CACHE_IMAGE_NAME}
|
||||||
|
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@master
|
uses: docker/setup-qemu-action@master
|
||||||
|
@ -91,8 +98,11 @@ jobs:
|
||||||
context: .
|
context: .
|
||||||
file: ./Dockerfile
|
file: ./Dockerfile
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
|
target: deploy
|
||||||
push: ${{ steps.prep.outputs.publish_image }}
|
push: ${{ steps.prep.outputs.publish_image }}
|
||||||
tags: ${{ steps.prep.outputs.tags }}
|
tags: ${{ steps.prep.outputs.tags }}
|
||||||
|
cache-from: type=registry,ref=${{ steps.prep.outputs.build_cache_image_name }}
|
||||||
|
cache-to: type=inline
|
||||||
labels: |
|
labels: |
|
||||||
org.opencontainers.image.title=${{ github.event.repository.name }}
|
org.opencontainers.image.title=${{ github.event.repository.name }}
|
||||||
org.opencontainers.image.description=${{ github.event.repository.description }}
|
org.opencontainers.image.description=${{ github.event.repository.description }}
|
||||||
|
|
|
@ -3,7 +3,7 @@ RUN apk --no-cache add curl && mkdir /downloads
|
||||||
# Download installation files
|
# Download installation files
|
||||||
RUN curl https://github.com/avollkopf/craftbeerpi4-ui/archive/main.zip -L -o ./downloads/cbpi-ui.zip
|
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
|
# Install dependencies
|
||||||
RUN apt-get update \
|
RUN apt-get update \
|
||||||
|
@ -36,6 +36,7 @@ RUN python3 -m pip install --no-cache-dir --upgrade pip setuptools wheel
|
||||||
COPY --chown=craftbeerpi ./requirements.txt /cbpi-src/
|
COPY --chown=craftbeerpi ./requirements.txt /cbpi-src/
|
||||||
RUN pip3 install --no-cache-dir -r /cbpi-src/requirements.txt
|
RUN pip3 install --no-cache-dir -r /cbpi-src/requirements.txt
|
||||||
|
|
||||||
|
FROM base as deploy
|
||||||
# Install craftbeerpi from source
|
# Install craftbeerpi from source
|
||||||
COPY --chown=craftbeerpi . /cbpi-src
|
COPY --chown=craftbeerpi . /cbpi-src
|
||||||
RUN pip3 install --no-cache-dir /cbpi-src
|
RUN pip3 install --no-cache-dir /cbpi-src
|
||||||
|
|
Loading…
Reference in a new issue