Update Docker tag name for main branch #10
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: Docker | |
on: | |
push: | |
branches: | |
- 'main' | |
- 'release/*' | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
# Checkout the repository to the GitHub Actions runner | |
- name: Checkout | |
uses: actions/checkout@v4 | |
# Set up Docker Buildx | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
# Login to GitHub Container Registry | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: set lower case owner name | |
run: | | |
echo "OWNER_LC=${OWNER,,}" >>${GITHUB_ENV} | |
env: | |
OWNER: '${{ github.repository_owner }}' | |
# Determine the Docker tag name based on the branch name | |
- name: Set Docker tag name | |
run: | | |
# If the branch is 'main', set the tag name to 'latest' | |
if [[ "${GITHUB_REF#refs/heads/}" == "main" ]]; then | |
echo "DOCKER_TAG_NAME=latest" >> $GITHUB_ENV | |
# If the branch is a release branch, extract the release name | |
elif [[ "${GITHUB_REF#refs/heads/}" == release/* ]]; then | |
# Extract the release name and set it as the tag name | |
RELEASE_NAME=$(echo "${GITHUB_REF#refs/heads/release/}") | |
echo "DOCKER_TAG_NAME=${RELEASE_NAME}" >> $GITHUB_ENV | |
fi | |
# Build and push Docker image to GitHub Container Registry | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
# Use the branch name as the tag for the Docker image | |
tags: ghcr.io/${{ env.OWNER_LC }}/vocode-next-template:${{ env.DOCKER_TAG_NAME }} |