Skip to content

SECRETS to VARS

SECRETS to VARS #2

name: Publish Docker Image to Docker Hub
on:
push:
branches:
- main # Still triggers on main branch for "latest" image
tags:
- '*' # Triggers on any tag
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
# Checkout the code
- name: Check out the repository
uses: actions/checkout@v3
# Log in to Docker Hub
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ vars.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# Determine the Docker tag (use "latest" for main branch; tag name for tag pushes)
- name: SetDocker tag
id: docker_tag
run: |
if [ "${{ github.ref_type }}" == "tag" ]; then
echo "tag=${GITHUB_REF##*/}" >> $GITHUB_ENV
else
echo "tag=latest" >> $GITHUB_ENV
fi
# Build the docker image
- name: Build Docker image
run: |
docker build -t ${{ vars.DOCKER_USERNAME }}/hbcd_motion_postproc:${{ env.tag }} .
# Push the Docker image to Docker Hub
- name: Push Docker image to Docker Hub
run: |
docker push ${{ vars.DOCKER_USERNAME }}/hbcd_motion_postproc:${{ env.tag }}