Skip to content

Merge pull request #16 from drizuid/update #31

Merge pull request #16 from drizuid/update

Merge pull request #16 from drizuid/update #31

Workflow file for this run

name: Docker Image CI
on:
push:
branches:
- main
- dev # Add your dev branch here
- 'feature/**' # Optional: for any feature branch
jobs:
build_and_push_image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Determine Image Tags
id: set_tags
run: |
# Get a sanitized, lowercased version of the branch name (e.g., "dev")
BRANCH_NAME=$(echo "${{ github.ref_name }}" | sed 's/[^a-zA-Z0-9-]/_/g' | tr '[:upper:]' '[:lower:]')
# Define the base name for the image
IMAGE_NAME=ghcr.io/${{ github.repository }}
# Conditionally set tags based on the branch
if [[ "${{ github.ref_name }}" == "main" ]]; then
# For the main branch, tag with 'latest'
TAGS="${IMAGE_NAME}:latest"
else
# For all other branches (like 'dev'), tag with the branch name
TAGS="${IMAGE_NAME}:${BRANCH_NAME}"
fi
# Output the tags for use in the next step
echo "TAGS=${TAGS}" >> $GITHUB_OUTPUT
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.set_tags.outputs.TAGS }}