From 3af4cebcee5a6a4f01e5d190b3b0b01b5c700664 Mon Sep 17 00:00:00 2001 From: albttx Date: Thu, 9 May 2024 08:30:25 +0100 Subject: [PATCH 1/4] chore(ci): setup docker build cache --- .github/workflows/docker.yml | 90 ++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000000..1dd188d1e0e --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,90 @@ +name: docker +on: + pull_request: + paths: + - "**" + - "misc/loop" + - "!misc/**" + - "!docs/**" + - "!**.md" + push: + branches: ["master"] + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + build-main: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Get commit SHA + id: commit + run: echo "sha=${GITHUB_SHA::8}" >> "$GITHUB_OUTPUT" + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + if: (github.event_name != 'pull_request') + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + cache-from: type=gha + cache-to: type=gha,mode=max + tags: | + ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest + ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ steps.commit.outputs.sha }} + + build-slim: + runs-on: ubuntu-latest + strategy: + matrix: + target: + [gnoland-slim, gnokey-slim, gno-slim, gnofaucet-slim, gnoweb-slim] + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Get commit SHA + id: commit + run: echo "sha=${GITHUB_SHA::8}" >> "$GITHUB_OUTPUT" + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + if: (github.event_name != 'pull_request') + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64,linux/arm64 + target: ${{ matrix.target }} + cache-from: type=gha + cache-to: type=gha,mode=max + push: ${{ github.event_name != 'pull_request' }} + tags: | + ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/${{ matrix.target }}:latest + ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/${{ matrix.target }}:${{ steps.commit.outputs.sha }} From 72137d2b8c10ec9c709ca547181db06b7514caa1 Mon Sep 17 00:00:00 2001 From: albttx Date: Thu, 9 May 2024 08:56:26 +0100 Subject: [PATCH 2/4] chore: add go-cache --- .github/workflows/docker.yml | 26 +++++++++++ .github/workflows/portal-loop.yml | 7 +++ Dockerfile | 71 +++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 Dockerfile diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 1dd188d1e0e..c0c0dd16f97 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -36,6 +36,19 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Go Build Cache for Docker + uses: actions/cache@v3 + with: + path: go-build-cache + key: ${{ runner.os }}-go-build-cache-${{ hashFiles('**/go.sum') }} + + - name: inject go-build-cache into docker + # v1 was composed of two actions: "inject" and "extract". + # v2 is unified to a single action. + uses: reproducible-containers/buildkit-cache-dance@v2.1.2 + with: + cache-source: go-build-cache + - name: Build and push uses: docker/build-push-action@v5 with: @@ -76,6 +89,19 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Go Build Cache for Docker + uses: actions/cache@v3 + with: + path: go-build-cache + key: ${{ runner.os }}-go-build-cache-${{ hashFiles('**/go.sum') }} + + - name: inject go-build-cache into docker + # v1 was composed of two actions: "inject" and "extract". + # v2 is unified to a single action. + uses: reproducible-containers/buildkit-cache-dance@v2.1.2 + with: + cache-source: go-build-cache + - name: Build and push uses: docker/build-push-action@v5 with: diff --git a/.github/workflows/portal-loop.yml b/.github/workflows/portal-loop.yml index 6db5ffe4225..17a35d78aab 100644 --- a/.github/workflows/portal-loop.yml +++ b/.github/workflows/portal-loop.yml @@ -46,3 +46,10 @@ jobs: push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + + build-gno: + uses: ./.github/workflows/docker.yml + + test-portal-loop: + runs-on: ubuntu-latest + needs: build-gno diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000000..6b7f3149095 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,71 @@ +# build gno +FROM golang:1.22 AS build-gno +RUN go env -w GOMODCACHE=/root/.cache/go-build +RUN mkdir -p /opt/gno/src /opt/build +WORKDIR /opt/build +ADD go.mod go.sum . +RUN --mount=type=cache,target=/root/.cache/go-build go mod download +ADD . ./ +RUN --mount=type=cache,target=/root/.cache/go-build go build -o ./build/gnoland ./gno.land/cmd/gnoland +RUN --mount=type=cache,target=/root/.cache/go-build go build -o ./build/gnokey ./gno.land/cmd/gnokey +RUN --mount=type=cache,target=/root/.cache/go-build go build -o ./build/gnoweb ./gno.land/cmd/gnoweb +RUN --mount=type=cache,target=/root/.cache/go-build go build -o ./build/gno ./gnovm/cmd/gno +RUN ls -la ./build +ADD . /opt/gno/src/ +RUN rm -rf /opt/gno/src/.git + +# build faucet +FROM golang:1.22 AS build-faucet +RUN go env -w GOMODCACHE=/root/.cache/go-build +RUN mkdir -p /opt/gno/src /opt/build +RUN mkdir -p /opt/gno/src /opt/build +WORKDIR /opt/build +ADD contribs/gnofaucet/go.mod contribs/gnofaucet/go.sum . +# RUN go mod download +RUN --mount=type=cache,target=/root/.cache/go-build go mod download +ADD contribs/gnofaucet ./ +# RUN go build -o ./build/gnofaucet . +RUN --mount=type=cache,target=/root/.cache/go-build go build -o ./build/gnofaucet . + + +# runtime-base + runtime-tls +FROM debian:stable-slim AS runtime-base +ENV PATH="${PATH}:/opt/gno/bin" \ + GNOROOT="/opt/gno/src" +WORKDIR /opt/gno/src +FROM runtime-base AS runtime-tls +RUN apt-get update && apt-get install -y expect ca-certificates && update-ca-certificates + +# slim images +FROM runtime-base AS gnoland-slim +WORKDIR /opt/gno/src/gno.land/ +COPY --from=build-gno /opt/build/build/gnoland /opt/gno/bin/ +ENTRYPOINT ["gnoland"] +EXPOSE 26657 36657 + +FROM runtime-base AS gnokey-slim +COPY --from=build-gno /opt/build/build/gnokey /opt/gno/bin/ +ENTRYPOINT ["gnokey"] + +FROM runtime-base AS gno-slim +COPY --from=build-gno /opt/build/build/gno /opt/gno/bin/ +ENTRYPOINT ["gno"] + +FROM runtime-tls AS gnofaucet-slim +COPY --from=build-faucet /opt/build/build/gnofaucet /opt/gno/bin/ +ENTRYPOINT ["gnofaucet"] +EXPOSE 5050 + +FROM runtime-tls AS gnoweb-slim +COPY --from=build-gno /opt/build/build/gnoweb /opt/gno/bin/ +COPY --from=build-gno /opt/gno/src/gno.land/cmd/gnoweb /opt/gno/src/gnoweb +ENTRYPOINT ["gnoweb"] +EXPOSE 8888 + +# all, contains everything. +FROM runtime-tls AS all +COPY --from=build-gno /opt/build/build/* /opt/gno/bin/ +COPY --from=build-faucet /opt/build/build/* /opt/gno/bin/ +COPY --from=build-gno /opt/gno/src /opt/gno/src +# gofmt is required by `gnokey maketx addpkg` +COPY --from=build-gno /usr/local/go/bin/gofmt /usr/bin From ef86b7ba35ed956af36984ec56011efe9ce8a8dc Mon Sep 17 00:00:00 2001 From: albttx Date: Thu, 13 Jun 2024 11:04:40 +0200 Subject: [PATCH 3/4] chore: update Dockerfile --- Dockerfile | 97 +++++++++++++++++++++++------------------------------- 1 file changed, 42 insertions(+), 55 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6b7f3149095..fa5a9e47270 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,71 +1,58 @@ # build gno -FROM golang:1.22 AS build-gno +FROM golang:1.22-alpine AS build-gno RUN go env -w GOMODCACHE=/root/.cache/go-build -RUN mkdir -p /opt/gno/src /opt/build -WORKDIR /opt/build -ADD go.mod go.sum . +WORKDIR /gnoroot +ENV GNOROOT="/gnoroot" +COPY . ./ RUN --mount=type=cache,target=/root/.cache/go-build go mod download -ADD . ./ RUN --mount=type=cache,target=/root/.cache/go-build go build -o ./build/gnoland ./gno.land/cmd/gnoland RUN --mount=type=cache,target=/root/.cache/go-build go build -o ./build/gnokey ./gno.land/cmd/gnokey RUN --mount=type=cache,target=/root/.cache/go-build go build -o ./build/gnoweb ./gno.land/cmd/gnoweb RUN --mount=type=cache,target=/root/.cache/go-build go build -o ./build/gno ./gnovm/cmd/gno -RUN ls -la ./build -ADD . /opt/gno/src/ -RUN rm -rf /opt/gno/src/.git -# build faucet -FROM golang:1.22 AS build-faucet -RUN go env -w GOMODCACHE=/root/.cache/go-build -RUN mkdir -p /opt/gno/src /opt/build -RUN mkdir -p /opt/gno/src /opt/build -WORKDIR /opt/build -ADD contribs/gnofaucet/go.mod contribs/gnofaucet/go.sum . -# RUN go mod download -RUN --mount=type=cache,target=/root/.cache/go-build go mod download -ADD contribs/gnofaucet ./ -# RUN go build -o ./build/gnofaucet . -RUN --mount=type=cache,target=/root/.cache/go-build go build -o ./build/gnofaucet . - - -# runtime-base + runtime-tls -FROM debian:stable-slim AS runtime-base -ENV PATH="${PATH}:/opt/gno/bin" \ - GNOROOT="/opt/gno/src" -WORKDIR /opt/gno/src -FROM runtime-base AS runtime-tls -RUN apt-get update && apt-get install -y expect ca-certificates && update-ca-certificates - -# slim images -FROM runtime-base AS gnoland-slim -WORKDIR /opt/gno/src/gno.land/ -COPY --from=build-gno /opt/build/build/gnoland /opt/gno/bin/ -ENTRYPOINT ["gnoland"] -EXPOSE 26657 36657 - -FROM runtime-base AS gnokey-slim -COPY --from=build-gno /opt/build/build/gnokey /opt/gno/bin/ -ENTRYPOINT ["gnokey"] - -FROM runtime-base AS gno-slim -COPY --from=build-gno /opt/build/build/gno /opt/gno/bin/ -ENTRYPOINT ["gno"] +# Base image +FROM alpine:3.17 AS base +WORKDIR /gnoroot +ENV GNOROOT="/gnoroot" +RUN apk add ca-certificates +CMD [ "" ] + +# alpine images +# gnoland +FROM base AS gnoland +COPY --from=build-gno /gnoroot/build/gnoland /usr/bin/gnoland +COPY --from=build-gno /gnoroot/examples /gnoroot/examples +COPY --from=build-gno /gnoroot/gnovm/stdlibs /gnoroot/gnovm/stdlibs +COPY --from=build-gno /gnoroot/gno.land/genesis/genesis_txs.jsonl /gnoroot/gno.land/genesis/genesis_txs.jsonl +COPY --from=build-gno /gnoroot/gno.land/genesis/genesis_balances.txt /gnoroot/gno.land/genesis/genesis_balances.txt +EXPOSE 26656 26657 +ENTRYPOINT ["/usr/bin/gnoland"] + +# gnokey +FROM base AS gnokey +COPY --from=build-gno /gnoroot/build/gnokey /usr/bin/gnokey +# gofmt is required by `gnokey maketx addpkg` +COPY --from=build-gno /usr/local/go/bin/gofmt /usr/bin/gofmt +ENTRYPOINT ["/usr/bin/gnokey"] -FROM runtime-tls AS gnofaucet-slim -COPY --from=build-faucet /opt/build/build/gnofaucet /opt/gno/bin/ -ENTRYPOINT ["gnofaucet"] -EXPOSE 5050 +# gno +FROM base AS gno +COPY --from=build-gno /gnoroot/build/gno /usr/bin/gno +ENTRYPOINT ["/usr/bin/gno"] -FROM runtime-tls AS gnoweb-slim -COPY --from=build-gno /opt/build/build/gnoweb /opt/gno/bin/ +# gnoweb +FROM base AS gnoweb +COPY --from=build-gno /gnoroot/build/gnoweb /usr/bin/gnoweb COPY --from=build-gno /opt/gno/src/gno.land/cmd/gnoweb /opt/gno/src/gnoweb -ENTRYPOINT ["gnoweb"] EXPOSE 8888 +ENTRYPOINT ["/usr/bin/gnoweb"] # all, contains everything. -FROM runtime-tls AS all -COPY --from=build-gno /opt/build/build/* /opt/gno/bin/ -COPY --from=build-faucet /opt/build/build/* /opt/gno/bin/ -COPY --from=build-gno /opt/gno/src /opt/gno/src +FROM base AS all +COPY --from=build-gno /gnoroot/build/* /usr/bin/ +COPY --from=build-gno /gnoroot/examples /gnoroot/examples +COPY --from=build-gno /gnoroot/gnovm/stdlibs /gnoroot/gnovm/stdlibs +COPY --from=build-gno /gnoroot/gno.land/genesis/genesis_txs.jsonl /gnoroot/gno.land/genesis/genesis_txs.jsonl +COPY --from=build-gno /gnoroot/gno.land/genesis/genesis_balances.txt /gnoroot/gno.land/genesis/genesis_balances.txt # gofmt is required by `gnokey maketx addpkg` COPY --from=build-gno /usr/local/go/bin/gofmt /usr/bin From f56c0af5bab33ab6aee72eae077db8c48c362552 Mon Sep 17 00:00:00 2001 From: albttx Date: Thu, 13 Jun 2024 11:14:49 +0200 Subject: [PATCH 4/4] chore(ci): fix docker workflow --- .github/workflows/docker.yml | 95 ++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 53 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index c0c0dd16f97..1e5464d06cb 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,116 +1,105 @@ +# This workflow only build the docker images as a test. +# This images are not published, check Dockerfile.release for this. +# This images are only for dev/local purpose. name: docker on: - pull_request: - paths: - - "**" - - "misc/loop" - - "!misc/**" - - "!docs/**" - - "!**.md" push: - branches: ["master"] + branches: + - "master" + - "ci/docker-cache" concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true jobs: - build-main: + build-docker-image-main: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - - name: Get commit SHA - id: commit - run: echo "sha=${GITHUB_SHA::8}" >> "$GITHUB_OUTPUT" - - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - if: (github.event_name != 'pull_request') - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Go Build Cache for Docker uses: actions/cache@v3 with: path: go-build-cache key: ${{ runner.os }}-go-build-cache-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go-build-cache- - name: inject go-build-cache into docker - # v1 was composed of two actions: "inject" and "extract". - # v2 is unified to a single action. - uses: reproducible-containers/buildkit-cache-dance@v2.1.2 + uses: reproducible-containers/buildkit-cache-dance@v3.1.0 with: cache-source: go-build-cache + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=raw,value=latest + - name: Build and push uses: docker/build-push-action@v5 with: context: . platforms: linux/amd64,linux/arm64 - push: ${{ github.event_name != 'pull_request' }} + push: false cache-from: type=gha cache-to: type=gha,mode=max - tags: | - ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest - ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ steps.commit.outputs.sha }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} - build-slim: + build-docker-images: runs-on: ubuntu-latest + needs: build-docker-image-main strategy: matrix: target: - [gnoland-slim, gnokey-slim, gno-slim, gnofaucet-slim, gnoweb-slim] + - gnoland + - gnokey + - gno + - gnoweb steps: - name: Checkout uses: actions/checkout@v4 - - name: Get commit SHA - id: commit - run: echo "sha=${GITHUB_SHA::8}" >> "$GITHUB_OUTPUT" - - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - if: (github.event_name != 'pull_request') - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Go Build Cache for Docker uses: actions/cache@v3 with: path: go-build-cache key: ${{ runner.os }}-go-build-cache-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go-build-cache- - name: inject go-build-cache into docker - # v1 was composed of two actions: "inject" and "extract". - # v2 is unified to a single action. - uses: reproducible-containers/buildkit-cache-dance@v2.1.2 + uses: reproducible-containers/buildkit-cache-dance@v3.1.0 with: cache-source: go-build-cache + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=raw,value=latest + - name: Build and push uses: docker/build-push-action@v5 with: context: . - platforms: linux/amd64,linux/arm64 target: ${{ matrix.target }} + platforms: linux/amd64,linux/arm64 + push: false cache-from: type=gha cache-to: type=gha,mode=max - push: ${{ github.event_name != 'pull_request' }} - tags: | - ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/${{ matrix.target }}:latest - ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/${{ matrix.target }}:${{ steps.commit.outputs.sha }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }}