Merge pull request #311 from Rakshitha-D/githubWorkflows #1
Workflow file for this run
This file contains hidden or 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: Build and Publish Docker Image | |
on: | |
push: | |
tags: | |
- '*' | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Get short commit hash | |
id: vars | |
run: echo "commit_hash=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
- name: Prepare Docker image name and tag | |
run: | | |
REPO_NAME_LOWERCASE=$(echo "${GITHUB_REPOSITORY}" | tr '[:upper:]' '[:lower:]') | |
TAG_NAME=$(echo "${GITHUB_REF_NAME}" | tr '[:upper:]' '[:lower:]') | |
BUILD_TAG="${TAG_NAME}_${{ steps.vars.outputs.commit_hash }}_${GITHUB_RUN_NUMBER}" | |
echo "IMAGE_NAME=ghcr.io/${REPO_NAME_LOWERCASE}" >> $GITHUB_ENV | |
echo "IMAGE_TAG=${BUILD_TAG}" >> $GITHUB_ENV | |
- name: Build Docker image | |
run: docker build -t $IMAGE_NAME:$IMAGE_TAG . | |
- name: Push Docker image | |
run: docker push $IMAGE_NAME:$IMAGE_TAG |