Skip to content

Commit

Permalink
Push to Docker only when updated
Browse files Browse the repository at this point in the history
  • Loading branch information
szepeviktor authored Mar 9, 2021
1 parent be96326 commit 26723e7
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ jobs:

strategy:
matrix:
base-image:
- ubuntu:20.04
php-version:
- 7.3
- 7.4
Expand All @@ -62,10 +64,33 @@ jobs:
- name: Echo out the files
run: ls -al

- name: Cache base image digest
uses: actions/cache@v2
with:
path: ${{ runner.temp }}/.base-image-digest
key: base-image-digest

- name: Pull base image
run: docker pull ${{ matrix.base-image }}

- name: Read cached base image digest
id: cached-base-image-digest
run: |
touch "${{ runner.temp }}/.base-image-digest"
echo "::set-output name=sha256::$(head -n 1 "${{ runner.temp }}/.base-image-digest")"
- name: Set base image digest
id: base-image-digest
run: echo "::set-output name=sha256::$(docker inspect --format='{{index .RepoDigests 0}}' ${{ matrix.base-image }}')"

- name: Build image
if: steps.base-image-digest.outputs.sha256 != steps.cached-base-image-digest.outputs.sha256

This comment has been minimized.

Copy link
@jaydrogers

jaydrogers Mar 9, 2021

Member

@szepeviktor: How should we handle this scenario:

  1. Ubuntu 20.04 image DOES NOT have an image update
  2. But there is an update for "ondrej/php"

We might have to loop back to this later. Maybe it's best I get my other code in here first so you can see the approach I've been using.

run: docker build php/${{ matrix.php-version }}/. --tag serversideup/php:${{ matrix.php-version }}


- name: Push image
if: steps.base-image-digest.outputs.sha256 != steps.cached-base-image-digest.outputs.sha256
run: docker push serversideup/php:${{ matrix.php-version }}

- name: Update base image digest cache
run: |
docker push serversideup/php:${{ matrix.php-version }}
echo "${{ steps.base-image-digest.outputs.sha256 }}" >"${{ runner.temp }}/.base-image-digest"

0 comments on commit 26723e7

Please sign in to comment.