Skip to content

Commit

Permalink
Merge pull request #13 from windsource/statically_linked
Browse files Browse the repository at this point in the history
Use static linking
  • Loading branch information
windsource authored Jul 21, 2024
2 parents 4cbb204 + 09a0a5e commit eb161f0
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 40 deletions.
11 changes: 11 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[target.x86_64-unknown-linux-gnu]
linker="x86_64-linux-gnu-gcc"

[target.x86_64-unknown-linux-musl]
linker="x86_64-linux-gnu-gcc"

[target.aarch64-unknown-linux-musl]
linker="aarch64-linux-gnu-gcc"

[target.aarch64-unknown-linux-gnu]
linker="aarch64-linux-gnu-gcc"
11 changes: 4 additions & 7 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

FROM mcr.microsoft.com/vscode/devcontainers/rust:1-1-bookworm

RUN dpkg --add-architecture arm64 && \
apt-get update && export DEBIAN_FRONTEND=noninteractive \
RUN apt update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends \
tmux \
vim \
gcc-aarch64-linux-gnu \
libssl-dev:arm64 \
libc6-dev:arm64
vim

RUN rustup target add aarch64-unknown-linux-gnu
RUN rustup target add x86_64-unknown-linux-musl \
&& rustup target add aarch64-unknown-linux-musl
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ target
temp
docker-compose.yml
.devcontainer/*.env
.cargo
.cargo/*
!.cargo/config.toml
46 changes: 18 additions & 28 deletions .woodpecker.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
variables:
- &rust 'rust:1.77.1-bookworm'
- &rust 'rust:1.79-bookworm'
- &buildx_plugin 'woodpeckerci/plugin-docker-buildx:2.1.0'

labels:
platform: linux/amd64

clone:
git:
image: woodpeckerci/plugin-git:2.2.0
image: woodpeckerci/plugin-git:2.5.1
when:
- event: pull_request
- event: [push, tag, manual]
Expand All @@ -16,39 +16,29 @@ clone:
steps:
- name: build-x86
image: *rust
commands: |
if [ "$CI_SYSTEM_PLATFORM" = "linux/amd64" ]; then
export CARGO_HOME=$(pwd)/.cargo/
cargo test
cargo build --release
mkdir -p target/linux/amd64
cp target/release/picus target/linux/amd64/picus
else
echo Unsupported platform!
exit1
fi
commands:
- apt update
- apt install -y musl-tools
- rustup target add x86_64-unknown-linux-musl
- export CARGO_HOME=$(pwd)/.cargo/
- cargo test --target x86_64-unknown-linux-musl
- cargo build --release --target x86_64-unknown-linux-musl
- cp target/x86_64-unknown-linux-musl/release/picus target/picus-linux-amd64
when:
- event: pull_request
- event: [push, tag, manual]
branch: main

- name: build-arm64
image: *rust
commands: |
if [ "$CI_SYSTEM_PLATFORM" = "linux/amd64" ]; then
dpkg --add-architecture arm64
apt-get update
export DEBIAN_FRONTED=noninteractive
apt-get -y install --no-install-recommends gcc-aarch64-linux-gnu libssl-dev:arm64 libc6-dev:arm64
rustup target add aarch64-unknown-linux-gnu
export CARGO_HOME=$(pwd)/.cargo/
RUSTFLAGS="-C linker=aarch64-linux-gnu-gcc" PKG_CONFIG_SYSROOT_DIR=/ cargo build --target aarch64-unknown-linux-gnu --release
mkdir -p target/linux/arm64
cp target/aarch64-unknown-linux-gnu/release/picus target/linux/arm64/
else
echo Unsupported platform!
exit1
fi
commands:
- dpkg --add-architecture arm64
- apt update
- apt install -y --no-install-recommends gcc-aarch64-linux-gnu musl-tools libc6-dev:arm64
- rustup target add aarch64-unknown-linux-musl
- export CARGO_HOME=$(pwd)/.cargo/
- cargo build --release --target aarch64-unknown-linux-musl
- cp target/aarch64-unknown-linux-musl/release/picus target/picus-linux-arm64
when:
- event: pull_request
- event: [push, tag, manual]
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.distroless.multiarch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM gcr.io/distroless/cc-debian12:nonroot
FROM gcr.io/distroless/static-debian12:nonroot

LABEL org.opencontainers.image.source https://github.com/windsource/picus

ARG TARGETOS TARGETARCH
COPY target/${TARGETOS}/${TARGETARCH}/picus /usr/local/bin/picus
COPY target/picus-${TARGETOS}-${TARGETARCH} /usr/local/bin/picus

CMD ["/usr/local/bin/picus"]
4 changes: 2 additions & 2 deletions Dockerfile.multiarch
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM debian:12.1-slim
FROM debian:12.6-slim

LABEL org.opencontainers.image.source https://github.com/windsource/picus

Expand All @@ -9,6 +9,6 @@ RUN groupadd -g 999 appuser && \
USER appuser

ARG TARGETOS TARGETARCH
COPY target/${TARGETOS}/${TARGETARCH}/picus /usr/local/bin/picus
COPY target/picus-${TARGETOS}-${TARGETARCH} /usr/local/bin/picus

CMD ["/usr/local/bin/picus"]

0 comments on commit eb161f0

Please sign in to comment.