Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 12 additions & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,37 @@ env:

jobs:
build-image:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ "ubuntu-latest", "ubuntu-24.04-arm" ]
runs-on: ${{ matrix.os }}
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: docker/metadata-action@v3
- uses: docker/metadata-action@v5
id: meta
with:
images: ${{ env.REGISTRY }}/goccy/bigquery-emulator
images: ${{ env.REGISTRY }}/${{ github.repository }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: setup docker buildx
uses: docker/setup-buildx-action@v2
- name: cache for linux
uses: actions/cache@v3
if: runner.os == 'Linux'
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v3
- uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=~/.cache/go-build
annotations: ${{ steps.meta.outputs.annotations }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
VERSION=v${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
REVISION=${{ steps.meta.outputs.sha }}
43 changes: 34 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,44 @@
FROM ghcr.io/goccy/go-zetasql:latest
ARG DEBIAN_VERSION=bookworm

ARG VERSION
FROM golang:${DEBIAN_VERSION} AS cgo_builder
RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get -y install --no-install-recommends clang

WORKDIR /work
WORKDIR /build
# We copy the depenencies first to leverage Docker cache
COPY go.mod go.sum ./
RUN go mod download

COPY . ./
COPY cmd ./cmd
COPY internal ./internal
COPY server ./server
COPY types ./types

ENV CGO_ENABLED=1
ENV CC=clang
ENV CGO_CFLAGS="-fPIC"
ENV CXX=clang++
ENV CGO_CPPFLAGS="-fPIC"
ENV CGO_CXXFLAGS="-fPIC"
ARG TARGETPLATFORM
ARG VERSION
ARG REVISION

RUN go mod edit -replace github.com/goccy/go-zetasql=../go-zetasql
RUN go mod download
RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
export STATIC_LINK_FLAGS="-extldflags -static"; \
fi \
&& go build -o /go/bin/bigquery-emulator \
-ldflags "-s -w -X main.version=${VERSION} -X main.revision=${REVISION} -linkmode=external $STATIC_LINK_FLAGS" \
./cmd/bigquery-emulator

RUN make emulator/build

FROM debian:bullseye AS emulator
# AMD64 would be fine using scratch, as long as we also create an empty
# /tmp directory and copy over /usr/share/zoneinfo. However, static linking
# fails with ARM64, so we need to use a base image with the same glibc.
FROM debian:${DEBIAN_VERSION}

COPY --from=0 /work/bigquery-emulator /bin/bigquery-emulator
COPY --from=cgo_builder /go/bin/bigquery-emulator /bin/bigquery-emulator

WORKDIR /work

Expand Down