Workflow file for this run
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
name: Create and publish a Docker image | |
on: | |
release: | |
types: [ published ] | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
build-and-push-image: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
attestations: write | |
id-token: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.22' | |
- name: Log in to the Container registry | |
uses: docker/#-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Log in to the Container registry | |
uses: docker/#-action@v3 | |
with: | |
username: dvdandroid | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build Docker image | |
run: | | |
GITHUB_SHA=$(echo ${{ github.sha }} | cut -c1-7) | |
VERSION=$(echo ${{ github.ref }} | sed 's/refs\/tags\///') | |
IMAGE_TAG=${VERSION}-${GITHUB_SHA} | |
docker build -t img -f Dockerfile . | |
# make IMAGE_NAME lowercase | |
IMAGE_NAME=$(echo ${{ env.IMAGE_NAME }} | tr '[:upper:]' '[:lower:]') | |
if [[ ${{ github.event.release.prerelease }} == "false" ]]; then | |
major=$(echo $VERSION | cut -d. -f1) | |
minor=$(echo $VERSION | cut -d. -f2) | |
tag_major="$major" | |
tag_minor="$major.$minor" | |
docker tag img ${{ env.REGISTRY }}/${IMAGE_NAME}:${tag_major} | |
docker tag img ${{ env.REGISTRY }}/${IMAGE_NAME}:${tag_minor} | |
docker tag img ${{ env.REGISTRY }}/${IMAGE_NAME}:latest | |
docker tag img ${IMAGE_NAME}:${tag_major} | |
docker tag img ${IMAGE_NAME}:${tag_minor} | |
docker tag img ${IMAGE_NAME}:latest | |
fi | |
docker tag img ${{ env.REGISTRY }}/${IMAGE_NAME}:${VERSION} | |
docker tag img ${{ env.REGISTRY }}/${IMAGE_NAME}:${IMAGE_TAG} | |
docker tag img ${{ env.REGISTRY }}/${IMAGE_NAME}:${GITHUB_SHA} | |
docker tag img ${IMAGE_NAME}:${VERSION} | |
docker tag img ${IMAGE_NAME}:${IMAGE_TAG} | |
docker tag img ${IMAGE_NAME}:${GITHUB_SHA} | |
- name: Push Docker image | |
run: | | |
# make IMAGE_NAME lowercase | |
IMAGE_NAME=$(echo ${{ env.IMAGE_NAME }} | tr '[:upper:]' '[:lower:]') | |
docker push -a ${{ env.REGISTRY }}/${IMAGE_NAME} | |
docker push -a ${IMAGE_NAME} |