From c12e985f817a83e6faf1beb88a771b802df780b9 Mon Sep 17 00:00:00 2001 From: Ween Jiann <16207788+lwj5@users.noreply.github.com> Date: Sat, 10 Jul 2021 11:20:09 +0800 Subject: [PATCH] Refactor Github workflow files (#382) * Refactor * Add sha * Add missing dash --- .github/workflows/build-image-v4.yaml | 57 ++++++++++++++++ .github/workflows/build-image-v4.yml | 67 ------------------- ...build-image-v5.yml => build-image-v5.yaml} | 4 +- .../{publish-image.yml => publish-image.yaml} | 4 +- .../{release.yaml => release-chart.yaml} | 0 .../{charts.yaml => test-charts.yaml} | 0 alpine/4/cache_buster | 1 + 7 files changed, 62 insertions(+), 71 deletions(-) create mode 100644 .github/workflows/build-image-v4.yaml delete mode 100644 .github/workflows/build-image-v4.yml rename .github/workflows/{build-image-v5.yml => build-image-v5.yaml} (96%) rename .github/workflows/{publish-image.yml => publish-image.yaml} (98%) rename .github/workflows/{release.yaml => release-chart.yaml} (100%) rename .github/workflows/{charts.yaml => test-charts.yaml} (100%) create mode 100644 alpine/4/cache_buster diff --git a/.github/workflows/build-image-v4.yaml b/.github/workflows/build-image-v4.yaml new file mode 100644 index 0000000..8d555fb --- /dev/null +++ b/.github/workflows/build-image-v4.yaml @@ -0,0 +1,57 @@ +name: Build Container Image v4 + +# 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: + pull_request: + paths: + - "alpine/4/**" + push: + paths: + - "alpine/4/**" + branches: + - master + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + with: + platforms: all + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-4-${{ hashFiles('alpine/5/cache_buster') }}-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx-4-${{ hashFiles('alpine/5/cache_buster') }}- + + - name: Build + id: docker_build + uses: docker/build-push-action@v2 + with: + builder: ${{ steps.buildx.outputs.name }} + context: ./alpine/4/ + build-args: INVOICENINJA_VERSION=4.5.42 + target: prod + platforms: linux/amd64,linux/arm64 + tags: invoiceninja/invoiceninja:cache + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new + + - name: Move cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache diff --git a/.github/workflows/build-image-v4.yml b/.github/workflows/build-image-v4.yml deleted file mode 100644 index 72b8ee7..0000000 --- a/.github/workflows/build-image-v4.yml +++ /dev/null @@ -1,67 +0,0 @@ -name: Build Container Image - -# 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: - paths: - - "alpine/4/**" - -jobs: - docker: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - - 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: Set up QEMU - uses: docker/setup-qemu-action@v1 - with: - platforms: all - - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v1 - - - name: Cache Docker layers - uses: actions/cache@v2 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ hashFiles('alpine/**') }} - restore-keys: | - ${{ runner.os }}-buildx- - - - name: Build - id: docker_build - uses: docker/build-push-action@v2 - with: - builder: ${{ steps.buildx.outputs.name }} - context: ./alpine/${{ steps.prep.outputs.major }}/ - build-args: INVOICENINJA_VERSION=${{ steps.prep.outputs.version }} - target: prod - platforms: linux/amd64,linux/arm64 - 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 diff --git a/.github/workflows/build-image-v5.yml b/.github/workflows/build-image-v5.yaml similarity index 96% rename from .github/workflows/build-image-v5.yml rename to .github/workflows/build-image-v5.yaml index da3b6b9..b2eb6b5 100644 --- a/.github/workflows/build-image-v5.yml +++ b/.github/workflows/build-image-v5.yaml @@ -34,9 +34,9 @@ jobs: uses: actions/cache@v2 with: path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-5-${{ hashFiles('alpine/5/cache_buster') }} + key: ${{ runner.os }}-buildx-5-${{ hashFiles('alpine/5/cache_buster') }}-${{ github.sha }} restore-keys: | - ${{ runner.os }}-buildx-5-${{ hashFiles('alpine/5/cache_buster') }} + ${{ runner.os }}-buildx-5-${{ hashFiles('alpine/5/cache_buster') }}- - name: Build id: docker_build diff --git a/.github/workflows/publish-image.yml b/.github/workflows/publish-image.yaml similarity index 98% rename from .github/workflows/publish-image.yml rename to .github/workflows/publish-image.yaml index 9ae9843..a7a7d78 100644 --- a/.github/workflows/publish-image.yml +++ b/.github/workflows/publish-image.yaml @@ -48,9 +48,9 @@ jobs: uses: actions/cache@v2 with: path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ steps.prep.outputs.major }}-${{ hashFiles('alpine/${{ steps.prep.outputs.major }}/cache_buster') }} + key: ${{ runner.os }}-buildx-${{ steps.prep.outputs.major }}-${{ hashFiles('alpine/${{ steps.prep.outputs.major }}/cache_buster') }}-${{ github.sha }} restore-keys: | - ${{ runner.os }}-buildx-${{ steps.prep.outputs.major }}-${{ hashFiles('alpine/${{ steps.prep.outputs.major }}/cache_buster') }} + ${{ runner.os }}-buildx-${{ steps.prep.outputs.major }}-${{ hashFiles('alpine/${{ steps.prep.outputs.major }}/cache_buster') }}- - name: Login to DockerHub if: github.event_name != 'pull_request' diff --git a/.github/workflows/release.yaml b/.github/workflows/release-chart.yaml similarity index 100% rename from .github/workflows/release.yaml rename to .github/workflows/release-chart.yaml diff --git a/.github/workflows/charts.yaml b/.github/workflows/test-charts.yaml similarity index 100% rename from .github/workflows/charts.yaml rename to .github/workflows/test-charts.yaml diff --git a/alpine/4/cache_buster b/alpine/4/cache_buster new file mode 100644 index 0000000..e38ef8f --- /dev/null +++ b/alpine/4/cache_buster @@ -0,0 +1 @@ +Fri Jul 2 7:33:22 +00 2021 \ No newline at end of file