Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Docker build for musl + update packages #3

Merged
merged 3 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ rustflags = ["-C", "link-args=-latomic"]
linker = "aarch64-linux-gnu-gcc"

[target.aarch64-unknown-linux-musl]
# The included linker for this target doesn't seem to work.
linker = "rust-lld"

[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"

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

# Use the sparse registry protocol for Cargo.
[registries.crates-io]
Expand Down
23 changes: 12 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "deltio"
version = "0.3.0"
version = "0.3.1"
edition = "2021"
authors = ["Jeff Hansen"]
description = "A Google Cloud Pub/Sub emulator alternative for local testing and CI"
Expand All @@ -23,7 +23,7 @@ parking_lot = "0.12.1"
log = "0.4.17"
env_logger = "0.10.0"
lazy_static = "1.4.0"
clap = { version = "4.2.7", features = ["derive"] }
clap = { version = "4.2.7", features = ["derive", "cargo"] }

# MiMalloc does not currently cross-compile for `i686-unknown-linux-musl` target,
# so we'll disable MiMalloc for x86 Linux for now.
Expand Down
25 changes: 9 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM --platform=$BUILDPLATFORM rust:1.69 as build

# Install Protocol Buffers.
RUN apt-get update && apt-get install -y protobuf-compiler
RUN apt-get update && apt-get install -y protobuf-compiler musl-tools musl-dev

# Create a new empty project.
RUN cargo new --bin deltio
Expand All @@ -22,17 +22,11 @@ ARG BUILDPLATFORM
# IMPORTANT: This only seems to work on a x86_64 Linux build platform.
RUN <<EOF
set -e;

# If the build platform is the same as the target platform, we don't
# need any more packages.
if [ "$BUILDPLATFORM" = "$TARGETPLATFORM" ]; then
echo "Build and target platform are the same, won't install extra stuff"
exit 0
fi

echo "Build platform: $BUILDPLATFORM"
echo "Target platform: $TARGETPLATFORM"
apt-get update
# This is the file we will be writing the compilation target to for
# subsequent steps.
touch .target

if [ "$TARGETPLATFORM" = "linux/arm64" ]; then
# musl-cross isn't available via apt-get, so have to download and install it manually.
mkdir /opt/musl-cross
Expand All @@ -41,7 +35,6 @@ RUN <<EOF
rustup target add aarch64-unknown-linux-musl
echo -n "aarch64-unknown-linux-musl" > .target
else
apt-get install -y musl-tools
if [ "$TARGETPLATFORM" = "linux/amd64" ]; then
rustup target add x86_64-unknown-linux-musl
echo -n "x86_64-unknown-linux-musl" > .target
Expand All @@ -66,11 +59,11 @@ RUN <<EOF

# If the build platform is the same as the target platform, we don't
# need to use any target.
if [ "$BUILDPLATFORM" = "$TARGETPLATFORM" ]; then
TARGET=$(cat .target)
if [ -z "$TARGET" ]; then
cargo build --release
rm ./target/release/deps/deltio*
else
TARGET=$(cat .target)
cargo build --target "$TARGET" --release
rm ./target/*/release/deps/deltio*
fi
Expand All @@ -89,12 +82,12 @@ RUN <<EOF
set -e;
# If the build platform is the same as the target platform, we don't
# need to use any target.
if [ "$BUILDPLATFORM" = "$TARGETPLATFORM" ]; then
TARGET=$(cat .target)
if [ -z "$TARGET" ]; then
cargo build --release
exit 0
fi

TARGET=$(cat .target)
cargo build --target "$TARGET" --release
mv "target/$TARGET/release/deltio" "target/release/deltio"
EOF
Expand Down
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ async fn main_core(args: Cli) -> Result<(), Box<dyn std::error::Error>> {
let server = make_server_builder();

// Start listening (TCP).
log::info!("Deltio starting, listening on {}", &args.bind);
log::info!(
"Deltio v{} starting, listening on {}",
clap::crate_version!(),
&args.bind
);
server.serve_with_shutdown(args.bind, signal).await?;

log::info!("Deltio stopped");
Expand Down