Skip to content

Commit d722328

Browse files
authored
Container building changes (dani-garcia#3958)
* WIP: Container building changes * Small updates - Updated to rust 1.73.0 - Updated crates - Updated documentation - Added a bake.sh script to make baking easier * Update GitHub Actions Workflow - Updated workflow to use qemu and buildx bake In the future i would like to extract the alpine based binaries and add them as artifacts to the release. * Address review remarks and small updates - Addressed review remarks - Added `podman-bake.sh` script to build Vaultwarden with podman - Updated README - Updated crates - Added `VW_VERSION` support - Added annotations - Updated web-vault to v2023.9.1
1 parent cb4b683 commit d722328

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1744
-2949
lines changed

.github/workflows/build.yml

+10-27
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ on:
1212
- "rustfmt.toml"
1313
- "diesel.toml"
1414
- "docker/Dockerfile.j2"
15+
- "docker/DockerSettings.yaml"
1516
pull_request:
1617
paths:
1718
- ".github/workflows/build.yml"
@@ -23,6 +24,7 @@ on:
2324
- "rustfmt.toml"
2425
- "diesel.toml"
2526
- "docker/Dockerfile.j2"
27+
- "docker/DockerSettings.yaml"
2628

2729
jobs:
2830
build:
@@ -32,7 +34,6 @@ jobs:
3234
# This is done globally to prevent rebuilds when the RUSTFLAGS env variable changes.
3335
env:
3436
RUSTFLAGS: "-D warnings"
35-
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
3637
strategy:
3738
fail-fast: false
3839
matrix:
@@ -113,46 +114,46 @@ jobs:
113114
prefix-key: "v2023.07-rust"
114115
# End Enable Rust Caching
115116

116-
# Run cargo tests (In release mode to speed up future builds)
117+
# Run cargo tests
117118
# First test all features together, afterwards test them separately.
118119
- name: "test features: sqlite,mysql,postgresql,enable_mimalloc"
119120
id: test_sqlite_mysql_postgresql_mimalloc
120121
if: $${{ always() }}
121122
run: |
122-
cargo test --release --features sqlite,mysql,postgresql,enable_mimalloc
123+
cargo test --features sqlite,mysql,postgresql,enable_mimalloc
123124
124125
- name: "test features: sqlite,mysql,postgresql"
125126
id: test_sqlite_mysql_postgresql
126127
if: $${{ always() }}
127128
run: |
128-
cargo test --release --features sqlite,mysql,postgresql
129+
cargo test --features sqlite,mysql,postgresql
129130
130131
- name: "test features: sqlite"
131132
id: test_sqlite
132133
if: $${{ always() }}
133134
run: |
134-
cargo test --release --features sqlite
135+
cargo test --features sqlite
135136
136137
- name: "test features: mysql"
137138
id: test_mysql
138139
if: $${{ always() }}
139140
run: |
140-
cargo test --release --features mysql
141+
cargo test --features mysql
141142
142143
- name: "test features: postgresql"
143144
id: test_postgresql
144145
if: $${{ always() }}
145146
run: |
146-
cargo test --release --features postgresql
147+
cargo test --features postgresql
147148
# End Run cargo tests
148149

149150

150-
# Run cargo clippy, and fail on warnings (In release mode to speed up future builds)
151+
# Run cargo clippy, and fail on warnings
151152
- name: "clippy features: sqlite,mysql,postgresql,enable_mimalloc"
152153
id: clippy
153154
if: ${{ always() && matrix.channel == 'rust-toolchain' }}
154155
run: |
155-
cargo clippy --release --features sqlite,mysql,postgresql,enable_mimalloc -- -D warnings
156+
cargo clippy --features sqlite,mysql,postgresql,enable_mimalloc -- -D warnings
156157
# End Run cargo clippy
157158

158159

@@ -194,21 +195,3 @@ jobs:
194195
run: |
195196
echo "### :tada: Checks Passed!" >> $GITHUB_STEP_SUMMARY
196197
echo "" >> $GITHUB_STEP_SUMMARY
197-
198-
199-
# Build the binary to upload to the artifacts
200-
- name: "build features: sqlite,mysql,postgresql"
201-
if: ${{ matrix.channel == 'rust-toolchain' }}
202-
run: |
203-
cargo build --release --features sqlite,mysql,postgresql
204-
# End Build the binary
205-
206-
207-
# Upload artifact to Github Actions
208-
- name: "Upload artifact"
209-
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
210-
if: ${{ matrix.channel == 'rust-toolchain' }}
211-
with:
212-
name: vaultwarden
213-
path: target/release/vaultwarden
214-
# End Upload artifact to Github Actions

.github/workflows/hadolint.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ jobs:
1616
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
1717
# End Checkout the repo
1818

19-
2019
# Download hadolint - https://github.com/hadolint/hadolint/releases
2120
- name: Download hadolint
2221
shell: bash
@@ -30,5 +29,5 @@ jobs:
3029
# Test Dockerfiles
3130
- name: Run hadolint
3231
shell: bash
33-
run: git ls-files --exclude='docker/*/Dockerfile*' --ignored --cached | xargs hadolint
32+
run: hadolint docker/Dockerfile.{debian,alpine}
3433
# End Test Dockerfiles

.github/workflows/release.yml

+70-135
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ on:
66
- ".github/workflows/release.yml"
77
- "src/**"
88
- "migrations/**"
9-
- "hooks/**"
109
- "docker/**"
1110
- "Cargo.*"
1211
- "build.rs"
@@ -15,6 +14,7 @@ on:
1514

1615
branches: # Only on paths above
1716
- main
17+
- release-build-revision
1818

1919
tags: # Always, regardless of paths above
2020
- '*'
@@ -35,23 +35,20 @@ jobs:
3535
with:
3636
cancel_others: 'true'
3737
# Only run this when not creating a tag
38-
if: ${{ startsWith(github.ref, 'refs/heads/') }}
38+
if: ${{ github.ref_type == 'branch' }}
3939

4040
docker-build:
4141
runs-on: ubuntu-22.04
4242
timeout-minutes: 120
4343
needs: skip_check
44-
# Start a local docker registry to be used to generate multi-arch images.
45-
services:
46-
registry:
47-
image: registry:2
48-
ports:
49-
- 5000:5000
44+
if: ${{ needs.skip_check.outputs.should_skip != 'true' && github.repository == 'dani-garcia/vaultwarden' }}
45+
# TODO: Start a local docker registry to be used to extract the final Alpine static build images
46+
# services:
47+
# registry:
48+
# image: registry:2
49+
# ports:
50+
# - 5000:5000
5051
env:
51-
# Use BuildKit (https://docs.docker.com/build/buildkit/) for better
52-
# build performance and the ability to copy extended file attributes
53-
# (e.g., for executable capabilities) across build phases.
54-
DOCKER_BUILDKIT: 1
5552
SOURCE_COMMIT: ${{ github.sha }}
5653
SOURCE_REPOSITORY_URL: "https://github.com/${{ github.repository }}"
5754
# The *_REPO variables need to be configured as repository variables
@@ -65,7 +62,6 @@ jobs:
6562
# QUAY_REPO needs to be 'quay.io/<user>/<repo>'
6663
# Check for Quay.io credentials in secrets
6764
HAVE_QUAY_LOGIN: ${{ vars.QUAY_REPO != '' && secrets.QUAY_USERNAME != '' && secrets.QUAY_TOKEN != '' }}
68-
if: ${{ needs.skip_check.outputs.should_skip != 'true' && github.repository == 'dani-garcia/vaultwarden' }}
6965
strategy:
7066
matrix:
7167
base_image: ["debian","alpine"]
@@ -77,18 +73,43 @@ jobs:
7773
with:
7874
fetch-depth: 0
7975

80-
# Determine Docker Tag
81-
- name: Init Variables
82-
id: vars
76+
- name: Initialize QEMU binfmt support
77+
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0
78+
with:
79+
platforms: "arm64,arm"
80+
81+
# Start Docker Buildx
82+
- name: Setup Docker Buildx
83+
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
84+
# https://github.com/moby/buildkit/issues/3969
85+
# Also set max parallelism to 2, the default of 4 breaks GitHub Actions
86+
with:
87+
config-inline: |
88+
[worker.oci]
89+
max-parallelism = 2
90+
driver-opts: |
91+
network=host
92+
93+
# Determine Base Tags and Source Version
94+
- name: Determine Base Tags and Source Version
8395
shell: bash
8496
run: |
85-
# Check which main tag we are going to build determined by github.ref
86-
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
87-
echo "DOCKER_TAG=${GITHUB_REF#refs/*/}" | tee -a "${GITHUB_OUTPUT}"
88-
elif [[ "${{ github.ref }}" == refs/heads/* ]]; then
89-
echo "DOCKER_TAG=testing" | tee -a "${GITHUB_OUTPUT}"
97+
# Check which main tag we are going to build determined by github.ref_type
98+
if [[ "${{ github.ref_type }}" == "tag" ]]; then
99+
echo "BASE_TAGS=latest,${GITHUB_REF#refs/*/}" | tee -a "${GITHUB_ENV}"
100+
elif [[ "${{ github.ref_type }}" == "branch" ]]; then
101+
echo "BASE_TAGS=testing" | tee -a "${GITHUB_ENV}"
102+
fi
103+
104+
# Get the Source Version for this release
105+
GIT_EXACT_TAG="$(git describe --tags --abbrev=0 --exact-match 2>/dev/null || true)"
106+
if [[ -n "${GIT_EXACT_TAG}" ]]; then
107+
echo "SOURCE_VERSION=${GIT_EXACT_TAG}" | tee -a "${GITHUB_ENV}"
108+
else
109+
GIT_LAST_TAG="$(git describe --tags --abbrev=0)"
110+
echo "SOURCE_VERSION=${GIT_LAST_TAG}-${SOURCE_COMMIT:0:8}" | tee -a "${GITHUB_ENV}"
90111
fi
91-
# End Determine Docker Tag
112+
# End Determine Base Tags
92113

93114
# Login to Docker Hub
94115
- name: Login to Docker Hub
@@ -98,6 +119,12 @@ jobs:
98119
password: ${{ secrets.DOCKERHUB_TOKEN }}
99120
if: ${{ env.HAVE_DOCKERHUB_LOGIN == 'true' }}
100121

122+
- name: Add registry for DockerHub
123+
if: ${{ env.HAVE_DOCKERHUB_LOGIN == 'true' }}
124+
shell: bash
125+
run: |
126+
echo "CONTAINER_REGISTRIES=${{ vars.DOCKERHUB_REPO }}" | tee -a "${GITHUB_ENV}"
127+
101128
# Login to GitHub Container Registry
102129
- name: Login to GitHub Container Registry
103130
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
@@ -107,6 +134,12 @@ jobs:
107134
password: ${{ secrets.GITHUB_TOKEN }}
108135
if: ${{ env.HAVE_GHCR_LOGIN == 'true' }}
109136

137+
- name: Add registry for ghcr.io
138+
if: ${{ env.HAVE_GHCR_LOGIN == 'true' }}
139+
shell: bash
140+
run: |
141+
echo "CONTAINER_REGISTRIES=${CONTAINER_REGISTRIES:+${CONTAINER_REGISTRIES},}${{ vars.GHCR_REPO }}" | tee -a "${GITHUB_ENV}"
142+
110143
# Login to Quay.io
111144
- name: Login to Quay.io
112145
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
@@ -116,120 +149,22 @@ jobs:
116149
password: ${{ secrets.QUAY_TOKEN }}
117150
if: ${{ env.HAVE_QUAY_LOGIN == 'true' }}
118151

119-
# Debian
120-
121-
# Docker Hub
122-
- name: Build Debian based images (docker.io)
123-
shell: bash
124-
env:
125-
DOCKER_REPO: "${{ vars.DOCKERHUB_REPO }}"
126-
DOCKER_TAG: "${{steps.vars.outputs.DOCKER_TAG}}"
127-
run: |
128-
./hooks/build
129-
if: ${{ matrix.base_image == 'debian' && env.HAVE_DOCKERHUB_LOGIN == 'true' }}
130-
131-
- name: Push Debian based images (docker.io)
132-
shell: bash
133-
env:
134-
DOCKER_REPO: "${{ vars.DOCKERHUB_REPO }}"
135-
DOCKER_TAG: "${{steps.vars.outputs.DOCKER_TAG}}"
136-
run: |
137-
./hooks/push
138-
if: ${{ matrix.base_image == 'debian' && env.HAVE_DOCKERHUB_LOGIN == 'true' }}
139-
140-
# GitHub Container Registry
141-
- name: Build Debian based images (ghcr.io)
142-
shell: bash
143-
env:
144-
DOCKER_REPO: "${{ vars.GHCR_REPO }}"
145-
DOCKER_TAG: "${{steps.vars.outputs.DOCKER_TAG}}"
146-
run: |
147-
./hooks/build
148-
if: ${{ matrix.base_image == 'debian' && env.HAVE_GHCR_LOGIN == 'true' }}
149-
150-
- name: Push Debian based images (ghcr.io)
151-
shell: bash
152-
env:
153-
DOCKER_REPO: "${{ vars.GHCR_REPO }}"
154-
DOCKER_TAG: "${{steps.vars.outputs.DOCKER_TAG}}"
155-
run: |
156-
./hooks/push
157-
if: ${{ matrix.base_image == 'debian' && env.HAVE_GHCR_LOGIN == 'true' }}
158-
159-
# Quay.io
160-
- name: Build Debian based images (quay.io)
161-
shell: bash
162-
env:
163-
DOCKER_REPO: "${{ vars.QUAY_REPO }}"
164-
DOCKER_TAG: "${{steps.vars.outputs.DOCKER_TAG}}"
165-
run: |
166-
./hooks/build
167-
if: ${{ matrix.base_image == 'debian' && env.HAVE_QUAY_LOGIN == 'true' }}
168-
169-
- name: Push Debian based images (quay.io)
170-
shell: bash
171-
env:
172-
DOCKER_REPO: "${{ vars.QUAY_REPO }}"
173-
DOCKER_TAG: "${{steps.vars.outputs.DOCKER_TAG}}"
174-
run: |
175-
./hooks/push
176-
if: ${{ matrix.base_image == 'debian' && env.HAVE_QUAY_LOGIN == 'true' }}
177-
178-
# Alpine
179-
180-
# Docker Hub
181-
- name: Build Alpine based images (docker.io)
182-
shell: bash
183-
env:
184-
DOCKER_REPO: "${{ vars.DOCKERHUB_REPO }}"
185-
DOCKER_TAG: "${{steps.vars.outputs.DOCKER_TAG}}-alpine"
186-
run: |
187-
./hooks/build
188-
if: ${{ matrix.base_image == 'alpine' && env.HAVE_DOCKERHUB_LOGIN == 'true' }}
189-
190-
- name: Push Alpine based images (docker.io)
191-
shell: bash
192-
env:
193-
DOCKER_REPO: "${{ vars.DOCKERHUB_REPO }}"
194-
DOCKER_TAG: "${{steps.vars.outputs.DOCKER_TAG}}-alpine"
195-
run: |
196-
./hooks/push
197-
if: ${{ matrix.base_image == 'alpine' && env.HAVE_DOCKERHUB_LOGIN == 'true' }}
198-
199-
# GitHub Container Registry
200-
- name: Build Alpine based images (ghcr.io)
201-
shell: bash
202-
env:
203-
DOCKER_REPO: "${{ vars.GHCR_REPO }}"
204-
DOCKER_TAG: "${{steps.vars.outputs.DOCKER_TAG}}-alpine"
205-
run: |
206-
./hooks/build
207-
if: ${{ matrix.base_image == 'alpine' && env.HAVE_GHCR_LOGIN == 'true' }}
208-
209-
- name: Push Alpine based images (ghcr.io)
210-
shell: bash
211-
env:
212-
DOCKER_REPO: "${{ vars.GHCR_REPO }}"
213-
DOCKER_TAG: "${{steps.vars.outputs.DOCKER_TAG}}-alpine"
214-
run: |
215-
./hooks/push
216-
if: ${{ matrix.base_image == 'alpine' && env.HAVE_GHCR_LOGIN == 'true' }}
217-
218-
# Quay.io
219-
- name: Build Alpine based images (quay.io)
152+
- name: Add registry for Quay.io
153+
if: ${{ env.HAVE_QUAY_LOGIN == 'true' }}
220154
shell: bash
221-
env:
222-
DOCKER_REPO: "${{ vars.QUAY_REPO }}"
223-
DOCKER_TAG: "${{steps.vars.outputs.DOCKER_TAG}}-alpine"
224155
run: |
225-
./hooks/build
226-
if: ${{ matrix.base_image == 'alpine' && env.HAVE_QUAY_LOGIN == 'true' }}
156+
echo "CONTAINER_REGISTRIES=${CONTAINER_REGISTRIES:+${CONTAINER_REGISTRIES},}${{ vars.QUAY_REPO }}" | tee -a "${GITHUB_ENV}"
227157
228-
- name: Push Alpine based images (quay.io)
229-
shell: bash
158+
- name: Bake ${{ matrix.base_image }} containers
159+
uses: docker/bake-action@511fde2517761e303af548ec9e0ea74a8a100112 # v4.0.0
230160
env:
231-
DOCKER_REPO: "${{ vars.QUAY_REPO }}"
232-
DOCKER_TAG: "${{steps.vars.outputs.DOCKER_TAG}}-alpine"
233-
run: |
234-
./hooks/push
235-
if: ${{ matrix.base_image == 'alpine' && env.HAVE_QUAY_LOGIN == 'true' }}
161+
BASE_TAGS: "${{ env.BASE_TAGS }}"
162+
SOURCE_COMMIT: "${{ env.SOURCE_COMMIT }}"
163+
SOURCE_VERSION: "${{ env.SOURCE_VERSION }}"
164+
SOURCE_REPOSITORY_URL: "${{ env.SOURCE_REPOSITORY_URL }}"
165+
CONTAINER_REGISTRIES: "${{ env.CONTAINER_REGISTRIES }}"
166+
with:
167+
pull: true
168+
push: true
169+
files: docker/docker-bake.hcl
170+
targets: "${{ matrix.base_image }}-multi"

0 commit comments

Comments
 (0)