Skip to content

Merge branch 'ci-cd-phase-1' into test #2

Merge branch 'ci-cd-phase-1' into test

Merge branch 'ci-cd-phase-1' into test #2

Workflow file for this run

name: Docker Build and Push
on:
push:
branches:
- test
workflow_dispatch:
inputs:
tag:
description: 'Docker image tag'
required: false
default: 'latest'
jobs:
build-and-push:
name: Build and Push Docker Image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Set Tag
id: set_tag
run: |
TAG="${{ github.event.inputs.tag }}"
if [[ -z "$TAG" || "$TAG" == "latest" ]]; then
TAG=$(git rev-parse --short=7 HEAD)
fi
echo "::set-output name=tag::$TAG"
- name: Build Docker Image
run: |
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:${{ steps.set_tag.outputs.tag }} .
- name: Push Docker Image
run: |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:${{ steps.set_tag.outputs.tag }}
if [[ "${{ steps.set_tag.outputs.tag }}" != "latest" ]]; then
docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest
fi