Publish Latest Images to Docker Hub #3
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: Publish Latest Images to Docker Hub | |
on: | |
create: | |
tags: | |
- '*' | |
permissions: | |
contents: read | |
jobs: | |
publish: | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Clone Action Repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Login to Docker Hub | |
uses: docker/[email protected] | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build, Tag and Push Images | |
run: | | |
# Stop the script on errors | |
set -e | |
# Enable Docker BuildKit | |
export DOCKER_BUILDKIT=1 | |
# Set tag variables | |
COMMIT_HASH=$(git rev-parse --short HEAD) | |
TAG_NAME=$(git describe --tags --abbrev=0) | |
# Define a dictionary with paths to Dockerfiles as keys and image names as values | |
declare -A images | |
images=( | |
["build/python/backend"]="target/strelka-backend" | |
["build/go/frontend"]="target/strelka-frontend" | |
["build/go/fileshot"]="target/strelka-fileshot" | |
["build/go/filestream"]="target/strelka-filestream" | |
["build/go/oneshot"]="target/strelka-oneshot" | |
["build/go/manager"]="target/strelka-manager" | |
) | |
# Build, tag, and push each image | |
for path in "${!images[@]}"; do | |
IMAGE_NAME=${images[$path]} | |
docker build -f "${path}/Dockerfile" -t "${IMAGE_NAME}:${TAG_NAME}" -t "${IMAGE_NAME}:latest" . | |
docker push "${IMAGE_NAME}:${TAG_NAME}" | |
docker push "${IMAGE_NAME}:latest" | |
done | |
- name: Logout from Docker Hub | |
run: docker logout |