-
Notifications
You must be signed in to change notification settings - Fork 28
151 lines (130 loc) · 4.81 KB
/
docker.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
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
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:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Determine stable version
id: stable-version
if: ${{ inputs.version || github.event_name == 'release' }}
run: |
version="${{ inputs.version || github.event.release.tag_name }}"
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:
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-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Install Docker Buildx
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1
- name: Build image
run: >
docker buildx build .
--file ${{ matrix.dockerfile }}
--platform linux/amd64,linux/arm64
--build-arg VERSION=${{ needs.version.outputs.version }}
--output type=tar,dest=image.tar
# Build and deploy the image
deploy:
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-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Install Docker Buildx
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1
- name: Setup Docker Content Trust
id: setup-dct
uses: bitwarden/gh-actions/setup-docker-trust@main
with:
azure-creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }}
azure-keyvault-name: "bitwarden-ci"
- 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 }}
run: >
docker buildx build .
--file ${{ matrix.dockerfile }}
--platform linux/amd64,linux/arm64
--build-arg VERSION=${{ needs.version.outputs.version }}
--push
${{ format('--tag {0}/{1}:dev', env.DOCKER_CONTAINER_NAMESPACE, matrix.name) }}
${{ github.event_name == 'release' && format('--tag {0}/{1}:qa', env.DOCKER_CONTAINER_NAMESPACE, matrix.name) || '' }}
${{ github.event_name == 'release' && !github.event.release.prerelease && format('--tag {0}/{1}:latest', env.DOCKER_CONTAINER_NAMESPACE, matrix.name) || '' }}
${{ github.event_name == 'release' && !github.event.release.prerelease && format('--tag {0}/{1}:stable', env.DOCKER_CONTAINER_NAMESPACE, matrix.name) || '' }}
${{ github.event_name == 'release' && format('--tag {0}/{1}:{2}', env.DOCKER_CONTAINER_NAMESPACE, matrix.name, github.ref_name) || '' }}
${{ inputs.image-tag && format('--tag {0}/{1}:{2}', env.DOCKER_CONTAINER_NAMESPACE, matrix.name, inputs.image-tag) || '' }}
- name: Log out of Docker and disable Docker Notary
run: |
docker logout
echo "DOCKER_CONTENT_TRUST=0" >> $GITHUB_ENV