Skip to content

Commit

Permalink
perf: docker use musl
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgazelka committed Dec 14, 2024
1 parent e785f91 commit f9ebf83
Showing 1 changed file with 27 additions and 34 deletions.
61 changes: 27 additions & 34 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
# Define base arguments for versioning and optimization
# Define base arguments
ARG RUST_NIGHTLY_VERSION=nightly-2024-11-29
ARG RUSTFLAGS="-Z share-generics=y -Z threads=8"
ARG CARGO_HOME=/usr/local/cargo
ARG ALPINE_VERSION=3.21

# Use Ubuntu as base image
FROM ubuntu:22.04 AS packages
# Use Alpine as base image for packages
FROM alpine:${ALPINE_VERSION} AS packages

# Prevent apt from prompting for user input
ENV DEBIAN_FRONTEND=noninteractive

# Install essential build packages
FROM ubuntu:22.04 AS packages
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y \
curl \
build-essential \
libssl-dev \
pkg-config \
cmake \
perl \
gcc \
linux-headers-generic \
libclang1 \
llvm-dev \
libclang-dev \
&& rm -rf /var/lib/apt/lists/*
# Install packages needed for build
RUN apk add --no-cache \
curl \
build-base \
openssl-dev \
pkgconfig \
cmake \
perl \
gcc \
linux-headers \
clang-dev \
llvm-dev \
musl-dev

# Base builder stage with Rust installation
FROM packages AS builder-base
Expand All @@ -34,9 +28,11 @@ ARG RUSTFLAGS
ARG CARGO_HOME
ENV RUSTFLAGS=${RUSTFLAGS}
ENV CARGO_HOME=${CARGO_HOME}

RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain ${RUST_NIGHTLY_VERSION} && \
$CARGO_HOME/bin/rustup component add rust-src && \
$CARGO_HOME/bin/rustc --version

ENV PATH="${CARGO_HOME}/bin:${PATH}"
WORKDIR /app
COPY . .
Expand All @@ -47,7 +43,7 @@ RUN --mount=type=cache,target=${CARGO_HOME}/registry \
cargo fetch

# Release builder
FROM builder-base AS build-release
FROM builder-base AS build
ARG CARGO_HOME
RUN --mount=type=cache,target=${CARGO_HOME}/registry \
--mount=type=cache,target=${CARGO_HOME}/git \
Expand All @@ -57,28 +53,25 @@ RUN --mount=type=cache,target=${CARGO_HOME}/registry \
cp target/release-full/hyperion-proxy /app/build/ && \
cp target/release-full/tag /app/build/

# Runtime base image
FROM ubuntu:22.04 AS runtime-base
RUN apt-get update && \
apt-get install -y \
libssl3 \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Runtime base image (using scratch instead of Alpine)
FROM scratch AS runtime-base
COPY --from=packages /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
ENV RUST_BACKTRACE=1 \
RUST_LOG=info

# Hyperion Proxy Release
FROM runtime-base AS hyperion-proxy
COPY --from=build-release /app/build/hyperion-proxy /
COPY --from=build /app/build/hyperion-proxy /
LABEL org.opencontainers.image.source="https://github.com/andrewgazelka/hyperion" \
org.opencontainers.image.description="Hyperion Proxy Server" \
org.opencontainers.image.version="0.1.0"
EXPOSE 8080
ENTRYPOINT ["/hyperion-proxy"]
CMD ["0.0.0.0:8080"]
# NYC Release

# Tag Release
FROM runtime-base AS tag
COPY --from=build-release /app/build/tag /
COPY --from=build /app/build/tag /
LABEL org.opencontainers.image.source="https://github.com/andrewgazelka/hyperion" \
org.opencontainers.image.description="Hyperion Tag Event" \
org.opencontainers.image.version="0.1.0"
Expand Down

0 comments on commit f9ebf83

Please sign in to comment.