building image app/latest #8
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: Build and Push Docker Image | |
on: | |
workflow_dispatch: | |
inputs: | |
image_name: | |
description: 'Docker image name' | |
type: string | |
required: true | |
default: 'app' | |
tag: | |
description: 'Docker image tag' | |
type: string | |
required: true | |
default: 'latest' | |
push_to_dockerhub: | |
description: 'Whether we need to push the image to dockerhub' | |
type: boolean | |
required: true | |
dockerfile_path: | |
description: 'Dockerfile path' | |
type: string | |
default: '.' | |
required: true | |
run-name: building image ${{ inputs.image_name }}/${{ inputs.tag }} | |
jobs: | |
build-and-push-docker-image: | |
name: Build and Push Docker Image | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v2 | |
with: | |
context: ${{ inputs.dockerfile_path }} | |
push: ${{ inputs.push_to_dockerhub }} | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ inputs.image_name }}:${{ inputs.tag }} | |
- name: Build completed | |
run: echo "Image build completed" |