-
-
Notifications
You must be signed in to change notification settings - Fork 0
119 lines (108 loc) · 3.57 KB
/
_containerTemplate.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
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
117
118
119
name: Container Template
on:
workflow_call:
inputs:
environment:
required: true
type: string
default: "dev"
description: "Specifies the environment of the deployment."
working_directory:
required: false
type: string
default: ./code/function
description: "Specifies the uri of the container registry."
registry_uri:
required: false
type: string
default: ghcr.io
description: "Specifies the uri of the container registry."
image_namespace_name:
required: true
type: string
description: "Specifies the namespace name of the image."
image_name:
required: true
type: string
description: "Specifies the name of the image."
secrets:
USER_NAME:
required: true
description: "Specifies the user name for the container registry."
PASSWORD:
required: true
description: "Specifies the password for the container registry."
jobs:
deployment:
name: Container Build & Push
runs-on: [ubuntu-latest]
continue-on-error: false
environment: ${{ inputs.environment }}
permissions:
contents: read
packages: write
id-token: write
steps:
# Check Out Repository
- name: Check Out Repository
id: checkout_repository
uses: actions/checkout@v4
# Install cosign
- name: Install cosign
id: install_cosign
uses: sigstore/[email protected]
if: github.event_name != 'pull_request'
with:
cosign-release: 'v2.2.0'
# Install QEMU
- name: Set up QEMU
id: install_qemu
uses: docker/setup-qemu-action@v3
# Install BuildKit
- name: Install Buildx
id: install_buildx
uses: docker/[email protected]
# Login Container Registry
- name: Login Container Registry
id: registry_login
uses: docker/[email protected]
if: github.event_name != 'pull_request'
with:
registry: ${{ inputs.registry_uri }}
username: ${{ secrets.USER_NAME }}
password: ${{ secrets.PASSWORD }}
# Extract Metadata (tags, labels)
- name: Extract Metadata
id: metadata
uses: docker/[email protected]
with:
context: workflow
images: |
${{ inputs.registry_uri }}/${{ inputs.image_namespace_name }}/${{ inputs.image_name }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
# Build and Push Docker Image with Buildx
- name: Build and push Docker image
id: build_push
uses: docker/[email protected]
with:
context: ${{ inputs.working_directory }}
file: ${{ inputs.working_directory }}/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Sign container image
# This step uses the identity token to provision an ephemeral certificate against the sigstore community Fulcio instance.
- name: Sign container image
id: sign
if: github.event_name == 'release'
run: |
cosign sign --yes "${TAGS}@${DIGEST}"
env:
TAGS: ${{ steps.metadata.outputs.tags }}
DIGEST: ${{ steps.build_push.outputs.digest }}