Skip to content

Build and Push Docker Images 101 #2

Build and Push Docker Images 101

Build and Push Docker Images 101 #2

name: Build and Push Docker Images
on:
workflow_dispatch:
inputs:
branch:
description: "Target branch from which the source Dockerfile will be sourced"
required: true
pull_request:
branches:
- '**' # Trigger workflow on commits to any branch in a PR
jobs:
build-and-push-docker-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.branch || github.head_ref }}
- name: Get tag for the image
id: get-tag
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "TAG=${{ github.event.inputs.branch }}" >> $GITHUB_ENV
else
echo "TAG=${GITHUB_SHA::8}" >> $GITHUB_ENV
# This sets the tag to the branch name for manual trigger and commit SHA for PR
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push Dev Docker image
uses: docker/build-push-action@v6
with:
file: ./dockerfiles/registrar.Dockerfile
push: true
target: dev
tags: farhan943/practise:${{ env.TAG }}