-
Notifications
You must be signed in to change notification settings - Fork 5
102 lines (93 loc) · 3.19 KB
/
docker-build.yml
File metadata and controls
102 lines (93 loc) · 3.19 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: Docker Build and Push
on:
workflow_call:
inputs:
version:
description: 'Version to build (e.g., 1.11.0, 1.11.0rc1, 1.11.0a5)'
required: true
type: string
venue:
description: 'Deployment venue (dev, sit, uat, ops)'
required: true
type: string
push:
description: 'Whether to push the image to registry'
required: false
type: boolean
default: true
workflow_dispatch:
inputs:
version:
description: 'Version to build (e.g., 1.11.0, 1.11.0rc1, 1.11.0a5)'
required: true
type: string
venue:
description: 'Deployment venue (dev, sit, uat, ops)'
required: true
type: choice
options:
- dev
- sit
- uat
- ops
push:
description: 'Whether to push the image to registry'
required: false
type: boolean
default: true
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
docker:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Log in to Container Registry
if: ${{ inputs.push }}
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ inputs.version }}
type=raw,value=${{ inputs.venue }}
type=raw,value=latest,enable=${{ inputs.venue == 'ops' }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Build and push Docker image
uses: docker/build-push-action@v7
with:
context: .
file: Dockerfile
push: ${{ inputs.push }}
pull: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# Pull from multiple venue caches for better cache hit rates
cache-from: |
type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-${{ inputs.venue }}
type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-sit
type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-uat
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-${{ inputs.venue }},mode=max
- name: Output image tags
run: |
echo "### 🐳 Docker Image Published" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version:** \`${{ inputs.version }}\`" >> $GITHUB_STEP_SUMMARY
echo "**Venue:** \`${{ inputs.venue }}\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Tags:**" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY