From 0a0c99dfc27cc1628b6bf03a9ae9bef27530ad5d Mon Sep 17 00:00:00 2001 From: albttx Date: Mon, 10 Feb 2025 16:45:21 +0000 Subject: [PATCH 1/4] chore: refactoring docker system --- .github/workflows/docker-push.yml | 73 ++++++++++++++++++------------- Dockerfile | 22 +++++----- Makefile | 2 +- e2e.Dockerfile | 22 ---------- 4 files changed, 55 insertions(+), 64 deletions(-) delete mode 100644 e2e.Dockerfile diff --git a/.github/workflows/docker-push.yml b/.github/workflows/docker-push.yml index 50e6f6e8..12e4cfbf 100644 --- a/.github/workflows/docker-push.yml +++ b/.github/workflows/docker-push.yml @@ -1,51 +1,62 @@ -# source: https://docs.github.com/en/enterprise-cloud@latest/actions/publishing-packages/publishing-docker-images name: Create and publish a Docker image - on: - push: - branches: ['release'] + release: + types: [published] -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} +permissions: + contents: read + packages: write jobs: - build-and-push-image: + build-docker: runs-on: ubuntu-latest - permissions: - contents: read - packages: write steps: - - name: Checkout repository + - name: Checkout uses: actions/checkout@v4 - - name: Log in to the Container registry - uses: docker/login-action@v3.0.0 + # Seems required for cache + - uses: actions/setup-go@v5 + + - name: Login to Docker registry + uses: docker/login-action@v2 with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} + registry: ghcr.io + username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v5.5.1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Go Build Cache for Docker + uses: actions/cache@v3 with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + path: go-build-cache + key: ${{ runner.os }}-go-build-cache-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go-build-cache- - - name: Build and push Docker image - uses: docker/build-push-action@v5.1.0 + - name: inject go-build-cache into docker + uses: reproducible-containers/buildkit-cache-dance@v3.1.0 with: - context: . - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} + cache-source: go-build-cache - - name: Build and push e2e docker image - uses: docker/build-push-action@v5.1.0 + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 with: - context: . - file: Dockerfile.e2e + images: ghcr.io/${{ github.repository }} + tags: | + type=raw,value=latest + type=semver,pattern={{version}} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + platforms: linux/amd64,linux/arm64 + pull: true push: true - tags: ${{ steps.meta.outputs.tags }}-e2e + cache-from: type=gha + cache-to: type=gha,mode=max + tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index 3f7425b0..978a9a1d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,22 @@ -ARG IMG_TAG=latest +ARG GO_VERSION="1.22.10" +ARG ALPINE_VERSION=latest # Compile the atomoned binary -FROM golang:1.22-alpine AS atomoned-builder +FROM golang:$GO_VERSION-alpine AS builder WORKDIR /src/app/ COPY go.mod go.sum* ./ RUN go mod download COPY . . -ENV PACKAGES curl make git libc-dev bash gcc linux-headers eudev-dev python3 +ENV PACKAGES="curl make git libc-dev bash gcc linux-headers eudev-dev python3" RUN apk add --no-cache $PACKAGES RUN CGO_ENABLED=0 make install -# Add to a distroless container -FROM cgr.dev/chainguard/static:$IMG_TAG -ARG IMG_TAG -COPY --from=atomoned-builder /go/bin/atomoned /usr/local/bin/ +# Final image +FROM alpine:$ALPINE_VERSION +RUN adduser -D nonroot +ARG ALPINE_VERSION +COPY --from=builder /go/bin/atomoned /usr/local/bin/ EXPOSE 26656 26657 1317 9090 -USER 0 - -ENTRYPOINT ["atomoned", "start"] +USER nonroot +ENTRYPOINT [ "atomoned" ] +CMD [ "start" ] diff --git a/Makefile b/Makefile index bb6901ce..09703bf9 100644 --- a/Makefile +++ b/Makefile @@ -209,7 +209,7 @@ endif .PHONY: run-tests $(TEST_TARGETS) docker-build-debug: - @docker build -t cosmos/atomoned-e2e -f e2e.Dockerfile --build-arg GO_VERSION=$(GO_REQUIRED_VERSION) . + @docker build -t cosmos/atomoned-e2e -f Dockerfile --build-arg GO_VERSION=$(GO_REQUIRED_VERSION) . docker-build-hermes: @cd tests/e2e/docker; docker build -t ghcr.io/cosmos/hermes-e2e:1.0.0 -f hermes.Dockerfile . diff --git a/e2e.Dockerfile b/e2e.Dockerfile deleted file mode 100644 index 552428a4..00000000 --- a/e2e.Dockerfile +++ /dev/null @@ -1,22 +0,0 @@ -ARG GO_VERSION -ARG IMG_TAG=latest - -# Compile the atomoned binary -FROM golang:$GO_VERSION-alpine AS atomoned-builder -WORKDIR /src/app/ -COPY go.mod go.sum* ./ -RUN go mod download -COPY . . -ENV PACKAGES curl make git libc-dev bash gcc linux-headers eudev-dev python3 -RUN apk add --no-cache $PACKAGES -RUN CGO_ENABLED=0 make install - -# Add to a distroless container -FROM alpine:$IMG_TAG -RUN adduser -D nonroot -ARG IMG_TAG -COPY --from=atomoned-builder /go/bin/atomoned /usr/local/bin/ -EXPOSE 26656 26657 1317 9090 -USER nonroot - -ENTRYPOINT ["atomoned", "start"] From bef0cdf047a85a781bc66b7125873980176417d5 Mon Sep 17 00:00:00 2001 From: albttx Date: Tue, 11 Feb 2025 15:32:26 +0000 Subject: [PATCH 2/4] fix: Dockerfile --- Dockerfile | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 978a9a1d..1ba557b0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ -ARG GO_VERSION="1.22.10" -ARG ALPINE_VERSION=latest +ARG GO_VERSION +ARG IMG_TAG=latest # Compile the atomoned binary FROM golang:$GO_VERSION-alpine AS builder @@ -11,12 +11,13 @@ ENV PACKAGES="curl make git libc-dev bash gcc linux-headers eudev-dev python3" RUN apk add --no-cache $PACKAGES RUN CGO_ENABLED=0 make install -# Final image -FROM alpine:$ALPINE_VERSION +# Add to a distroless container +FROM alpine:$IMG_TAG RUN adduser -D nonroot -ARG ALPINE_VERSION +ARG IMG_TAG COPY --from=builder /go/bin/atomoned /usr/local/bin/ EXPOSE 26656 26657 1317 9090 USER nonroot -ENTRYPOINT [ "atomoned" ] -CMD [ "start" ] + +ENTRYPOINT ["atomoned"] +CMD ["start"] From 0a2cb63b3c267c9ceb8d4380945f5a030281ebde Mon Sep 17 00:00:00 2001 From: albttx Date: Tue, 11 Feb 2025 15:49:57 +0000 Subject: [PATCH 3/4] chore: update cache --- .github/workflows/docker-push.yml | 43 ++++++++++++++++++------------- Dockerfile | 5 +++- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/.github/workflows/docker-push.yml b/.github/workflows/docker-push.yml index 12e4cfbf..c447c13f 100644 --- a/.github/workflows/docker-push.yml +++ b/.github/workflows/docker-push.yml @@ -15,23 +15,35 @@ jobs: - name: Checkout uses: actions/checkout@v4 - # Seems required for cache - - uses: actions/setup-go@v5 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - name: Login to Docker registry - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=raw,value=latest + type=semver,pattern={{version}} - name: Go Build Cache for Docker - uses: actions/cache@v3 + id: cache + uses: actions/cache@v4.2.0 with: - path: go-build-cache + path: | + ~/.cache/go-build + ~/go/pkg/mod key: ${{ runner.os }}-go-build-cache-${{ hashFiles('**/go.sum') }} restore-keys: | ${{ runner.os }}-go-build-cache- @@ -39,22 +51,17 @@ jobs: - 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 - type=semver,pattern={{version}} + cache-map: | + { + "go-pkg-mod": "/go/pkg/mod", + "go-build-cache": "/root/.cache/go-build" + } + skip-extraction: ${{ steps.cache.outputs.cache-hit }} - name: Build and push uses: docker/build-push-action@v5 with: platforms: linux/amd64,linux/arm64 - pull: true push: true cache-from: type=gha cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile index 1ba557b0..00180d60 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,10 @@ RUN go mod download COPY . . ENV PACKAGES="curl make git libc-dev bash gcc linux-headers eudev-dev python3" RUN apk add --no-cache $PACKAGES -RUN CGO_ENABLED=0 make install + +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/go/pkg/mod \ + CGO_ENABLED=0 make install # Add to a distroless container FROM alpine:$IMG_TAG From 482b3a7dbcd69f4885441e12858ea20f19e44969 Mon Sep 17 00:00:00 2001 From: albttx Date: Mon, 10 Mar 2025 16:29:41 +0000 Subject: [PATCH 4/4] chore: init localnet-1 --- contrib/localnet-1/README.md | 19 +++++++++++ contrib/localnet-1/docker-compose.yml | 17 ++++++++++ contrib/localnet-1/entrypoint.sh | 49 +++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 contrib/localnet-1/README.md create mode 100644 contrib/localnet-1/docker-compose.yml create mode 100755 contrib/localnet-1/entrypoint.sh diff --git a/contrib/localnet-1/README.md b/contrib/localnet-1/README.md new file mode 100644 index 00000000..59036f0e --- /dev/null +++ b/contrib/localnet-1/README.md @@ -0,0 +1,19 @@ +# Localnet-1 + +This is a quick way to setup a node with current branch version + +:warn: This localnet don't persist data on disk + +## How to use + +```sh +docker compose up -d --build +``` + +## Endpoints + +- P2P http://localhost:26656 +- RPC http://localhost:26657 +- API http://localhost:1317 +- gRPC localhost:9090 +- gRPC web localhost:9091 diff --git a/contrib/localnet-1/docker-compose.yml b/contrib/localnet-1/docker-compose.yml new file mode 100644 index 00000000..777f03f0 --- /dev/null +++ b/contrib/localnet-1/docker-compose.yml @@ -0,0 +1,17 @@ +--- +services: + atomone: + image: ghcr.io/atomone-hub/atomone:dev + build: + context: ../.. + args: + GO_VERSION: ${GO_VERSION} + entrypoint: ["/bin/sh", "/entrypoint.sh"] + volumes: + - ./entrypoint.sh:/entrypoint.sh + ports: + - 1317:1317 + - 9090:9090 + - 9091:9091 + - 26656:26656 + - 26657:26657 diff --git a/contrib/localnet-1/entrypoint.sh b/contrib/localnet-1/entrypoint.sh new file mode 100755 index 00000000..c1244d08 --- /dev/null +++ b/contrib/localnet-1/entrypoint.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +CHAIN_ID="localnet-1" + +WALLET_VALIDATOR_ADDR="atone16zau0ntu4xqm58c537e5zwrnkq4s5zpdpxmwz7" +WALLET_VALIDATOR_MNEMONIC="safe permit shrug crumble snap tree law observe melt ramp exit lazy lend few elephant idle now debris soldier split course movie pepper afraid" + +WALLET_1_ADDR="atone19j38cmss7m3h4d0fptfwgltfsnhhw583y7h2ay" +WALLET_1_MNEMONIC="enjoy insect mimic number swamp trade obvious swamp stick give stool clarify bulk recipe minimum happy chunk coast suffer dutch high race trumpet sock" + +WALLET_2_ADDR="atone1083ytsqvwml9vcytzn79x0dxv027apfthrtsda" +WALLET_2_MNEMONIC="slam tree stamp write hole race unusual erosion express toy pulp domain scan power hawk ball combine that olympic solve loud talk saddle total" + +WALLET_3_ADDR="atone1dpspzdsd7nsch65n5dgalqd9ydcuc5nxs9s2x7" +WALLET_3_MNEMONIC="escape daring note begin cattle smooth you forget business vault mirror charge pilot few message corn equip asset nose snake scale sudden practice rib" + +atomoned init localnet --chain-id "${CHAIN_ID}" --default-denom="uatone" + +atomoned config keyring-backend test + +echo "${WALLET_VALIDATOR_MNEMONIC}" | atomoned keys add validator --recover +echo "${WALLET_1_MNEMONIC}" | atomoned keys add wallet-1 --recover +echo "${WALLET_2_MNEMONIC}" | atomoned keys add wallet-2 --recover +echo "${WALLET_3_MNEMONIC}" | atomoned keys add wallet-3 --recover + +# Add 100_000_000 $ATONE to all wallets +atomoned genesis add-genesis-account $WALLET_VALIDATOR_ADDR 100000000000uatone + +atomoned genesis add-genesis-account $WALLET_1_ADDR 100000000000uatone +atomoned genesis add-genesis-account $WALLET_2_ADDR 100000000000uatone +atomoned genesis add-genesis-account $WALLET_3_ADDR 100000000000uatone + +# gentx 10 $ATONE +atomoned genesis gentx validator 10000000uatone --chain-id ${CHAIN_ID} +atomoned genesis collect-gentxs +atomoned genesis validate-genesis + +# RPC +sed -i 's|laddr = "tcp://127.0.0.1:26657"|laddr = "tcp://0.0.0.0:26657"|g' $HOME/.atomone/config/config.toml + +# REST +sed -i 's|address = "tcp://localhost:1317"|address = "tcp://0.0.0.0:1317"|g' $HOME/.atomone/config/app.toml +sed -i 's|enable = false|enable = true|g' $HOME/.atomone/config/app.toml + +# GRPC +sed -i 's|address = "localhost:9090"|address = "0.0.0.0:9090"|g' $HOME/.atomone/config/app.toml +sed -i 's|address = "localhost:9091"|address = "0.0.0.0:9091"|g' $HOME/.atomone/config/app.toml + +exec atomoned start --minimum-gas-prices=0.025uatone