-
Notifications
You must be signed in to change notification settings - Fork 267
116 lines (103 loc) · 3.91 KB
/
Copy pathdocker_build.yml
File metadata and controls
116 lines (103 loc) · 3.91 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
name: Build Docker Image
on:
workflow_call:
inputs:
version:
description: "The version number"
default: "1.0.0"
required: false
type: string
registry:
description: "The Docker Registry"
default: "ghcr.io"
required: false
type: string
image_name:
description: "The Docker image name"
default: ${{ github.repository }}
required: false
type: string
folder_name:
description: "The folder where the Dockerfile is located"
default: .
required: false
type: string
user_name:
description: "The name of the user to login to the registry"
default: ${{ github.actor }}
required: false
type: string
run_number:
description: "The workflow run number"
default: ${{ github.run_number }}
required: false
type: string
environment:
description: "The GitHub environment to use (for environment-specific secrets/variables)"
required: false
type: string
platforms:
description: "The platforms to build for"
required: false
type: string
default: linux/amd64,linux/arm64
outputs:
build_image:
description: "The build image"
value: ${{ jobs.build.outputs.build_image }}
build_image_tag:
description: "The build image tag"
value: ${{ jobs.build.outputs.build_image_tag }}
version:
description: "The new version number"
value: ${{ jobs.build.outputs.version }}
jobs:
build:
name: ${{ inputs.environment && format('Build {0} Image', inputs.environment) || 'Build Image' }}
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
permissions:
contents: read
packages: write
attestations: write
outputs:
build_image: ${{ steps.output.outputs.build_image }}
build_image_tag: ${{ steps.output.outputs.build_image_tag }}
version: ${{ steps.output.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ inputs.registry }}
username: ${{ inputs.user_name }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ inputs.registry }}/${{ inputs.image_name }}
- name: Build and publish image
id: push
uses: docker/build-push-action@v7.0.0
with:
context: ${{ inputs.folder_name }}
push: true
tags: ${{ inputs.registry }}/${{ inputs.image_name }}:${{ inputs.version }}${{ inputs.environment && format('-{0}', inputs.environment) || '' }}-build.${{ inputs.run_number }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ inputs.platforms }}
- name: Store outputs
id: output
run: |
echo "build_image=${{ inputs.registry }}/${{ inputs.image_name }}" >> "$GITHUB_OUTPUT"
echo "build_image_tag=${{ inputs.version }}${{ inputs.environment && format('-{0}', inputs.environment) || '' }}-build.${{ inputs.run_number }}" >> "$GITHUB_OUTPUT"
echo "version=${{ inputs.version }}" >> "$GITHUB_OUTPUT"
- name: Generate summary
run: |
echo "## Build Summary" >> $GITHUB_STEP_SUMMARY;
echo "Build Image: ${{ inputs.registry }}/${{ inputs.image_name }}:${{ inputs.version }}${{ inputs.environment && format('-{0}', inputs.environment) || '' }}-build.${{ inputs.run_number }}" >> $GITHUB_STEP_SUMMARY;