-
Notifications
You must be signed in to change notification settings - Fork 0
53 lines (46 loc) · 1.4 KB
/
build_and_push_image.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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"