Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

chore(ci): speed up docker-build workflow #802

Closed
wants to merge 1 commit into from
Closed
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
131 changes: 116 additions & 15 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,69 @@ on:
tags:
- "v*"

env:
REGISTRY_IMAGE: us-docker.pkg.dev/evmchain/images/taiko-client

jobs:
push-docker-image:
build-binary:
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: "1.21"
id: go

- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Check out code into the Go module directory
uses: actions/checkout@v1

- name: build
run: |
mkdir -p /tmp/taiko-client
###
apt update
apt install gcc musl-dev linux-headers-generic git make build-base -y
make build
mv ./bin/taiko-client /tmp/taiko-client/taiko-client-amd64
###
make clean
apt install g++-aarch64-linux-gnu gcc-arm-none-eabi gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu -y
make build-arm
mv ./bin/taiko-client /tmp/taiko-client/taiko-client-arm64
cp ./ci.dockerfile /tmp/taiko-client/Dockerfile
- name: Upload binaries
uses: actions/upload-artifact@v3
with:
name: binaries
path: /tmp/taiko-client
if-no-files-found: error
retention-days: 1

build:
name: Build and push docker image
runs-on: ubuntu-latest
needs: build-binary
strategy:
matrix:
platform: [amd64, arm64]

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Login to GAR
uses: docker/login-action@v2
- name: Download binaries
uses: actions/download-artifact@v3
with:
registry: us-docker.pkg.dev
username: _json_key
password: ${{ secrets.GAR_JSON_KEY }}
name: binaries
path: /tmp/taiko-client
- name: Rename binaries
run: |
mv /tmp/taiko-client/taiko-client-${{ matrix.platform }} /tmp/taiko-client/taiko-client

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
Expand All @@ -40,10 +88,63 @@ jobs:
type=ref,event=tag
type=sha

- name: Build and push
uses: docker/build-push-action@v2
- name: Build
uses: docker/build-push-action@v4
id: build
with:
context: /tmp/taiko-client
file: /tmp/taiko-client/Dockerfile
platforms: linux/${{ matrix.platform }}
cache-from: type=gha
cache-to: type=gha,mode=max
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v3
with:
name: digests
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

merge:
runs-on: ubuntu-latest
needs:
- build
steps:
- name: Download digests
uses: actions/download-artifact@v3
with:
name: digests
path: /tmp/digests
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=ref,event=tag
type=sha
- name: Login to GAR
uses: docker/login-action@v2
with:
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
registry: us-docker.pkg.dev
username: _json_key
password: ${{ secrets.GAR_JSON_KEY }}

- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ LD_FLAGS := -ldflags "$(LD_FLAGS_ARGS)"
build:
@GO111MODULE=on CGO_CFLAGS="-O -D__BLST_PORTABLE__" CGO_CFLAGS_ALLOW="-O -D__BLST_PORTABLE__" go build -v $(LD_FLAGS) -o bin/taiko-client cmd/main.go

build-arm:
@GO111MODULE=on CGO_ENABLED=1 GOARCH=arm64 GOOS=linux CC=aarch64-linux-gnu-gcc CGO_CFLAGS="-O -D__BLST_PORTABLE__" CGO_CFLAGS_ALLOW="-O -D__BLST_PORTABLE__" go build -v $(LD_FLAGS) -o bin/taiko-client cmd/main.go

clean:
@rm -rf bin/*

Expand Down
10 changes: 10 additions & 0 deletions ci.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM ubuntu:latest

RUN apt install ca-certificates libstdc++6

COPY taiko-client /usr/local/bin/
RUN chmod +x /usr/local/bin/taiko-client

EXPOSE 6060

ENTRYPOINT ["taiko-client"]
Loading