diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8e86db6..2d6f28c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,7 +38,7 @@ jobs: - name: Add GOBIN to PATH run: echo "${{ github.workspace }}/bin" >> "$GITHUB_PATH" - - name: Generate protobuf bindings + - name: Generate protobuf stubs run: | buf export buf.build/agynio/api --output internal/.proto buf generate internal/.proto --template ./buf.gen.yaml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e2cfb0a..1d7b9f2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,6 +22,11 @@ jobs: with: go-version: '1.22.x' + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: linux/arm64 + - uses: docker/setup-buildx-action@v3 - name: Install system dependencies @@ -47,7 +52,7 @@ jobs: - name: Set release version run: echo "VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV" - - name: Generate protobufs + - name: Generate protobuf stubs run: | buf export buf.build/agynio/api --output internal/.proto buf generate internal/.proto --template ./buf.gen.yaml @@ -66,13 +71,14 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push release images - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: context: . file: ./Dockerfile + platforms: linux/amd64,linux/arm64 push: true tags: | - ghcr.io/agynio/token-counting:${{ env.VERSION }} + ghcr.io/agynio/token-counting:${{ github.ref_name }} ghcr.io/agynio/token-counting:latest ghcr.io/agynio/token-counting:${{ github.sha }} diff --git a/Dockerfile b/Dockerfile index 6b836a1..ebda1b3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,13 @@ +# syntax=docker/dockerfile:1.8 + FROM golang:1.22 AS builder +ARG TARGETOS +ARG TARGETARCH + ENV CGO_ENABLED=0 \ - GOOS=linux \ - GOARCH=amd64 \ GOBIN=/usr/local/bin -RUN apt-get update && apt-get install -y --no-install-recommends \ - ca-certificates \ - curl \ - protobuf-compiler && \ - rm -rf /var/lib/apt/lists/* - -RUN curl -sSL https://github.com/bufbuild/buf/releases/download/v1.64.0/buf-Linux-x86_64.tar.gz \ - | tar -xzf - -C /usr/local --strip-components=1 buf/bin/buf - -RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.34.2 && \ - go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.5.1 - WORKDIR /workspace COPY go.mod go.sum ./ @@ -24,10 +15,8 @@ RUN go mod download COPY . . -RUN buf export buf.build/agynio/api --output internal/.proto && \ - buf generate internal/.proto --template ./buf.gen.yaml - -RUN go build -o /out/token-counting ./cmd/token-counting +RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ + go build -trimpath -ldflags "-s -w" -o /out/token-counting ./cmd/token-counting FROM gcr.io/distroless/static-debian12