Reshuffle Dockerfile to optimise caching (#306)

* Refactor alpine folder

* Rearrange Dockerfile

* Updated build_push.yml for testing

* Updated build_push.yml for production

* Added IS_DOCKER env

* Added target to build_push.yml
This commit is contained in:
Ween Jiann
2021-03-25 22:05:47 +08:00
committed by GitHub
parent 176e2c96d6
commit 4ec70c8da6
4 changed files with 89 additions and 41 deletions

View File

@@ -1,36 +1,78 @@
name: Docker images
name: Publish Releases to Hub
# When its time to do a release do a full cross platform build for all supported
# architectures and push all of them to Docker Hub.
# Only trigger on semver shaped tags.
# Ref: https://github.com/metcalfc/docker-action-examples/blob/main/.github/workflows/release.yml
on:
push:
tags-ignore:
- "invoiceninja-*"
jobs:
deploy:
name: Build images
docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Checkout
uses: actions/checkout@v2
- name: Login to DockerHub
run: echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
- name: Prepare
id: prep
run: |
DOCKER_IMAGE=invoiceninja/invoiceninja
VERSION=edge
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
MAJOR="$(echo "${VERSION}" | cut -d. -f1)"
MINOR="$(echo "${VERSION}" | cut -d. -f2)"
TAGS="$TAGS,${DOCKER_IMAGE}:${MAJOR},${DOCKER_IMAGE}:${MAJOR}.${MINOR}"
if [[ $VERSION =~ ^5\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
TAGS="$TAGS,${DOCKER_IMAGE}:latest"
fi
echo ::set-output name=tags::${TAGS}
echo ::set-output name=version::${VERSION}
echo ::set-output name=major::${MAJOR}
- name: Get the latest tag
id: vars
run: echo ::set-output name=tag::$(echo ${GITHUB_REF:10})
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
with:
platforms: all
- name: Build image from alpine - v5
run: make build-alpine-v5 TAG="${{steps.vars.outputs.tag}}"
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Push alpine-based image - v5
run: make push-alpine-v5 TAG="${{steps.vars.outputs.tag}}"
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build image from alpine - v4
run: make build-alpine TAG="${{steps.vars.outputs.tag}}"
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Push alpine-based image - v4
run: make push-alpine TAG="${{steps.vars.outputs.tag}}"
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
builder: ${{ steps.buildx.outputs.name }}
context: ./
file: ./alpine/${{ steps.prep.outputs.major }}/Dockerfile
build-args: INVOICENINJA_VERSION=${{ steps.prep.outputs.version }}
target: prod
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.prep.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Logout from DockerHub
run: docker logout
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}