Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci): setup docker build cache #2062

Closed
wants to merge 6 commits 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
105 changes: 105 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +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:
push:
branches:
- "master"
- "ci/docker-cache"

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
build-docker-image-main:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- 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
uses: reproducible-containers/[email protected]
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: false
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

build-docker-images:
runs-on: ubuntu-latest
needs: build-docker-image-main
strategy:
matrix:
target:
- gnoland
- gnokey
- gno
- gnoweb
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- 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
uses: reproducible-containers/[email protected]
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: .
target: ${{ matrix.target }}
platforms: linux/amd64,linux/arm64
push: false
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
7 changes: 7 additions & 0 deletions .github/workflows/portal-loop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
58 changes: 58 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# build gno
FROM golang:1.22-alpine AS build-gno
RUN go env -w GOMODCACHE=/root/.cache/go-build
WORKDIR /gnoroot
ENV GNOROOT="/gnoroot"
COPY . ./
RUN --mount=type=cache,target=/root/.cache/go-build go mod download
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

# 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"]

# gno
FROM base AS gno
COPY --from=build-gno /gnoroot/build/gno /usr/bin/gno
ENTRYPOINT ["/usr/bin/gno"]

# 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
EXPOSE 8888
ENTRYPOINT ["/usr/bin/gnoweb"]

# all, contains everything.
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
Loading