From 46f72b56e8b8ba3a106ce6f6b760fb8433c19076 Mon Sep 17 00:00:00 2001 From: Lukas Gravley Date: Thu, 24 Jun 2021 10:19:42 -0500 Subject: [PATCH] Use GitHub Action cache (#1687) * maybe * buildx * fix order * make phar happy * have to use run * slashes * commands are hard * adding info * try load and push * only push * only load * better way * cleanup --- .automation/validate-docker-labels.sh | 9 ++++ .github/workflows/deploy-DEV-slim.yml | 52 ++++++++++++++---- .github/workflows/deploy-DEV-standard.yml | 53 +++++++++++++++---- .github/workflows/deploy-PROD-slim.yml | 25 +++++++++ .github/workflows/deploy-PROD-standard.yml | 25 +++++++++ .github/workflows/deploy-RELEASE-slim.yml | 27 +++++++++- .github/workflows/deploy-RELEASE-standard.yml | 25 +++++++++ Dockerfile | 4 +- Dockerfile-slim | 4 +- 9 files changed, 197 insertions(+), 27 deletions(-) diff --git a/.automation/validate-docker-labels.sh b/.automation/validate-docker-labels.sh index 58bc77b8..2a7600db 100755 --- a/.automation/validate-docker-labels.sh +++ b/.automation/validate-docker-labels.sh @@ -34,6 +34,15 @@ Header() { info "--------------------------------------------------" info "----- GitHub Actions validate docker labels ------" info "--------------------------------------------------" + + ################################## + # Print info on local containers # + ################################## + info "--------------------------------------------------" + info "Containers found locally:" + docker images + info "--------------------------------------------------" + } ################################################################################ #### Function ValidateLabel #################################################### diff --git a/.github/workflows/deploy-DEV-slim.yml b/.github/workflows/deploy-DEV-slim.yml index 5717b935..7b16c8b4 100644 --- a/.github/workflows/deploy-DEV-slim.yml +++ b/.github/workflows/deploy-DEV-slim.yml @@ -54,21 +54,53 @@ jobs: - name: Get current date run: echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> ${GITHUB_ENV} - ################################### - # Build image locally for testing # - ################################### + ######################## + # Setup Docker build X # + ######################## + - name: Setup BuildX + uses: docker/setup-buildx-action@v1.3.0 - ########################################## + ################ + # Docker cache # + ################ + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-single-buildx-slim + restore-keys: | + ${{ runner.os }}-single-buildx + + ########################################### # Build and Push containers to registries # ########################################### - name: Build Docker image - SLIM + uses: docker/build-push-action@v2.5.0 + with: + context: . + file: ./Dockerfile-slim + build-args: | + BUILD_DATE=${{ env.BUILD_DATE }} + BUILD_REVISION=${{ github.sha }} + BUILD_VERSION=${{ github.sha }} + load: true + push: false + tags: | + ghcr.io/github/super-linter:slim-${{ github.sha }} + ghcr.io/github/super-linter:slim-test + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new + + # Temp fix + # https://github.com/docker/build-push-action/issues/252 + # https://github.com/moby/buildkit/issues/1896 + ############# + # Fix Cache # + ############# + - name: Move cache run: | - docker build \ - --build-arg BUILD_DATE=${{ env.BUILD_DATE }} \ - --build-arg BUILD_REVISION=${{ github.sha }} \ - --build-arg BUILD_VERSION=${{ github.sha }} \ - -t ghcr.io/github/super-linter:slim-${{ github.sha }} \ - -t ghcr.io/github/super-linter:slim-test -f Dockerfile-slim . + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache ######################################## # Validates the metadata docker labels # diff --git a/.github/workflows/deploy-DEV-standard.yml b/.github/workflows/deploy-DEV-standard.yml index b2524ab4..5d1c8bab 100644 --- a/.github/workflows/deploy-DEV-standard.yml +++ b/.github/workflows/deploy-DEV-standard.yml @@ -54,20 +54,53 @@ jobs: - name: Get current date run: echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> ${GITHUB_ENV} - ################################### - # Build image locally for testing # - ################################### + ######################## + # Setup Docker build X # + ######################## + - name: Setup BuildX + uses: docker/setup-buildx-action@v1.3.0 + + ################ + # Docker cache # + ################ + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-single-buildx-standard + restore-keys: | + ${{ runner.os }}-single-buildx + ########################################### # Build and Push containers to registries # ########################################### - - name: Build Docker standard image + - name: Build Docker image - Standard + uses: docker/build-push-action@v2.5.0 + with: + context: . + file: ./Dockerfile + build-args: | + BUILD_DATE=${{ env.BUILD_DATE }} + BUILD_REVISION=${{ github.sha }} + BUILD_VERSION=${{ github.sha }} + load: true + push: false + tags: | + ghcr.io/github/super-linter:${{ github.sha }} + ghcr.io/github/super-linter:test + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new + + # Temp fix + # https://github.com/docker/build-push-action/issues/252 + # https://github.com/moby/buildkit/issues/1896 + ############# + # Fix Cache # + ############# + - name: Move cache run: | - docker build \ - --build-arg BUILD_DATE=${{ env.BUILD_DATE }} \ - --build-arg BUILD_REVISION=${{ github.sha }} \ - --build-arg BUILD_VERSION=${{ github.sha }} \ - -t ghcr.io/github/super-linter:${{ github.sha }} \ - -t ghcr.io/github/super-linter:test -f Dockerfile . + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache ######################################## # Validates the metadata docker labels # diff --git a/.github/workflows/deploy-PROD-slim.yml b/.github/workflows/deploy-PROD-slim.yml index 7959cc95..4fc73fc7 100644 --- a/.github/workflows/deploy-PROD-slim.yml +++ b/.github/workflows/deploy-PROD-slim.yml @@ -82,6 +82,17 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} env: Production-SLIM + ################ + # Docker cache # + ################ + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-single-buildx-slim + restore-keys: | + ${{ runner.os }}-single-buildx + ########################################### # Build and Push containers to registries # ########################################### @@ -94,10 +105,24 @@ jobs: BUILD_DATE=${{ env.BUILD_DATE }} BUILD_REVISION=${{ github.sha }} BUILD_VERSION=${{ github.sha }} + load: true push: true tags: | github/super-linter:slim-latest ghcr.io/github/super-linter:slim-latest + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new + + # Temp fix + # https://github.com/docker/build-push-action/issues/252 + # https://github.com/moby/buildkit/issues/1896 + ############# + # Fix Cache # + ############# + - name: Move cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache ####################################################### # Create a GitHub Issue with the info from this build # diff --git a/.github/workflows/deploy-PROD-standard.yml b/.github/workflows/deploy-PROD-standard.yml index ff11f08d..4fdb597d 100644 --- a/.github/workflows/deploy-PROD-standard.yml +++ b/.github/workflows/deploy-PROD-standard.yml @@ -82,6 +82,17 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} env: Production + ################ + # Docker cache # + ################ + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-single-buildx-standard + restore-keys: | + ${{ runner.os }}-single-buildx + ########################################### # Build and Push containers to registries # ########################################### @@ -94,10 +105,24 @@ jobs: BUILD_DATE=${{ env.BUILD_DATE }} BUILD_REVISION=${{ github.sha }} BUILD_VERSION=${{ github.sha }} + load: true push: true tags: | github/super-linter:latest ghcr.io/github/super-linter:latest + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new + + # Temp fix + # https://github.com/docker/build-push-action/issues/252 + # https://github.com/moby/buildkit/issues/1896 + ############# + # Fix Cache # + ############# + - name: Move cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache ####################################################### # Create a GitHub Issue with the info from this build # diff --git a/.github/workflows/deploy-RELEASE-slim.yml b/.github/workflows/deploy-RELEASE-slim.yml index 9edf32e9..01ca8d0e 100644 --- a/.github/workflows/deploy-RELEASE-slim.yml +++ b/.github/workflows/deploy-RELEASE-slim.yml @@ -24,7 +24,7 @@ on: jobs: deploy: # Name the Job - name: Deploy Docker Image - Release - slim + name: Deploy Docker Image - Release - SLIM # Set the agent to run on runs-on: ubuntu-latest @@ -116,6 +116,17 @@ jobs: | grep -E -o "v[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+")" \ >> ${GITHUB_ENV} + ################ + # Docker cache # + ################ + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-single-buildx-slim + restore-keys: | + ${{ runner.os }}-single-buildx + ########################################### # Build and Push containers to registries # ########################################### @@ -128,6 +139,7 @@ jobs: BUILD_DATE=${{ env.BUILD_DATE }} BUILD_REVISION=${{ github.sha }} BUILD_VERSION=${{ github.sha }} + load: true push: true tags: | github/super-linter:slim-latest @@ -136,6 +148,19 @@ jobs: ghcr.io/github/super-linter:slim-latest ghcr.io/github/super-linter:slim-v4 ghcr.io/github/super-linter:slim-${{ env.RELEASE_VERSION }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new + + # Temp fix + # https://github.com/docker/build-push-action/issues/252 + # https://github.com/moby/buildkit/issues/1896 + ############# + # Fix Cache # + ############# + - name: Move cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache ######################### # Update Deployment API # diff --git a/.github/workflows/deploy-RELEASE-standard.yml b/.github/workflows/deploy-RELEASE-standard.yml index 002061d8..505e61a5 100644 --- a/.github/workflows/deploy-RELEASE-standard.yml +++ b/.github/workflows/deploy-RELEASE-standard.yml @@ -123,6 +123,17 @@ jobs: ISSUE_TITLE: ${{ github.event.issue.title }} ISSUE_BODY: ${{ github.event.issue.body }} + ################ + # Docker cache # + ################ + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-single-buildx-standard + restore-keys: | + ${{ runner.os }}-single-buildx + ########################################### # Build and Push containers to registries # ########################################### @@ -135,6 +146,7 @@ jobs: BUILD_DATE=${{ env.BUILD_DATE }} BUILD_REVISION=${{ github.sha }} BUILD_VERSION=${{ github.sha }} + load: true push: true tags: | github/super-linter:latest @@ -143,6 +155,19 @@ jobs: ghcr.io/github/super-linter:latest ghcr.io/github/super-linter:v4 ghcr.io/github/super-linter:${{ env.RELEASE_VERSION }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new + + # Temp fix + # https://github.com/docker/build-push-action/issues/252 + # https://github.com/moby/buildkit/issues/1896 + ############# + # Fix Cache # + ############# + - name: Move cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache ############################# # Create the GitHub Release # diff --git a/Dockerfile b/Dockerfile index eecf96c8..4b745bd2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -346,9 +346,7 @@ RUN wget --tries=5 -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sger && wget -q --tries=5 -O phive.phar https://phar.io/releases/phive.phar \ && wget -q --tries=5 -O phive.phar.asc https://phar.io/releases/phive.phar.asc \ && PHAR_KEY_ID="0x9D8A98B29B2D5D79" \ - && ( gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$PHAR_KEY_ID" \ - || gpg --keyserver pgp.mit.edu --recv-keys "$PHAR_KEY_ID" \ - || gpg --keyserver keyserver.pgp.com --recv-keys "$PHAR_KEY_ID" ) \ + && gpg --keyserver hkps://keyserver.ubuntu.com --recv-keys "$PHAR_KEY_ID" \ && gpg --verify phive.phar.asc phive.phar \ && chmod +x phive.phar \ && mv phive.phar /usr/local/bin/phive \ diff --git a/Dockerfile-slim b/Dockerfile-slim index a41a8054..a0bb2335 100644 --- a/Dockerfile-slim +++ b/Dockerfile-slim @@ -283,9 +283,7 @@ RUN wget --tries=5 -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sger && wget -q --tries=5 -O phive.phar https://phar.io/releases/phive.phar \ && wget -q --tries=5 -O phive.phar.asc https://phar.io/releases/phive.phar.asc \ && PHAR_KEY_ID="0x9D8A98B29B2D5D79" \ - && ( gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$PHAR_KEY_ID" \ - || gpg --keyserver pgp.mit.edu --recv-keys "$PHAR_KEY_ID" \ - || gpg --keyserver keyserver.pgp.com --recv-keys "$PHAR_KEY_ID" ) \ + && gpg --keyserver hkps://keyserver.ubuntu.com --recv-keys "$PHAR_KEY_ID" \ && gpg --verify phive.phar.asc phive.phar \ && chmod +x phive.phar \ && mv phive.phar /usr/local/bin/phive \