From 3c0a2be786462f018e9743eee5cd5edd6880882a Mon Sep 17 00:00:00 2001 From: Julien Duchesne Date: Fri, 27 Oct 2023 13:07:21 -0400 Subject: [PATCH 1/2] Docker+CI: More efficient build CI was moved to GHA here: https://github.com/grafana/tanka/pull/938 However, it turns out that `buildx` is pretty slow. Improvements in this PR: - Remove `apk add curl` where easily doable - Download `jb` from Github releases rather than building it - Build `tk` exec outside of Docker --- .github/workflows/docker.yml | 21 +++++++++++++++++---- Dockerfile | 25 +++++++++---------------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index b0fbe9c6f..e361d7dbe 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -29,9 +29,11 @@ jobs: strategy: fail-fast: false matrix: - platform: - - linux/amd64 - - linux/arm64 + os: + - linux + arch: + - amd64 + - arm64 steps: - name: Checkout @@ -43,6 +45,17 @@ jobs: images: ${{ env.REGISTRY_IMAGE }} tags: ${{ env.TAGS_CONFIG }} + # Build executable + - name: Setup Go + uses: actions/setup-go@v2 + with: + go-version: '1.20' + - name: Build + run: make static + env: + GOOS: ${{ matrix.os }} + GOARCH: ${{ matrix.arch }} + # Setup buildx - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -71,7 +84,7 @@ jobs: uses: docker/build-push-action@v5 with: context: . - platforms: ${{ matrix.platform }} + platforms: ${{ matrix.os }}/${{ 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' }} diff --git a/Dockerfile b/Dockerfile index 89e53c167..cd58d3bcb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,5 @@ # download kubectl -FROM golang:1.21.1-alpine as kubectl -RUN apk add --no-cache curl +FROM golang:1.21.1 as kubectl RUN export VERSION=$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt) &&\ export OS=$(go env GOOS) && \ export ARCH=$(go env GOARCH) &&\ @@ -8,14 +7,12 @@ RUN export VERSION=$(curl -s https://storage.googleapis.com/kubernetes-release/r chmod +x /usr/local/bin/kubectl # build jsonnet-bundler -FROM golang:1.21.1-alpine as jb -WORKDIR /tmp -RUN apk add --no-cache git make bash &&\ - git clone https://github.com/jsonnet-bundler/jsonnet-bundler &&\ - ls /bin &&\ - cd jsonnet-bundler &&\ - make static &&\ - mv _output/jb /usr/local/bin/jb +FROM golang:1.21.1 as jb +RUN export OS=$(go env GOOS) &&\ + export ARCH=$(go env GOARCH) &&\ + curl -o /usr/local/bin/jb -L "https://github.com/jsonnet-bundler/jsonnet-bundler/releases/download/v0.5.1/jb-${OS}-${ARCH}" &&\ + chmod +x /usr/local/bin/jb + FROM golang:1.21.1-alpine as helm WORKDIR /tmp/helm @@ -39,15 +36,11 @@ RUN export TAG=$(curl --silent "https://api.github.com/repos/kubernetes-sigs/kus curl -SL "https://github.com/kubernetes-sigs/kustomize/releases/download/${TAG}/kustomize_${VERSION_TAG}_${OS}_${ARCH}.tar.gz" > kustomize.tgz && \ tar -xvf kustomize.tgz -FROM golang:1.21.1 as build -WORKDIR /app -COPY . . -RUN make static - # assemble final container FROM alpine:3.18 RUN apk add --no-cache coreutils diffutils less git openssh-client -COPY --from=build /app/tk /usr/local/bin/tk +# Need to `make static` before building the container +COPY tk /usr/local/bin/tk COPY --from=kubectl /usr/local/bin/kubectl /usr/local/bin/kubectl COPY --from=jb /usr/local/bin/jb /usr/local/bin/jb COPY --from=helm /tmp/helm/helm /usr/local/bin/helm From c9ca90097ae8d85afdab72258ee10fff9c5b86a8 Mon Sep 17 00:00:00 2001 From: Julien Duchesne Date: Fri, 27 Oct 2023 13:11:16 -0400 Subject: [PATCH 2/2] Set paths filter for docs --- .github/workflows/publish-page.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/publish-page.yml b/.github/workflows/publish-page.yml index 5bf0fea22..975a8461b 100644 --- a/.github/workflows/publish-page.yml +++ b/.github/workflows/publish-page.yml @@ -5,12 +5,16 @@ on: push: branches: - main + paths: + - docs/** pull_request: types: - opened - reopened - synchronize - closed + paths: + - docs/** permissions: contents: write