Skip to content

Commit

Permalink
Properly compile statically linked binary with shards build command, …
Browse files Browse the repository at this point in the history
…using correct target and production dependencies only (no development dependencies).
  • Loading branch information
afinetooth committed Aug 27, 2024
1 parent c8b811b commit e2c6479
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,21 @@ ARG BASE_IMAGE_TAG=ubuntu-22.04
FROM 84codes/crystal:${CRYSTAL_VERSION}-${BASE_IMAGE_TAG} AS builder-x86_64
WORKDIR /app
RUN git clone https://github.com/coverallsapp/coverage-reporter.git .
# Install only the necessary dependencies, skipping ameba and kcov
RUN sed -i '/ameba/d' shard.yml \
&& sed -i '/crystal-kcov/d' shard.yml \
&& shards install --ignore-crystal-version \
# Install production dependencies and build the binary
RUN shards install --production --ignore-crystal-version \
&& mkdir -p /app/bin \
&& crystal build --release src/coverage_reporter.cr -o /app/bin/coveralls
&& shards build coveralls --production --release --static --no-debug --progress -o /app/bin/coveralls \
&& strip /app/bin/coveralls # Reduce binary size

# Stage 2: Build for aarch64
FROM 84codes/crystal:${CRYSTAL_VERSION}-${BASE_IMAGE_TAG} AS builder-aarch64
WORKDIR /app
COPY --from=builder-x86_64 /app /app

# Install dependencies. Ensure ameba and kcov are not present
RUN sed -i '/ameba/d' shard.yml \
&& sed -i '/crystal-kcov/d' shard.yml \
&& rm -rf lib/* \
&& rm -rf .shards \
&& shards install --ignore-crystal-version \
# Install production dependencies and build the binary
RUN shards install --production --ignore-crystal-version \
&& mkdir -p /app/bin \
&& crystal build --release src/coverage_reporter.cr -o /app/bin/coveralls
&& shards build coveralls --production --release --static --no-debug --progress -o /app/bin/coveralls \
&& strip /app/bin/coveralls # Reduce binary size

# Stage 3a: Export Binary for x86_64
FROM scratch AS x86_64_binary
Expand Down

0 comments on commit e2c6479

Please sign in to comment.