diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000000..1e5464d06cb --- /dev/null +++ b/.github/workflows/docker.yml @@ -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/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: 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/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: . + 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 }} 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..fa5a9e47270 --- /dev/null +++ b/Dockerfile @@ -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