-
Notifications
You must be signed in to change notification settings - Fork 5
74 lines (67 loc) · 2.24 KB
/
build-and-push-image.yaml
File metadata and controls
74 lines (67 loc) · 2.24 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
---
name: Build and Push Image
"on":
workflow_call:
inputs:
environment:
description: Determines which docker registry credentials to use
required: true
type: string
image:
description: Image name (without the tag & registry)
required: true
type: string
docker-login:
description: Whether to log in to Docker Hub
required: false
type: boolean
default: true
push:
description: Whether to push the image to the registry
required: false
type: boolean
default: true
permissions: {}
jobs:
build_push_image:
name: Build and push image
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
if: ${{ inputs.docker-login }}
with:
# These credentials are managed in Terraform. Depending on the 'environment' value above,
# these will either be the credentials for 'dev' or 'prod'.
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker image metadata
id: metadata
uses: docker/metadata-action@v5
with:
images: prefecthq/${{ inputs.image }}
tags: |
# always: short sha
type=sha,prefix=,format=short
# for pull requests: "pr-123"
type=ref,event=pr
# for main merges: latest
type=raw,value=latest,enable={{is_default_branch}}
# for releases: 1.2.3
type=semver,pattern={{version}}
labels: |
org.opencontainers.image.title=prefect-operator
org.opencontainers.image.description=Prefect Operator image
org.opencontainers.image.vendor=Prefect
- name: ${{ inputs.push && 'Build and push' || 'Build' }}
uses: docker/build-push-action@v6
with:
context: .
push: ${{ inputs.push }}
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}