-
Notifications
You must be signed in to change notification settings - Fork 834
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor build workflow and add check for update
- Loading branch information
Showing
2 changed files
with
115 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
name: Push image | ||
description: Push image to image repos | ||
inputs: | ||
image: | ||
description: image to push | ||
required: true | ||
tag: | ||
description: tag to push | ||
required: true | ||
update-check: | ||
description: command to run on old image and check for updates | ||
required: true | ||
github-token: | ||
description: token for pushing image to GitHub | ||
required: true | ||
dockerhub-username: | ||
description: username for pushing image to Docker Hub | ||
required: true | ||
dockerhub-password: | ||
description: password for pushing image to Docker Hub | ||
required: true | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Check for changes or updates | ||
id: changes | ||
shell: bash | ||
run: | | ||
latest_tag="docker.pkg.github.com/${{ inputs.image }}/${{ inputs.tag }}" | ||
echo "${{ inputs.github-token }}" | docker login docker.pkg.github.com \ | ||
-u ${{ github.actor }} --password-stdin | ||
docker pull "$latest_tag" | ||
docker logout docker.pkg.github.com | ||
packages="$(docker run --rm "$latest_tag" sh -c "${{ inputs.update-check }}")" | ||
echo "$packages" | ||
revision="$(docker image inspect --format \ | ||
'{{index .Config.Labels "org.opencontainers.image.revision"}}' \ | ||
"$latest_tag")" | ||
echo "$revision" | ||
if [ "$revision" != "$GITHUB_SHA" ] || [ "${#packages}" -gt 0 ]; then | ||
echo "Changes detected" | ||
echo "detected=true" >> "$GITHUB_OUTPUT" | ||
else | ||
echo "No change detected" | ||
echo "detected=false" >> "$GITHUB_OUTPUT" | ||
fi | ||
- name: Build image | ||
if: steps.changes.outputs.detected == 'true' | ||
shell: bash | ||
run: | | ||
docker build . \ | ||
--pull=true \ | ||
--file=Dockerfile-alpine \ | ||
--tag="${{ inputs.image }}:${{ inputs.tag }}" \ | ||
--label="org.opencontainers.image.source=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \ | ||
--label="org.opencontainers.image.revision=$GITHUB_SHA" \ | ||
--label="org.opencontainers.image.created=$(date --rfc-3339=seconds)" | ||
- name: Test image | ||
if: steps.changes.outputs.detected == 'true' | ||
shell: bash | ||
run: tests/run "${{ inputs.image }}:${{ inputs.tag }}" | ||
|
||
- name: Push image to GitHub registry | ||
if: > | ||
steps.changes.outputs.detected == 'true' && | ||
github.ref == 'refs/heads/master' | ||
shell: bash | ||
run: | | ||
echo "${{ inputs.github-token }}" | docker login docker.pkg.github.com \ | ||
-u ${{ github.actor }} --password-stdin | ||
github_tag=docker.pkg.github.com/${{ inputs.image }}/${{ inputs.tag }} | ||
docker tag "${{ inputs.image }}:${{ inputs.tag }}" $github_tag | ||
docker push "$github_tag" | ||
docker logout docker.pkg.github.com | ||
- name: Push images to Docker Hub registry | ||
if: steps.changes.outputs.detected == 'true' | ||
shell: bash | ||
run: | | ||
echo "${{ inputs.dockerhub-password }}" | docker login \ | ||
-u ${{ inputs.dockerhub-username }} --password-stdin | ||
docker push "${{ inputs.image }}:${{ inputs.tag }}" | ||
docker logout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters