Skip to content

Commit

Permalink
use musl builds for docker and homebrew
Browse files Browse the repository at this point in the history
  • Loading branch information
deepu105 committed Jan 22, 2024
1 parent 4d4a6cf commit 9de75a7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 34 deletions.
42 changes: 22 additions & 20 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ jobs:
matrix:
# prettier-ignore
job:
- { name: "macOS-arm64", os: "macOS-latest", target: "aarch64-apple-darwin", artifact_prefix: "macos-arm64", use-cross: true }
- { name: "macOS-amd64", os: "macOS-latest", target: "x86_64-apple-darwin", artifact_prefix: "macos" }
- { name: "windows-amd64", os: "windows-latest", target: "x86_64-pc-windows-msvc", artifact_prefix: "windows" }
- { name: "windows-aarch64", os: "windows-latest", target: "aarch64-pc-windows-msvc", artifact_prefix: "windows-aarch64", use-cross: true }
- { name: "linux-gnu", os: "ubuntu-latest", target: "x86_64-unknown-linux-gnu", artifact_prefix: "linux" }
- { name: "linux-musl", os: "ubuntu-latest", target: "x86_64-unknown-linux-musl", artifact_prefix: "linux-musl", use-cross: true, }
- { name: "linux-aarch64-gnu", os: "ubuntu-latest", target: "aarch64-unknown-linux-gnu", artifact_prefix: "aarch64-gnu", use-cross: true, test-bin: "--bin kdash" }
- { name: "linux-aarch64-musl", os: "ubuntu-latest", target: "aarch64-unknown-linux-musl", artifact_prefix: "aarch64-musl", use-cross: true, test-bin: "--bin kdash" }
- { name: "linux-arm-gnu", os: "ubuntu-latest", target: "arm-unknown-linux-gnueabi", artifact_prefix: "armv6-gnu", use-cross: true, test-bin: "--bin kdash" }
- { name: "linux-arm-musl", os: "ubuntu-latest", target: "arm-unknown-linux-musleabihf", artifact_prefix: "armv6-musl", use-cross: true, test-bin: "--bin kdash" }
- { name: "linux-armv7-gnu", os: "ubuntu-latest", target: "armv7-unknown-linux-gnueabihf", artifact_prefix: "armv7-gnu", use-cross: true, test-bin: "--bin kdash" }
- { name: "linux-armv7-musl", os: "ubuntu-latest", target: "armv7-unknown-linux-musleabihf", artifact_prefix: "armv7-musl", use-cross: true, test-bin: "--bin kdash" }
- { name: "macOS-arm64", os: "macOS-latest", target: "aarch64-apple-darwin", artifact_suffix: "macos-arm64", use-cross: true }
- { name: "macOS-amd64", os: "macOS-latest", target: "x86_64-apple-darwin", artifact_suffix: "macos" }
- { name: "windows-amd64", os: "windows-latest", target: "x86_64-pc-windows-msvc", artifact_suffix: "windows" }
- { name: "windows-aarch64", os: "windows-latest", target: "aarch64-pc-windows-msvc", artifact_suffix: "windows-aarch64", use-cross: true }
- { name: "linux-gnu", os: "ubuntu-latest", target: "x86_64-unknown-linux-gnu", artifact_suffix: "linux" }
- { name: "linux-musl", os: "ubuntu-latest", target: "x86_64-unknown-linux-musl", artifact_suffix: "linux-musl", use-cross: true, }
- { name: "linux-aarch64-gnu", os: "ubuntu-latest", target: "aarch64-unknown-linux-gnu", artifact_suffix: "aarch64-gnu", use-cross: true, test-bin: "--bin kdash" }
- { name: "linux-aarch64-musl", os: "ubuntu-latest", target: "aarch64-unknown-linux-musl", artifact_suffix: "aarch64-musl", use-cross: true, test-bin: "--bin kdash" }
- { name: "linux-arm-gnu", os: "ubuntu-latest", target: "arm-unknown-linux-gnueabi", artifact_suffix: "armv6-gnu", use-cross: true, test-bin: "--bin kdash" }
- { name: "linux-arm-musl", os: "ubuntu-latest", target: "arm-unknown-linux-musleabihf", artifact_suffix: "armv6-musl", use-cross: true, test-bin: "--bin kdash" }
- { name: "linux-armv7-gnu", os: "ubuntu-latest", target: "armv7-unknown-linux-gnueabihf", artifact_suffix: "armv7-gnu", use-cross: true, test-bin: "--bin kdash" }
- { name: "linux-armv7-musl", os: "ubuntu-latest", target: "armv7-unknown-linux-musleabihf", artifact_suffix: "armv7-musl", use-cross: true, test-bin: "--bin kdash" }
rust: [stable]

steps:
Expand Down Expand Up @@ -102,7 +102,7 @@ jobs:
shell: bash
run: |
sudo apt-get -y update
sudo apt-get -y install -qq pkg-config libssl-dev libxcb1-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev musl-tools
sudo apt-get -y install -qq pkg-config libssl-dev
case ${{ matrix.job.target }} in
arm*-linux-*) sudo apt-get -y install gcc-arm-linux-gnueabihf ;;
aarch64-*-linux-*) sudo apt-get -y install gcc-aarch64-linux-gnu ;;
Expand All @@ -124,9 +124,11 @@ jobs:
run: |
cd target/${{ matrix.job.target }}/release
BINARY_NAME=kdash.exe
# strip the binary
strip $BINARY_NAME
RELEASE_NAME=kdash-${{ matrix.job.artifact_prefix }}
if [ "${{ matrix.job.target }}" != "aarch64-pc-windows-msvc" ]; then
# strip the binary
strip $BINARY_NAME
fi
RELEASE_NAME=kdash-${{ matrix.job.artifact_suffix }}
tar czvf $RELEASE_NAME.tar.gz $BINARY_NAME
# create sha checksum files
certutil -hashfile $RELEASE_NAME.tar.gz sha256 | grep -E [A-Fa-f0-9]{64} > $RELEASE_NAME.sha256
Expand All @@ -146,7 +148,7 @@ jobs:
BINARY_NAME=kdash
# strip the binary
"$STRIP" "$BINARY_NAME"
RELEASE_NAME=kdash-${{ matrix.job.artifact_prefix }}
RELEASE_NAME=kdash-${{ matrix.job.artifact_suffix }}
tar czvf $RELEASE_NAME.tar.gz $BINARY_NAME
# create sha checksum files
shasum -a 256 $RELEASE_NAME.tar.gz > $RELEASE_NAME.sha256
Expand Down Expand Up @@ -194,7 +196,7 @@ jobs:
echo "MACOS_SHA=$macos_sha" >> $GITHUB_ENV
macos_sha_arm="$(cat ./artifacts/kdash-macos-arm64.sha256 | awk '{print $1}')"
echo "MACOS_SHA_ARM=$macos_sha_arm" >> $GITHUB_ENV
linux_sha="$(cat ./artifacts/kdash-linux.sha256 | awk '{print $1}')"
linux_sha="$(cat ./artifacts/kdash-linux-musl.sha256 | awk '{print $1}')"
echo "LINUX_SHA=$linux_sha" >> $GITHUB_ENV
release_version="$(cat ./artifacts/release-version)"
echo "RELEASE_VERSION=$release_version" >> $GITHUB_ENV
Expand All @@ -203,7 +205,7 @@ jobs:
run: |
echo "Release SHA macos: ${{ env.MACOS_SHA }}"
echo "Release SHA macos-arm: ${{ env.MACOS_SHA_ARM }}"
echo "Release SHA linux: ${{ env.LINUX_SHA }}"
echo "Release SHA linux musl: ${{ env.LINUX_SHA }}"
echo "Release version: ${{ env.RELEASE_VERSION }}"
- name: Execute Homebrew packaging script
Expand Down Expand Up @@ -335,5 +337,5 @@ jobs:
- uses: dtolnay/rust-toolchain@stable
- run: |
sudo apt-get update
sudo apt-get install -y -qq pkg-config libssl-dev libxcb1-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev
sudo apt-get install -y -qq pkg-config libssl-dev
- run: cargo publish --token ${{ secrets.CARGO_API_KEY }} --allow-dirty
22 changes: 9 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,35 @@
# Build Kdash base image
# -----------------------------

FROM rust as builder
FROM clux/muslrust:stable AS builder
WORKDIR /usr/src

# Download and compile Rust dependencies in an empty project and cache as a separate Docker layer
RUN USER=root cargo new --bin kdash-temp

WORKDIR /usr/src/kdash-temp
COPY ./Cargo.lock ./Cargo.lock
COPY ./Cargo.toml ./Cargo.toml
COPY Cargo.* .
RUN cargo build --release --target x86_64-unknown-linux-musl
# remove src form empty project
# remove src from empty project
RUN rm -r src

# Copy actual source files and Build the app binary
COPY src ./src
# remove previous deps
RUN rm ./target/x86_64-unknown-linux-musl/release/deps/kdash*
# due to cargo bug https://github.com/rust-lang/rust/issues/25289
RUN apt-get update && \
apt-get dist-upgrade -y && \
apt-get install -y -qq pkg-config libssl-dev libxcb1-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev

RUN RUST_BACKTRACE=1 RUSTFLAGS="-Ctarget-feature=-crt-static" cargo rustc --release --target x86_64-unknown-linux-musl
# RUN RUST_BACKTRACE=1 cargo build --release --target x86_64-unknown-linux-gnu
RUN --mount=type=cache,target=/volume/target \
--mount=type=cache,target=/root/.cargo/registry \
cargo build --release --target x86_64-unknown-linux-musl --bin kdash
RUN mv target/x86_64-unknown-linux-musl/release/kdash .

# -----------------------------
# build final Kdash image
# -----------------------------

FROM debian:stable-slim

ARG KUBECTL_VERSION="v1.29.0"
# Copy the compiled binary from the builder container
COPY --from=builder /usr/src/kdash-temp/target/x86_64-unknown-linux-musl/release/kdash /usr/local/bin
COPY --from=builder --chown=nonroot:nonroot /usr/src/kdash-temp/kdash /usr/local/bin

# Install dependencies like kubectl
RUN apt-get update && \
Expand Down
2 changes: 1 addition & 1 deletion deployment/homebrew/kdash.rb.template
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Kdash < Formula
url "https://github.com/kdash-rs/kdash/releases/download/$version/kdash-macos.tar.gz"
sha256 "$hash_mac"
else
url "https://github.com/kdash-rs/kdash/releases/download/$version/kdash-linux.tar.gz"
url "https://github.com/kdash-rs/kdash/releases/download/$version/kdash-linux-musl.tar.gz"
sha256 "$hash_linux"
end
version "$version"
Expand Down

0 comments on commit 9de75a7

Please sign in to comment.