-
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
1 parent
dac83bc
commit f377bde
Showing
1 changed file
with
11 additions
and
24 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 |
---|---|---|
@@ -1,66 +1,53 @@ | ||
name: Build Docker Image | ||
name: Build and Push Docker Image | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: [main] | ||
tags: "v*.*.*" | ||
tags: 'v*.*.*' | ||
|
||
jobs: | ||
build: | ||
name: "Build and Push Docker Image" | ||
name: 'Build and Push Docker Image' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Prepare Tags | ||
id: prep | ||
id: tags | ||
run: | | ||
DOCKER_IMAGE=${{ secrets.DOCKER_USERNAME }}/${GITHUB_REPOSITORY#*/} | ||
VERSION=${GITHUB_REF##*/} | ||
# If this is the main branch, use 'latest' instead | ||
if [[ $GITHUB_REF == refs/heads/main ]]; then | ||
if [[ $VERSION == main ]]; then | ||
VERSION=latest | ||
fi | ||
TAGS="${DOCKER_IMAGE}:${VERSION}" | ||
# If the version is a version number, also tag with 'latest' | ||
if [[ $VERSION =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
TAGS="$TAGS,${DOCKER_IMAGE}:latest" | ||
fi | ||
# Tag with the GitHub run id to create a unique tag for this run | ||
TAGS="$TAGS,${DOCKER_IMAGE}:${GITHUB_RUN_ID}" | ||
TAGS="${DOCKER_IMAGE}:${VERSION},${DOCKER_IMAGE}:${GITHUB_RUN_ID}" | ||
echo "tags=${TAGS}" >> $GITHUB_OUTPUT | ||
echo "docker_image=${DOCKER_IMAGE}" >> $GITHUB_OUTPUT | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v2 | ||
uses: docker/setup-qemu-action@v3 | ||
with: | ||
platforms: all | ||
|
||
- name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@v2 | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Login to Docker | ||
if: github.event_name != 'pull_request' | ||
uses: docker/login-action@v2 | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
|
||
- name: Build and Push | ||
uses: docker/build-push-action@v4 | ||
uses: docker/build-push-action@v6 | ||
with: | ||
builder: ${{ steps.buildx.outputs.name }} | ||
context: . | ||
file: ./Dockerfile | ||
platforms: linux/amd64 | ||
push: true | ||
tags: ${{ steps.prep.outputs.tags }} | ||
tags: ${{ steps.tags.outputs.tags }} |