From 6cd87fe4092fc9eac97acb9b602e0c463cab5496 Mon Sep 17 00:00:00 2001 From: Clem Date: Sun, 10 Mar 2024 12:19:18 +0100 Subject: [PATCH] wip2 rtabby docker workflow --- .github/workflows/rtabby.yml | 7 +++++++ Cargo.toml | 2 +- Dockerfile | 8 ++++---- build.rs | 4 ++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.github/workflows/rtabby.yml b/.github/workflows/rtabby.yml index 3e6d231..f04a144 100644 --- a/.github/workflows/rtabby.yml +++ b/.github/workflows/rtabby.yml @@ -50,10 +50,14 @@ jobs: # Install the cosign tool except on PR # https://github.com/sigstore/cosign-installer - name: Install cosign + if: ${{ github.event_name == 'release' }} uses: sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 #v3.1.1 with: cosign-release: 'v2.1.1' + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + # Set up BuildKit Docker container builder to be able to build # multi-platform images and export cache # https://github.com/docker/setup-buildx-action @@ -63,6 +67,7 @@ jobs: # Login against a Docker registry except on PR # https://github.com/docker/login-action - name: Log into registry ${{ env.REGISTRY }} + if: ${{ github.event_name == 'release' }} uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 with: registry: ${{ env.REGISTRY }} @@ -109,6 +114,7 @@ jobs: uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0 with: context: . + platforms: linux/amd64,linux/arm64 push: ${{ github.event_name == 'release' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} @@ -116,6 +122,7 @@ jobs: cache-to: type=gha,mode=max build-args: | GIT_COMMIT=${{ steps.prep.outputs.GIT_COMMIT }} + FEATURE_FLAGS=-F|${{ matrix.db }}-bundle${{ matrix.minimal && '' || '|-F|all-login' }} # Sign the resulting Docker image digest except on PRs. # This will only write to the public Rekor transparency log when the Docker diff --git a/Cargo.toml b/Cargo.toml index 092de5f..43896ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" default = ["mysql", "all-login"] dotenv = ["dep:dotenvy"] mysql = ["diesel/mysql"] -mysqlclient-static = ["mysql"] +mysqlclient-bundle = ["mysql"] sqlite = ["diesel/sqlite"] sqlite-bundle = ["sqlite", "libsqlite3-sys/bundled"] third-party-login = ["dep:actix-session", "dep:tera", "dep:reqwest", "dep:actix-files"] diff --git a/Dockerfile b/Dockerfile index 01bcfd2..bc876e3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,12 @@ # syntax=docker/dockerfile:1 FROM rust:1.76-alpine AS builder -ARG FEATURE_FLAGS="-F|mysqlclient-static|-F|github-login" +ARG FEATURE_FLAGS="-F|mysqlclient-bundle|-F|all-login" WORKDIR /build COPY . . RUN apk add --no-cache build-base -RUN if [[ "$FEATURE_FLAGS" == *"mysqlclient-static"* ]]; then \ +RUN if [[ "$FEATURE_FLAGS" == *"mysqlclient-bundle"* ]]; then \ apk add --no-cache binutils mariadb-dev musl-dev bash cmake curl && \ bash scripts/mariadb-static-build.sh && \ bash scripts/zlib-static-build.sh && \ @@ -24,14 +24,14 @@ RUN if [[ "$FEATURE_FLAGS" == *"login"* ]]; then \ fi -RUN cargo build --target=x86_64-unknown-linux-musl --release $(echo "$FEATURE_FLAGS" | sed 's/|/ /g') +RUN cargo build --release --no-default-features --target-dir /build/target/docker $(echo "$FEATURE_FLAGS" | sed 's/|/ /g') FROM scratch ARG GIT_COMMIT WORKDIR /config -COPY --from=builder /build/target/x86_64-unknown-linux-musl/release/rtabby-web-api / +COPY --from=builder /build/target/docker/release/rtabby-web-api / COPY --from=builder /build/users.exemple.yml . COPY --from=builder /build/web/ /www/web/ ENV STATIC_FILES_BASE_DIR=/www/web/ diff --git a/build.rs b/build.rs index 2c216f0..b03b6ad 100644 --- a/build.rs +++ b/build.rs @@ -1,9 +1,9 @@ fn main() { - #[cfg(feature = "mysqlclient-static")] + #[cfg(feature = "mysqlclient-bundle")] mysqlclient_static(); } -#[cfg(feature = "mysqlclient-static")] +#[cfg(feature = "mysqlclient-bundle")] fn mysqlclient_static() { println!("cargo:rustc-link-search=native=lib"); println!("cargo:rustc-link-lib=static=mysqlclient");