From 30fb539289a684d715e441360fb78cafa402753e Mon Sep 17 00:00:00 2001 From: sjdonado Date: Fri, 7 Feb 2025 19:18:11 +0100 Subject: [PATCH] ci: speed up build with crystal arm64 binary --- .github/workflows/publish.yml | 7 +++--- Dockerfile | 41 +++++++++++++++++++++-------------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index fd2a15e..8f93c3d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -22,9 +22,6 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 @@ -42,12 +39,16 @@ jobs: - name: Build and push platform image uses: docker/build-push-action@v5 + env: + CRYSTAL_WORKERS: ${{ matrix.platform == 'linux/amd64' && 4 || 2 }} with: context: . platforms: ${{ matrix.platform }} push: true tags: | sjdonado/bit:${{ github.event_name == 'release' && steps.version.outputs.version || 'latest' }}-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }} + build-args: | + TARGETARCH=${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }} cache-from: type=gha cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile index 0206cb1..371daaa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,32 +1,41 @@ -FROM alpine:edge AS build +FROM debian:bookworm-slim AS build +ARG TARGETARCH ENV ENV=production WORKDIR /usr/src/app -RUN apk update && apk add --no-cache \ +RUN apt-get update && apt-get install -y \ + curl \ + gnupg \ + ca-certificates \ + && mkdir -p /etc/apt/keyrings \ + && curl -fsSL https://packagecloud.io/84codes/crystal/gpgkey | gpg --dearmor > /etc/apt/trusted.gpg.d/84codes_crystal.gpg \ + && echo "deb [signed-by=/etc/apt/trusted.gpg.d/84codes_crystal.gpg] https://packagecloud.io/84codes/crystal/debian/ bookworm main" > /etc/apt/sources.list.d/84codes_crystal.list + +RUN apt-get update && apt-get install -y \ crystal \ - shards \ - yaml-dev \ - sqlite-dev \ - openssl-dev + libssl-dev \ + libyaml-dev \ + libsqlite3-dev \ + libevent-dev \ + && rm -rf /var/lib/apt/lists/* COPY . . -RUN shards install -RUN shards build --release --no-debug +RUN shards install --production +RUN shards build --release --no-debug --progress --stats -FROM alpine:edge AS runtime +FROM debian:bookworm-slim AS runtime ENV ENV=production WORKDIR /usr/src/app -RUN apk add --no-cache \ - gc \ - pcre2 \ - libevent \ - yaml \ - sqlite-libs \ - openssl +RUN apt-get update && apt-get install -y \ + libssl3 \ + libyaml-0-2 \ + libsqlite3-0 \ + libevent-2.1-7 \ + && rm -rf /var/lib/apt/lists/* RUN mkdir -p sqlite