Add cross platform builds
This commit is contained in:
parent
aada6a3b87
commit
88c9364448
7 changed files with 104 additions and 15 deletions
5
.github/workflows/check.yml
vendored
5
.github/workflows/check.yml
vendored
|
|
@ -22,6 +22,11 @@ jobs:
|
||||||
with:
|
with:
|
||||||
node-version: "22.x"
|
node-version: "22.x"
|
||||||
check-latest: true
|
check-latest: true
|
||||||
|
|
||||||
|
- name: Setup Rust toolchain
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
with:
|
||||||
|
toolchain: "1.89.0"
|
||||||
|
|
||||||
- name: Setup rust
|
- name: Setup rust
|
||||||
run: |
|
run: |
|
||||||
|
|
|
||||||
5
.github/workflows/e2e.yml
vendored
5
.github/workflows/e2e.yml
vendored
|
|
@ -23,6 +23,11 @@ jobs:
|
||||||
node-version: "22.x"
|
node-version: "22.x"
|
||||||
check-latest: true
|
check-latest: true
|
||||||
|
|
||||||
|
- name: Setup Rust toolchain
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
with:
|
||||||
|
toolchain: "1.89.0"
|
||||||
|
|
||||||
- name: Setup rust
|
- name: Setup rust
|
||||||
run: |
|
run: |
|
||||||
cargo install sqlx-cli
|
cargo install sqlx-cli
|
||||||
|
|
|
||||||
2
.github/workflows/publish-docker.yml
vendored
2
.github/workflows/publish-docker.yml
vendored
|
|
@ -67,7 +67,7 @@ jobs:
|
||||||
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
|
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
|
||||||
with:
|
with:
|
||||||
context: sync-server
|
context: sync-server
|
||||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
platforms: linux/amd64,linux/arm64
|
||||||
push: ${{ github.ref_type == 'tag' }}
|
push: ${{ github.ref_type == 'tag' }}
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
|
|
||||||
15
.github/workflows/publish-plugin.yml
vendored
15
.github/workflows/publish-plugin.yml
vendored
|
|
@ -25,6 +25,19 @@ jobs:
|
||||||
cd frontend
|
cd frontend
|
||||||
npm ci
|
npm ci
|
||||||
npm run build
|
npm run build
|
||||||
|
|
||||||
|
- name: Setup Rust toolchain
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
with:
|
||||||
|
toolchain: "1.89.0"
|
||||||
|
|
||||||
|
- name: Install cross-compilation tools
|
||||||
|
run: |
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install -y gcc-aarch64-linux-gnu musl-tools gcc-mingw-w64-x86-64
|
||||||
|
|
||||||
|
- name: Build Linux and Windows binaries
|
||||||
|
run: ./scripts/build-sync-server-binaries.sh
|
||||||
|
|
||||||
- name: Create release
|
- name: Create release
|
||||||
env:
|
env:
|
||||||
|
|
@ -37,4 +50,4 @@ jobs:
|
||||||
gh release create "$tag" \
|
gh release create "$tag" \
|
||||||
--title="$tag" \
|
--title="$tag" \
|
||||||
--draft \
|
--draft \
|
||||||
main.js manifest.json styles.css
|
main.js manifest.json styles.css artifacts/sync-server-*
|
||||||
|
|
|
||||||
46
scripts/build-sync-server-binaries.sh
Executable file
46
scripts/build-sync-server-binaries.sh
Executable file
|
|
@ -0,0 +1,46 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
cd "$(dirname "$0")/../sync-server"
|
||||||
|
|
||||||
|
# Setup database
|
||||||
|
sqlx database create --database-url sqlite://db.sqlite3 2>/dev/null || true
|
||||||
|
sqlx migrate run --source src/app_state/database/migrations --database-url sqlite://db.sqlite3
|
||||||
|
|
||||||
|
targets=${@:-"x86_64-unknown-linux-gnu x86_64-unknown-linux-musl aarch64-unknown-linux-gnu x86_64-pc-windows-gnu"}
|
||||||
|
|
||||||
|
mkdir -p ../artifacts
|
||||||
|
rm -f ../artifacts/sync-server-*
|
||||||
|
|
||||||
|
|
||||||
|
for target in $targets; do
|
||||||
|
echo "Building $target..."
|
||||||
|
|
||||||
|
# Set linkers for cross-compilation
|
||||||
|
case "$target" in
|
||||||
|
aarch64-unknown-linux-gnu)
|
||||||
|
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc ;;
|
||||||
|
x86_64-unknown-linux-musl)
|
||||||
|
export CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=musl-gcc ;;
|
||||||
|
x86_64-pc-windows-gnu)
|
||||||
|
export CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER=x86_64-w64-mingw32-gcc ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
rustup target add "$target" 2>/dev/null || true
|
||||||
|
|
||||||
|
cargo build --release --target "$target"
|
||||||
|
ext=""
|
||||||
|
[[ "$target" == *windows* ]] && ext=".exe"
|
||||||
|
|
||||||
|
name="sync-server-${target//-/_}$ext"
|
||||||
|
name="${name//x86_64_unknown_linux_gnu/linux-x86_64}"
|
||||||
|
name="${name//x86_64_unknown_linux_musl/linux-x86_64-musl}"
|
||||||
|
name="${name//aarch64_unknown_linux_gnu/linux-aarch64}"
|
||||||
|
name="${name//x86_64_pc_windows_gnu/windows-x86_64}"
|
||||||
|
|
||||||
|
cp "target/$target/release/sync_server$ext" "../artifacts/$name"
|
||||||
|
echo "✓ Built $name"
|
||||||
|
done
|
||||||
|
|
||||||
|
ls -la ../artifacts/sync-server-*
|
||||||
|
|
@ -1,18 +1,33 @@
|
||||||
FROM rust:1.89-alpine AS builder
|
FROM rust:1.89-slim-trixie AS builder
|
||||||
|
|
||||||
|
ARG TARGETPLATFORM
|
||||||
WORKDIR /usr/src/backend
|
WORKDIR /usr/src/backend
|
||||||
|
|
||||||
# Install build dependencies for Alpine
|
# Set RUST_TARGET based on platform and create sourceable script
|
||||||
RUN apk add --no-cache musl-dev pkgconf openssl-dev perl make
|
RUN case "$TARGETPLATFORM" in \
|
||||||
|
"linux/amd64") echo 'export RUST_TARGET="x86_64-unknown-linux-musl"' > /tmp/rust_env ;; \
|
||||||
|
"linux/arm64") echo 'export RUST_TARGET="aarch64-unknown-linux-musl"' > /tmp/rust_env ;; \
|
||||||
|
"linux/arm/v7") echo 'export RUST_TARGET="armv7-unknown-linux-musleabihf"' > /tmp/rust_env ;; \
|
||||||
|
*) echo "Unsupported platform: $TARGETPLATFORM" && exit 1 ;; \
|
||||||
|
esac
|
||||||
|
|
||||||
# Install sqlx-cli
|
# Install musl tools, cross-compilation toolchains, and OpenSSL dev packages
|
||||||
RUN cargo install sqlx-cli --features=openssl-vendored
|
RUN . /tmp/rust_env && \
|
||||||
|
apt update && \
|
||||||
|
apt install -y musl-tools libssl-dev pkg-config \
|
||||||
|
gcc-aarch64-linux-gnu \
|
||||||
|
gcc-arm-linux-gnueabi &&\
|
||||||
|
rustup target add $RUST_TARGET && \
|
||||||
|
cargo install sqlx-cli
|
||||||
|
|
||||||
# Setup database and build
|
# Build application
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN sqlx database create --database-url sqlite://db.sqlite3 && \
|
|
||||||
|
RUN . /tmp/rust_env && \
|
||||||
|
export CFLAGS="-Wno-stringop-overread" && \
|
||||||
|
sqlx database create --database-url sqlite://db.sqlite3 && \
|
||||||
sqlx migrate run --source src/app_state/database/migrations --database-url sqlite://db.sqlite3 && \
|
sqlx migrate run --source src/app_state/database/migrations --database-url sqlite://db.sqlite3 && \
|
||||||
cargo build --release
|
cargo build --release --target $RUST_TARGET
|
||||||
|
|
||||||
# Runtime image
|
# Runtime image
|
||||||
FROM alpine:3.22.0
|
FROM alpine:3.22.0
|
||||||
|
|
@ -21,7 +36,7 @@ LABEL org.opencontainers.image.authors="andras@schmelczer.dev"
|
||||||
|
|
||||||
RUN apk add --no-cache curl ca-certificates
|
RUN apk add --no-cache curl ca-certificates
|
||||||
|
|
||||||
COPY --from=builder /usr/src/backend/target/release/sync_server /app/sync_server
|
COPY --from=builder /usr/src/backend/target/*/release/sync_server /app/sync_server
|
||||||
|
|
||||||
VOLUME /data
|
VOLUME /data
|
||||||
EXPOSE 3000/tcp
|
EXPOSE 3000/tcp
|
||||||
|
|
@ -30,4 +45,4 @@ WORKDIR /data
|
||||||
HEALTHCHECK --interval=30s --timeout=5s \
|
HEALTHCHECK --interval=30s --timeout=5s \
|
||||||
CMD curl -f http://localhost:3000/vaults/fake/ping || exit 1
|
CMD curl -f http://localhost:3000/vaults/fake/ping || exit 1
|
||||||
|
|
||||||
ENTRYPOINT ["/app/sync_server"]
|
ENTRYPOINT ["/app/sync_server"]
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,9 @@
|
||||||
[toolchain]
|
[toolchain]
|
||||||
channel = "1.89.0"
|
channel = "1.89.0"
|
||||||
targets = [ "x86_64-unknown-linux-gnu", "x86_64-unknown-linux-musl" ]
|
targets = [
|
||||||
|
"x86_64-unknown-linux-gnu",
|
||||||
|
"x86_64-unknown-linux-musl",
|
||||||
|
"aarch64-unknown-linux-gnu",
|
||||||
|
"x86_64-pc-windows-gnu",
|
||||||
|
]
|
||||||
profile = "default"
|
profile = "default"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue