-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
163 additions
and
1 deletion.
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,72 @@ | ||
name: "Publish to Docker" | ||
description: "Pushes built artifacts to Docker" | ||
|
||
inputs: | ||
docker_username: | ||
description: Username for Docker Hub account | ||
required: true | ||
docker_token: | ||
description: Token for Docker Hub account | ||
required: true | ||
image_registry: | ||
description: Registry to push images to | ||
required: true | ||
image_repository: | ||
description: Repository to push images to | ||
required: true | ||
image_tag: | ||
description: Tag to apply to images | ||
required: true | ||
image_latest: | ||
description: Apply the latest tag to the image | ||
required: true | ||
context: | ||
description: Path to Dockerfile | ||
required: true | ||
file: | ||
description: Path to Dockerfile | ||
required: true | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v2 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
with: | ||
install: true | ||
|
||
- name: Login to DockerHub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ inputs.docker_username }} | ||
password: ${{ inputs.docker_token }} | ||
|
||
- name: Prepare | ||
id: prep | ||
shell: bash | ||
env: | ||
REGISTRY: ${{ inputs.image_registry }} | ||
REPOSITORY: ${{ inputs.image_repository }} | ||
TAG: ${{ inputs.image_tag }} | ||
run: | | ||
IMAGE="$REGISTRY/$REPOSITORY" | ||
echo "IMAGE=${IMAGE}" >> $GITHUB_OUTPUT | ||
echo "TAG=${TAG}" >> $GITHUB_OUTPUT | ||
echo "TAGGED_IMAGE=${IMAGE}:${TAG}" >> $GITHUB_OUTPUT | ||
if [ "${{ inputs.image_latest }}" = "true" ]; then | ||
echo "TAGGED_IMAGE=${IMAGE}:${TAG},${IMAGE}:latest" >> $GITHUB_OUTPUT | ||
fi | ||
- name: Build and push | ||
uses: docker/build-push-action@v3 | ||
with: | ||
push: true | ||
context: ${{ inputs.context }} | ||
file: ${{ inputs.file }} | ||
platforms: linux/amd64, linux/arm64 | ||
tags: ${{ steps.prep.outputs.TAGGED_IMAGE }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max |
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,86 @@ | ||
name: Build and publish docker images | ||
on: | ||
push: | ||
branches: | ||
- main | ||
- development # Remove after testing | ||
jobs: | ||
maybe_build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
image: | ||
- wordpress-franken | ||
- wordpress-cli | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Process vars | ||
id: vars | ||
run: | | ||
IMAGE_DIR=./docker/${{ matrix.image }} | ||
IMAGE_VERSION=$(grep -oP '(?<=ARG IMAGE_VERSION=).+' $IMAGE_DIR/Dockerfile) | ||
if [[ -z "$IMAGE_VERSION" ]]; then | ||
echo "No image version found in Dockerfile" | ||
exit 0 | ||
fi | ||
echo "IMAGE_REPOSITORY=${{ matrix.image }}" >> $GITHUB_ENV | ||
echo "IMAGE_DIR=$IMAGE_DIR" >> $GITHUB_ENV | ||
echo "IMAGE_VERSION=$IMAGE_VERSION" >> $GITHUB_ENV | ||
- name: Get current version | ||
id: current_version | ||
if: steps.vars.outputs.IMAGE_VERSION | ||
run: | | ||
IMAGE_REPOSITORY=${{ steps.vars.outputs.IMAGE_REPOSITORY }} | ||
REGISTRY=${{ secrets.DOCKERHUB_REGISTRY }} | ||
# Get the jwt token from Docker Hub | ||
TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d '{"username": "'${{ secrets.DOCKERHUB_USERNAME }}'", "password": "'${{ secrets.DOCKERHUB_TOKEN }}'"}' https://hub.docker.com/v2/users/login/ | jq -r .token) | ||
# Get the tag latest from the registry | ||
IMAGE_DIGEST=$(curl -s -H "Authorization: JWT $TOKEN" -H "Accept: application/json" https://hub.docker.com/v2/repositories/${REGISTRY}/${IMAGE_REPOSITORY}/tags/latest | jq -r '.digest') | ||
echo "Image digest found: $IMAGE_DIGEST" | ||
if [ -z "$IMAGE_DIGEST" ]; then | ||
echo "No image digest found in Docker Hub. Assuming it's the first build." | ||
echo "CURRENT_VERSION=0.0.0" >> $GITHUB_ENV | ||
exit 0 | ||
fi | ||
# Get the other tag with the same digest (the version) | ||
DIGESTS=$(curl -s -H "Authorization: JWT $TOKEN" -H "Accept: application/json" https://hub.docker.com/v2/repositories/${REGISTRY}/${IMAGE_REPOSITORY}/tags | jq -r '.results[] | "\(.digest)$\(.name)"') | ||
for DIGEST in $DIGESTS; do | ||
CURRENT_VERSION=$(echo $DIGEST | cut -d$ -f2) | ||
CURRENT_DIGEST=$(echo $DIGEST | cut -d$ -f1) | ||
if [ "$CURRENT_DIGEST" = "$IMAGE_DIGEST" -a "$CURRENT_VERSION" != "latest" ]; then | ||
echo "Image version found: $CURRENT_VERSION" | ||
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV | ||
exit 0 | ||
break | ||
fi | ||
done | ||
echo "No image version found in Docker Hub. Cannot continue." | ||
exit 1 | ||
- name: "Read Semver Info" | ||
id: "semver_info" | ||
uses: YunaBraska/semver-info-action@main | ||
if: steps.vars.outputs.IMAGE_VERSION && steps.current_version.outputs.CURRENT_VERSION | ||
with: | ||
semver-a: ${{ steps.vars.outputs.IMAGE_VERSION }} | ||
semver-b: ${{ steps.current_version.outputs.CURRENT_VERSION }} | ||
|
||
- name: Publish to DockerHub | ||
if: steps.semver_info.outputs.is_greater_a && steps.semver_info.outputs.is_stable_a | ||
uses: ./.github/actions/image-publisher | ||
with: | ||
docker_username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
docker_token: ${{ secrets.DOCKERHUB_TOKEN }} | ||
image_registry: ${{ secrets.DOCKERHUB_REGISTRY }} | ||
image_repository: ${{ steps.vars.outputs.IMAGE_REPOSITORY }} | ||
image_tag: ${{ steps.vars.outputs.IMAGE_VERSION }} | ||
image_latest: true | ||
file: ${{ steps.vars.outputs.IMAGE_DIR }}/Dockerfile | ||
context: ${{ steps.vars.outputs.IMAGE_DIR }} |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
FROM wordpress:cli | ||
|
||
ARG IMAGE_VERSION=1.0.0 | ||
|
||
ARG USER=www-data | ||
|
||
USER root | ||
|
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
docker/wordpress/Dockerfile → docker/wordpress-franken/Dockerfile
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
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