mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
feat(ci): move rust docker target bash to shell script
This commit is contained in:
parent
79f7c973e7
commit
124da02a42
5 changed files with 139 additions and 19 deletions
42
ci/Dockerfile.rust
Normal file
42
ci/Dockerfile.rust
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
FROM alpine:latest AS builder
|
||||
|
||||
WORKDIR /build
|
||||
|
||||
RUN apk add rustup build-base protoc
|
||||
# todo: arm64 target
|
||||
RUN rustup-init --default-host x86_64-unknown-linux-musl --default-toolchain nightly-2024-08-20 --profile default -y
|
||||
|
||||
ENV PATH=/root/.cargo/bin:$PATH
|
||||
ENV RUSTFLAGS='-C link-arg=-s'
|
||||
|
||||
RUN cargo install cargo-chef --locked
|
||||
|
||||
# build dependencies first to cache
|
||||
FROM builder AS recipe-builder
|
||||
COPY . .
|
||||
RUN cargo chef prepare --recipe-path recipe.json
|
||||
|
||||
FROM builder AS binary-builder
|
||||
COPY --from=recipe-builder /build/recipe.json recipe.json
|
||||
RUN cargo chef cook --release --recipe-path recipe.json --target x86_64-unknown-linux-musl
|
||||
|
||||
COPY Cargo.toml /build/
|
||||
COPY Cargo.lock /build/
|
||||
COPY proto/ /build/proto
|
||||
|
||||
# this needs to match workspaces in Cargo.toml
|
||||
COPY lib/libpk /build/lib/libpk
|
||||
COPY services/api/ /build/services/api
|
||||
COPY services/gateway/ /build/services/gateway
|
||||
COPY services/avatars/ /build/services/avatars
|
||||
|
||||
RUN cargo build --bin api --release --target x86_64-unknown-linux-musl
|
||||
RUN cargo build --bin gateway --release --target x86_64-unknown-linux-musl
|
||||
RUN cargo build --bin avatars --release --target x86_64-unknown-linux-musl
|
||||
|
||||
FROM scratch
|
||||
|
||||
COPY --from=binary-builder /build/target/x86_64-unknown-linux-musl/release/api /api
|
||||
COPY --from=binary-builder /build/target/x86_64-unknown-linux-musl/release/gateway /gateway
|
||||
COPY --from=binary-builder /build/target/x86_64-unknown-linux-musl/release/avatars /avatars
|
||||
COPY --from=binary-builder /build/target/x86_64-unknown-linux-musl/release/avatars /avatars
|
||||
42
ci/rust-docker-target.sh
Executable file
42
ci/rust-docker-target.sh
Executable file
|
|
@ -0,0 +1,42 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
#tag=
|
||||
#branch=
|
||||
#push=
|
||||
|
||||
build() {
|
||||
bin=$1
|
||||
extra=$2
|
||||
|
||||
f=$(mktemp)
|
||||
|
||||
cat > $f << EOF
|
||||
FROM alpine:latest
|
||||
COPY .docker-bin/$bin /bin/$bin
|
||||
$extra
|
||||
CMD ["/bin/$bin"]
|
||||
EOF
|
||||
|
||||
echo "building $dockerfile"
|
||||
|
||||
$dockerfile | docker build -t ghcr.io/pluralkit/$bin:$tag -f $f .
|
||||
|
||||
rm $f
|
||||
|
||||
if [ "$push" == "true" ]; then
|
||||
docker push ghcr.io/pluralkit/$bin:$tag
|
||||
docker image tag ghcr.io/pluralkit/$bin:$tag ghcr.io/pluralkit/$bin:$branch
|
||||
docker push ghcr.io/pluralkit/$bin:$branch
|
||||
if [ "$branch" == "main" ]; then
|
||||
docker image tag ghcr.io/pluralkit/$bin:$tag ghcr.io/pluralkit/$bin:latest
|
||||
docker push ghcr.io/pluralkit/$bin:latest
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# add rust binaries here to build
|
||||
build api
|
||||
build gateway
|
||||
build avatars
|
||||
Loading…
Add table
Add a link
Reference in a new issue