Skip to content

Commit

Permalink
Try building binary outside docker for speed
Browse files Browse the repository at this point in the history
  • Loading branch information
julienduchesne committed Jan 29, 2024
1 parent 455bbae commit f8f1526
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
19 changes: 12 additions & 7 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ jobs:
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64
arch:
- amd64
- arm64

steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.21'
- run: make cross
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
Expand Down Expand Up @@ -72,8 +75,10 @@ jobs:
id: build
uses: docker/build-push-action@v5
with:
build-args:
arch=${{ matrix.arch }}
context: .
platforms: ${{ matrix.platform }}
platforms: linux/${{ matrix.arch }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' }}
cache-from: type=gha
Expand All @@ -86,7 +91,7 @@ jobs:
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
echo "artifact_name=digests-${{ matrix.platform }}" | sed -e 's/\//-/g' >> "$GITHUB_OUTPUT"
echo "artifact_name=digests-linux/${{ matrix.arch }}" | sed -e 's/\//-/g' >> "$GITHUB_OUTPUT"
- name: Upload digest
if: github.event_name != 'pull_request'
Expand Down
11 changes: 2 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
FROM golang:1.20.6
ARG JSONNET_VERSION=v0.19.1
ARG JB_VERSION=v0.5.1
WORKDIR /app
RUN wget https://github.com/mitchellh/gox/archive/refs/tags/v1.0.1.tar.gz \
&& tar -xzf v1.0.1.tar.gz \
&& cd gox-1.0.1/ \
&& go build \
&& mv gox /usr/local/bin
RUN CGO_ENABLED=0 go install github.com/google/go-jsonnet/cmd/jsonnet@${JSONNET_VERSION} && \
CGO_ENABLED=0 go install github.com/google/go-jsonnet/cmd/jsonnetfmt@${JSONNET_VERSION} && \
CGO_ENABLED=0 go install github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb@${JB_VERSION}
COPY . .
RUN make install

FROM alpine
COPY --from=0 /go/bin/grr /usr/local/bin/grr
ARG arch=amd64
COPY /dist/grr-linux-${arch} /usr/local/bin/grr
COPY --from=0 /go/bin/jsonnet /usr/local/bin/jsonnet
COPY --from=0 /go/bin/jsonnetfmt /usr/local/bin/jsonnetfmt
COPY --from=0 /go/bin/jb /usr/local/bin/jb
Expand Down
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: dev lint test integration static install uninstall cross build-test-image run-test-image-locally test-clean
.PHONY: dev lint test integration install uninstall cross build-test-image run-test-image-locally test-clean
VERSION := $(shell git describe --tags --dirty --always)
BIN_DIR := $(GOPATH)/bin
GOX := $(BIN_DIR)/gox
Expand Down Expand Up @@ -28,8 +28,6 @@ dev:
go build -ldflags "-X main.Version=dev-${VERSION}" ./cmd/grr

LDFLAGS := '-s -w -extldflags "-static" -X main.Version=${VERSION}'
static:
CGO_ENABLED=0 GOOS=linux go build -ldflags=${LDFLAGS} ./cmd/grr

install:
CGO_ENABLED=0 go install -ldflags=${LDFLAGS} ./cmd/grr
Expand All @@ -45,5 +43,5 @@ cross: $(GOX)
CGO_ENABLED=0 $(GOPATH)/bin/gox -output="dist/{{.Dir}}-{{.OS}}-{{.Arch}}" -ldflags=${LDFLAGS} -arch="amd64 arm64 arm" -os="linux" -osarch="darwin/amd64 darwin/arm64" ./cmd/grr

# Docker container
container: static
container: cross
docker build -t grafana/grizzly .

0 comments on commit f8f1526

Please sign in to comment.