Skip to content

Commit b0f3ceb

Browse files
tronghntommytroenkimtore
committed
build: attempt multi-platform build
Co-authored-by: Tommy Trøen <[email protected]> Co-authored-by: Kim Tore Jensen <[email protected]>
1 parent ad56bb6 commit b0f3ceb

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

.github/workflows/build.yml

+1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ jobs:
2626
google_service_account: gh-texas
2727
push: true
2828
push_ghcr: true
29+
multi-platform: 'true'
2930
workload_identity_provider: ${{ secrets.NAIS_IO_WORKLOAD_IDENTITY_PROVIDER }}

Dockerfile

+30-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,34 @@
1-
FROM rust:alpine AS builder
2-
RUN apk add musl-dev
3-
COPY . /src
4-
WORKDIR /src
5-
RUN cargo build --release
1+
FROM --platform=$BUILDPLATFORM rust:1 as builder
2+
3+
WORKDIR /build
4+
ARG TARGETPLATFORM
5+
RUN \
6+
set -eux ; \
7+
if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
8+
apt-get --yes update && apt-get --yes install cmake musl-tools ; \
9+
rustup target add x86_64-unknown-linux-musl ; \
10+
elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
11+
apt-get --yes update && apt-get --yes install cmake musl-tools gcc-aarch64-linux-gnu ; \
12+
rustup target add aarch64-unknown-linux-musl ; \
13+
fi
14+
15+
COPY . .
16+
17+
RUN \
18+
set -eux ; \
19+
if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
20+
export TARGET=x86_64-unknown-linux-musl ; \
21+
elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
22+
export TARGET=aarch64-unknown-linux-musl ; \
23+
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-gnu-gcc ; \
24+
export CC_aarch64_unknown_linux_musl=aarch64-linux-gnu-gcc ; \
25+
export CXX_aarch64_unknown_linux_musl=aarch64-linux-gnu-g++ ; \
26+
fi ; \
27+
cargo test --release --target ${TARGET} -- --test-threads 1 ; \
28+
cargo build --release --target ${TARGET} && mkdir -p target/final/release/ && mv target/${TARGET}/release/texas target/final/release/texas ; \
29+
file target/final/release/texas
630

731
FROM gcr.io/distroless/static-debian12:nonroot
832
WORKDIR /app
9-
COPY --from=builder /src/target/release/texas /app/texas
33+
COPY --from=builder /build/target/final/release/texas /app/texas
1034
CMD ["/app/texas"]

src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub mod config {
1717
#[command(version, about, long_about = None)]
1818
pub struct Config {
1919
#[arg(short, long, env, default_value = "127.0.0.1:3000")]
20-
pub bind_address: String,
20+
pub bind_addr: String,
2121
#[arg(env)]
2222
pub maskinporten_client_id: String,
2323
#[arg(env)]
@@ -72,7 +72,7 @@ async fn main() {
7272
.route("/token", post(handlers::token)).with_state(state.clone())
7373
.route("/introspection", post(handlers::introspection).with_state(state.clone()));
7474

75-
let listener = tokio::net::TcpListener::bind(cfg.bind_address).await.unwrap();
75+
let listener = tokio::net::TcpListener::bind(cfg.bind_addr).await.unwrap();
7676

7777
info!("Serving on {:?}", listener.local_addr().unwrap());
7878

0 commit comments

Comments
 (0)