From 53028068ddfd18f8a736a051a8244f8317b66442 Mon Sep 17 00:00:00 2001 From: waldner Date: Sat, 5 Oct 2024 19:24:52 +0200 Subject: [PATCH] GH actions for build + multiarch --- .github/workflows/docker-publish.yml | 63 ++++++++++++++++++++++++++++ Dockerfile | 38 ++++++++++++----- README.md | 2 - docker-compose.yml | 2 +- 4 files changed, 92 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/docker-publish.yml diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..f3e6490 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,63 @@ +name: Docker + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +on: + push: + branches: [ "master" ] + +env: + # Use docker.io for Docker Hub if empty + REGISTRY: ghcr.io + # github.repository as / + IMAGE_NAME: ${{ github.repository }} + +jobs: + + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + # This is used to complete the identity challenge + # with sigstore/fulcio when running outside of PRs. + id-token: write + + steps: + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Checkout repository + uses: actions/checkout@v4 + + # Set up BuildKit Docker container builder to be able to build + # multi-platform images and export cache + # https://github.com/docker/setup-buildx-action + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: ghcr.io/waldner/keybase-kbfs-docker:1 + cache-from: type=gha + cache-to: type=gha,mode=max + diff --git a/Dockerfile b/Dockerfile index 13410d8..76e7582 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,33 @@ -FROM debian:12-slim - +FROM golang:1.23.2-bookworm AS builder0-arm64 ENV DEBIAN_FRONTEND=noninteractive +RUN curl -fsSL https://dl.yarnpkg.com/debian/pubkey.gpg -o /etc/apt/keyrings/yarn.asc && \ + echo "deb [signed-by=/etc/apt/keyrings/yarn.asc] https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list && \ + apt-get update && apt-get install -y yarn rsync fakeroot && \ + git clone https://github.com/keybase/client /tmp/client && \ + cd /tmp/client/packaging/linux && \ + export KEYBASE_BUILD_ARM_ONLY=1 && \ + ./build_binaries.sh prerelease /tmp/out && \ + sed -i 's|^export debian_arch=amd64|export debian_arch=arm64|' deb/package_binaries.sh && \ + deb/package_binaries.sh /tmp/out && \ + cp /tmp/out/deb/arm64/keybase-*-arm64.deb /tmp/keybase.deb + +FROM debian:12-slim AS builder-arm64 +COPY --from=builder0-arm64 /tmp/keybase.deb /tmp/keybase.deb + +FROM debian:12-slim AS builder-amd64 +RUN apt-get update && apt-get install -y curl && \ + cd /tmp && curl -s -o /tmp/keybase.deb https://prerelease.keybase.io/keybase_amd64.deb +# stupid trick +FROM builder-${TARGETARCH} AS final-builder + +FROM debian:12-slim AS final +ENV DEBIAN_FRONTEND=noninteractive +COPY --from=final-builder /tmp/keybase.deb /tmp/keybase.deb RUN apt-get update && apt-get install -y \ - perl-modules \ - apt-utils \ - gosu \ - curl && \ - curl -s -O https://prerelease.keybase.io/keybase_amd64.deb && \ - apt-get install -y ./keybase_amd64.deb && \ - rm keybase_amd64.deb && \ + perl-modules apt-utils gosu curl \ + && apt-get install -y /tmp/keybase.deb && \ + rm /tmp/keybase.deb && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* /var/cache/* @@ -17,7 +35,7 @@ RUN useradd -m keybase COPY entrypoint.sh /tmp COPY run_keybase.sh /tmp -RUN chmod +x /tmp/run_keybase.sh /tmp/entrypoint.sh; +RUN chmod +x /tmp/run_keybase.sh /tmp/entrypoint.sh ENTRYPOINT ["/tmp/entrypoint.sh"] CMD ["/tmp/run_keybase.sh"] diff --git a/README.md b/README.md index 66bd23d..d662267 100644 --- a/README.md +++ b/README.md @@ -36,8 +36,6 @@ After that, you can run `docker-compose up -d`. It uses the prebuilt image at [t Create a file `docker-compose.override.yml` with the follwing contents: ``` -version: '3' - services: keybase: volumes: diff --git a/docker-compose.yml b/docker-compose.yml index d0dfc49..b1feca6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ services: keybase: - image: waldner/keybase:5 + image: ghcr.io/waldner/keybase-kbfs-docker:1 container_name: keybase restart: always