-
Notifications
You must be signed in to change notification settings - Fork 43
195 lines (166 loc) · 5.63 KB
/
Copy pathdocker.yml
File metadata and controls
195 lines (166 loc) · 5.63 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
name: Docker
on:
push:
branches:
- main
pull_request:
branches:
- main
release:
types:
- published
workflow_dispatch:
inputs:
version:
description: Application version to use when publishing the project
required: false
image-tag:
description: Additional Docker image tag to apply on deployment
required: false
jobs:
# Determine version
version:
name: Determine version
runs-on: ubuntu-24.04
permissions:
contents: read
steps:
- name: Determine stable version
id: stable-version
if: ${{ inputs.version || github.event_name == 'release' }}
env:
VERSION: ${{ inputs.version || github.event.release.tag_name }}
run: |
if ! [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z].*)?$ ]]; then
echo "Invalid version: $VERSION"
exit 1
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Determine prerelease version
id: pre-version
run: |
hash="${{ github.event.pull_request.head.sha || github.sha }}"
echo "version=0.0.0-ci-${hash:0:7}" >> "$GITHUB_OUTPUT"
outputs:
version: ${{ steps.stable-version.outputs.version || steps.pre-version.outputs.version }}
# Build the image without deploying just to make sure the dockerfile is valid
pack:
name: Build image
needs: version
strategy:
matrix:
app:
- Api
#- AdminConsole
- Self-Host
include:
- app: Api
dockerfile: Api.dockerfile
#- app: AdminConsole
# dockerfile: AdminConsole.dockerfile
- app: Self-Host
dockerfile: self-host/Dockerfile
runs-on: ubuntu-24.04
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Install Docker Buildx
uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3.8.0
- name: Build image
env:
VERSION: ${{ needs.version.outputs.version }}
run: >
docker buildx build .
--file ${{ matrix.dockerfile }}
--platform linux/amd64,linux/arm64
--build-arg VERSION="${VERSION}"
--output type=tar,dest=image.tar
# Build and deploy the image
deploy:
name: Deploy image
if: ${{ github.event_name != 'pull_request' }}
needs: version
strategy:
matrix:
app:
- Api
#- AdminConsole
- Self-Host
include:
- app: Api
dockerfile: Api.dockerfile
name: passwordless-test-api
#- app: AdminConsole
# dockerfile: AdminConsole.dockerfile
# repository: passwordless-test-admin-console
- app: Self-Host
dockerfile: self-host/Dockerfile
name: passwordless-self-host
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Install Docker Buildx
uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3.8.0
- name: Log in to Azure
uses: bitwarden/gh-actions/azure-login@main
with:
subscription_id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
tenant_id: ${{ secrets.AZURE_TENANT_ID }}
client_id: ${{ secrets.AZURE_CLIENT_ID }}
- name: Setup Docker Content Trust
id: setup-dct
uses: bitwarden/gh-actions/setup-docker-trust@main
with:
azure-keyvault-name: "bitwarden-ci"
- name: Log out from Azure
uses: bitwarden/gh-actions/azure-logout@main
- name: Build & push image
env:
_DOCKER_CONTAINER_NAMESPACE: bitwarden
_DOCKER_CONTENT_TRUST: 1
_DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE: ${{ steps.setup-dct.outputs.dct-delegate-repo-passphrase }}
_VERSION: ${{ needs.version.outputs.version }}
_DOCKERFILE: ${{ matrix.dockerfile }}
_IMAGE_NAME: ${{ matrix.name }}
_EVENT_NAME: ${{ github.event_name }}
_IS_PRERELEASE: ${{ github.event.release.prerelease }}
_REF_NAME: ${{ github.ref_name }}
_INPUT_TAG: ${{ inputs.image-tag }}
run: |
set -euo pipefail
args=(
--file "$_DOCKERFILE"
--platform "linux/amd64,linux/arm64"
--build-arg "VERSION=$_VERSION"
--push
"$PWD"
)
# Always tag with dev
args+=( --tag "$_DOCKER_CONTAINER_NAMESPACE/$_IMAGE_NAME:dev" )
if [[ "$_EVENT_NAME" == "release" ]]; then
args+=( --tag "$_DOCKER_CONTAINER_NAMESPACE/$_IMAGE_NAME:qa" )
if [[ "$_IS_PRERELEASE" != "true" ]]; then
args+=( --tag "$_DOCKER_CONTAINER_NAMESPACE/$_IMAGE_NAME:latest" )
args+=( --tag "$_DOCKER_CONTAINER_NAMESPACE/$_IMAGE_NAME:stable" )
fi
args+=( --tag "$_DOCKER_CONTAINER_NAMESPACE/$_IMAGE_NAME:$_REF_NAME" )
fi
if [[ -n "${_INPUT_TAG:-}" ]]; then
args+=( --tag "$_DOCKER_CONTAINER_NAMESPACE/$_IMAGE_NAME:$_INPUT_TAG" )
fi
docker buildx build "${args[@]}"
- name: Log out of Docker and disable Docker Notary
run: |
docker logout
echo "DOCKER_CONTENT_TRUST=0" >> "$GITHUB_ENV"