Updated the changes for the fix #166
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: CI Docker Build and Push for Backend Services | |
on: | |
push: | |
branches: | |
- main | |
- develop | |
pull_request: | |
branches: | |
- main | |
- develop | |
workflow_dispatch: # Manual trigger | |
inputs: | |
RELEASE_VERSION: | |
description: 'Release version (e.g., 1.0.0). The "v" prefix will be automatically added.' | |
required: false | |
default: '' | |
jobs: | |
ci-build: | |
name: CI Docker Build | |
runs-on: ubuntu-latest | |
if: github.event_name != 'workflow_dispatch' # Only run on push or PR, skip manual dispatch | |
steps: | |
# Step 1: Checkout the repository | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
# Step 2: Set up Docker Image Tag | |
- name: Set up Docker Image Tag | |
id: tag_step | |
run: | | |
DATE_TAG="v$(date +'%Y.%m.%d')" | |
# Create a default tag for CI builds that isn't meant to be pushed | |
NEW_TAG="${DATE_TAG}-ci" | |
echo "Docker Tag: ${NEW_TAG}" | |
echo "tag=${NEW_TAG}" >> "$GITHUB_OUTPUT" | |
# Step 3: Build Docker Image (without push) | |
- name: Build Docker Image (No Push) | |
uses: docker/build-push-action@v5 | |
with: | |
file: ./infra_env_dashboard/backend/Dockerfile # Path to the single Dockerfile | |
context: ./infra_env_dashboard/backend # Set context to backend root | |
push: false | |
tags: | | |
sam123ben/infra-dashboard-backend:${{ steps.tag_step.outputs.tag }} | |
manual-build-push: | |
name: Manual Docker Build and Push | |
runs-on: ubuntu-latest | |
if: github.event_name == 'workflow_dispatch' # Only run on manual trigger | |
steps: | |
# Step 1: Checkout the repository | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
# Step 2: Validate Release Version | |
- name: Validate Release Version | |
run: | | |
if [ -z "${{ github.event.inputs.RELEASE_VERSION }}" ]; then | |
echo "Error: Please provide a valid release version for manual build and push." | |
exit 1 | |
fi | |
# Step 3: Log in to Docker Hub using the Access Token | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_PAT_TOKEN }} | |
# Step 4: Build and Push Docker Image | |
- name: Build and Push Docker Image | |
uses: docker/build-push-action@v5 | |
with: | |
file: ./infra_env_dashboard/backend/Dockerfile # Path to the single Dockerfile | |
context: ./infra_env_dashboard/backend # Set context to backend root | |
push: true | |
tags: | | |
sam123ben/infra-dashboard-backend:latest | |
sam123ben/infra-dashboard-backend:${{ github.event.inputs.RELEASE_VERSION }} |