From 64fa141bebfd50ac4801f16e9907fa295b44e753 Mon Sep 17 00:00:00 2001 From: Amit Zafran Date: Sun, 2 Jun 2024 13:54:36 +0300 Subject: [PATCH] feat: Lava Docker support (#1458) * update GA * names * dockerfiles * GA * build args * release and push * m a p * s * push: true * red * name * contents: read * x * upload logs * old dockerfile * ports --------- Co-authored-by: amitz --- .dockerignore | 4 + .github/workflows/lava.yml | 104 ++++++++++++++++---------- .github/workflows/release.yml | 137 +++++++++++----------------------- Dockerfile | 2 +- cmd/lavad/Dockerfile | 58 ++++++++++++++ cmd/lavap/Dockerfile | 58 ++++++++++++++ 6 files changed, 227 insertions(+), 136 deletions(-) create mode 100644 cmd/lavad/Dockerfile create mode 100644 cmd/lavap/Dockerfile diff --git a/.dockerignore b/.dockerignore index 146e253a30..89aa2ce572 100644 --- a/.dockerignore +++ b/.dockerignore @@ -17,5 +17,9 @@ ecosystem/**/package-lock.json .idea/ .vscode/ .storage/ +.vscode/ +go.work +go.work.sum +*.md Dockerfile \ No newline at end of file diff --git a/.github/workflows/lava.yml b/.github/workflows/lava.yml index 18089a6afa..df8d75ff69 100644 --- a/.github/workflows/lava.yml +++ b/.github/workflows/lava.yml @@ -21,11 +21,6 @@ jobs: with: go-version-file: go.mod cache-dependency-path: go.sum - # Setup Paths - - name: home - run: pwd && ls -l - - name: ls usr - run: ls -l /home/runner/work/lava/lava - name: cp lava run: cp -r ~/work/lava/lava ~/go/lava - name: export PATH @@ -34,14 +29,6 @@ jobs: run: export GOPATH=$GOPATH:$(go env GOPATH):/go:/go/lava:/usr/local:`pwd` - name: export LAVA run: export LAVA=/home/runner/work/lava/lava - - name: go env - run: go env - - name: pwd - run: pwd - - name: tree - run: tree - - name: ls -l - run: ls -l ###################################################### ### Run Consensus unitests @@ -51,18 +38,7 @@ jobs: go install github.com/jstemmer/go-junit-report/v2@latest go test -v ./utils/... | go-junit-report -iocopy -set-exit-code -out utils-report.xml go test -v ./common/... | go-junit-report -iocopy -set-exit-code -out common-report.xml - go test -v ./x/pairing/... | go-junit-report -iocopy -set-exit-code -out pairing-report.xml - go test -v ./x/epochstorage/... | go-junit-report -iocopy -set-exit-code -out epochstorage-report.xml - go test -v ./x/spec/... | go-junit-report -iocopy -set-exit-code -out spec-report.xml - go test -v ./x/conflict/... | go-junit-report -iocopy -set-exit-code -out conflict-report.xml - go test -v ./x/plans/... | go-junit-report -iocopy -set-exit-code -out plans-report.xml - go test -v ./x/projects/... | go-junit-report -iocopy -set-exit-code -out projects-report.xml - go test -v ./x/subscription/... | go-junit-report -iocopy -set-exit-code -out subscription-report.xml - go test -v ./x/dualstaking/... | go-junit-report -iocopy -set-exit-code -out dualstaking-report.xml - go test -v ./x/fixationstore/... | go-junit-report -iocopy -set-exit-code -out fixationstore-report.xml - go test -v ./x/timerstore/... | go-junit-report -iocopy -set-exit-code -out timerstore-report.xml - go test -v ./x/downtime/... | go-junit-report -iocopy -set-exit-code -out downtime-report.xml - go test -v ./x/rewards/... | go-junit-report -iocopy -set-exit-code -out rewards-report.xml + go test -v ./x/... | go-junit-report -iocopy -set-exit-code -out x-report.xml - name: Upload Test Results if: always() @@ -79,12 +55,6 @@ jobs: with: go-version-file: go.mod cache-dependency-path: go.sum - - # Setup Paths - - name: home - run: pwd && ls -l - - name: ls usr - run: ls -l /home/runner/work/lava/lava - name: cp lava run: cp -r ~/work/lava/lava ~/go/lava - name: export GOPATH @@ -93,14 +63,6 @@ jobs: run: export PATH=$PATH:/go:/go/bin:$(go env GOPATH)/bin:/usr/local:`pwd`:/home/runner/work/lava/lava/:$GOPATH/bin - name: export LAVA run: export LAVA=/home/runner/work/lava/lava - - name: go env - run: go env - - name: pwd - run: pwd - - name: tree - run: tree - - name: ls -l - run: ls -l ###################################################### ### Run protocol unitests @@ -217,6 +179,13 @@ jobs: if: always() continue-on-error: true run: grep "" testutil/e2e/protocolLogs/06_RPCConsumer* --include="*errors*" + + - name: Upload Protocol E2E Logs + if: always() + uses: actions/upload-artifact@v4 + with: + name: Protocol E2E Logs + path: "testutil/e2e/protocolLogs/*" test-sdk-e2e: runs-on: ubuntu-latest @@ -327,6 +296,13 @@ jobs: if: always() continue-on-error: true run: grep "" testutil/e2e/sdkLogs/01_sdkTest* --include="*errors*" + + - name: Upload SDK E2E Logs + if: always() + uses: actions/upload-artifact@v4 + with: + name: SDK E2E Logs + path: "testutil/e2e/sdkLogs/*" test-payment-e2e: runs-on: ubuntu-latest @@ -382,6 +358,13 @@ jobs: if: always() continue-on-error: true run: grep "" testutil/e2e/protocolLogs/06_RPCConsumer* --include="*errors*" + + - name: Upload Payment E2E Logs + if: always() + uses: actions/upload-artifact@v4 + with: + name: Payment E2E Logs + path: "testutil/e2e/protocolLogs/*" report-tests-results: runs-on: ubuntu-latest @@ -396,7 +379,48 @@ jobs: uses: EnricoMi/publish-unit-test-result-action@v2 with: files: "artifacts/**/*.xml" - + + build_docker: + permissions: + contents: read + packages: write + needs: [test-consensus, test-protocol] + runs-on: ubuntu-latest + strategy: + matrix: + binary: [lavap, lavad] + env: + REGISTRY: ghcr.io + IMAGE_NAME: "lavanet/lava/${{ matrix.binary }}" + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + - name: Build and push + uses: docker/build-push-action@v5 + with: + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + file: cmd/${{ matrix.binary }}/Dockerfile + build-args: | + GIT_VERSION="${{ steps.meta.outputs.version }}" + GIT_COMMIT="${{ github.sha }}" + push: true + build_and_package: name: ${{ matrix.binary }}-${{ matrix.targetos }}-${{ matrix.arch }} needs: [test-consensus, test-protocol] diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8068ef0597..b6aaec846d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -26,8 +26,8 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 - ref: ${{ github.event.inputs.release_tag != '' && github.event.inputs.release_tag || github.ref_name }} - + ref: ${{ github.event.inputs.release_tag != '' && github.event.inputs.release_tag || github.ref_name }} + - name: Fetch all tags run: | git fetch --force --tags @@ -38,6 +38,7 @@ jobs: go-version-file: go.mod cache-dependency-path: go.sum + - name: Run GoReleaser id: releaser uses: goreleaser/goreleaser-action@v5 @@ -46,96 +47,42 @@ jobs: args: release --clean --timeout 90m env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - # - name: Check for existing assests - # id: existing_asset - # run: | - # if [ "${{ github.event.release.assets[0].name }}" = "lavad" ]; then - # echo "URL=${{ github.event.release.assets[0].id }}" >> $GITHUB_OUTPUT - # echo "URL=${{ github.event.release.assets[0].url }}" >> $GITHUB_OUTPUT - # echo "CHECK=true" >> $GITHUB_OUTPUT - # else - # echo "CHECK=false" >> $GITHUB_OUTPUT - # fi - - # - name: Upload build to release - # run: | - # upload_binary () { - # echo "Uploading binary to: $(echo '${{ github.event.release.upload_url }}' | sed 's/{?name,label}/?name=lavad/g')" - # curl \ - # -X POST \ - # -H "Accept: application/vnd.github+json" \ - # -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ - # -H "Content-Type: $(file -b --mime-type build/lavad)" \ - # --data-binary @build/lavad \ - # $(echo '${{ github.event.release.upload_url }}' | sed 's/{?name,label}/?name=lavad-${{ github.event.release.tag_name }}-linux-amd64/g') - - # curl \ - # -X POST \ - # -H "Accept: application/vnd.github+json" \ - # -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ - # -H "Content-Type: $(file -b --mime-type build/lavap)" \ - # --data-binary @build/lavap \ - # $(echo '${{ github.event.release.upload_url }}' | sed 's/{?name,label}/?name=lavap-${{ github.event.release.tag_name }}-linux-amd64/g') - - # curl \ - # -X POST \ - # -H "Accept: application/vnd.github+json" \ - # -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ - # -H "Content-Type: $(file -b --mime-type build/lavavisor)" \ - # --data-binary @build/lavavisor \ - # $(echo '${{ github.event.release.upload_url }}' | sed 's/{?name,label}/?name=lavavisor-${{ github.event.release.tag_name }}-linux-amd64/g') - # } - - # delete_binary(){ - # echo "Deleting existing binary" - # curl \ - # -X DELETE \ - # -H "Accept: application/vnd.github+json" \ - # -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ - # ${{ steps.existing_asset.outputs.URL }} - # } - - # if ${{ steps.existing_asset.outputs.CHECK }}; then - # delete_binary - # upload_binary - # else - # upload_binary - # fi - - # - name: Check for existing Checksum - # id: existing_checksum - # run: | - # #Get Checksum of new build - # export CHECKSUM=$(sha256sum build/lavad | cut -d " " -f1) - - # #Get the existing body - # existing_body=$(curl \ - # -H "Accept: application/vnd.github+json" \ - # -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ - # -H "Content-Type: $(file -b --mime-type build/lavad)" \ - # ${{ github.event.release.url }} | jq '.body') - - # if [[ $existing_body == *"$CHECKSUM"* ]]; then - # echo "CHECK=true" >> $GITHUB_OUTPUT - # echo "Checksum hasn't changed." - # else - # echo "CHECK=false" >> $GITHUB_OUTPUT - # cat <> /tmp/body - # $(echo $existing_body | sed '$s/.$//')\r\nChecksum $CHECKSUM" - # EOF - # echo -E "NEW_BODY=$(cat /tmp/body)" >> $GITHUB_OUTPUT - # fi - - # - name: Append Binary Checksum - # uses: actions/github-script@v6 - # if: ${{ steps.existing_checksum.outputs.CHECK }} == 'false' - # with: - # github-token: ${{ secrets.GITHUB_TOKEN }} - # script: | - # const { data } = await github.rest.repos.updateRelease({ - # owner: context.repo.owner, - # repo: context.repo.repo, - # release_id: context.payload.release.id, - # body: ${{ steps.existing_checksum.outputs.NEW_BODY }} - # }); \ No newline at end of file + + release_docker: + permissions: + packages: write + runs-on: ubuntu-latest + strategy: + matrix: + binary: [lavap, lavad] + env: + REGISTRY: ghcr.io + IMAGE_NAME: "lavanet/lava/${{ matrix.binary }}" + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + - name: Build and push + uses: docker/build-push-action@v5 + with: + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + file: cmd/${{ matrix.binary }}/Dockerfile + build-args: | + GIT_VERSION="${{ steps.meta.outputs.version }}" + GIT_COMMIT="${{ github.sha }}" + push: true \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index edc101d1f1..99f1350bb5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -194,4 +194,4 @@ EXPOSE 26656 # tendermint rpc EXPOSE 26657 -ENTRYPOINT ["/entrypoint.sh"] +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/cmd/lavad/Dockerfile b/cmd/lavad/Dockerfile new file mode 100644 index 0000000000..39efa9dbcd --- /dev/null +++ b/cmd/lavad/Dockerfile @@ -0,0 +1,58 @@ +# syntax=docker/dockerfile:1 + +ARG GO_VERSION="1.20" +ARG BUILD_TAGS="netgo,ledger,muslc" + +FROM golang:${GO_VERSION}-alpine3.18 as builder + +RUN apk add --no-cache \ + ca-certificates \ + build-base \ + linux-headers \ + binutils-gold + +WORKDIR /lava + +COPY go.mod go.sum ./ + +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/root/go/pkg/mod \ + go mod download + +COPY . . + +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/root/go/pkg/mod \ + GOWORK=off go build \ + -mod=readonly \ + -tags "netgo,ledger,muslc" \ + -ldflags \ + "-X github.com/cosmos/cosmos-sdk/version.Name="lava" \ + -X github.com/cosmos/cosmos-sdk/version.AppName="lavad" \ + -X github.com/cosmos/cosmos-sdk/version.Version=${GIT_VERSION} \ + -X github.com/cosmos/cosmos-sdk/version.Commit=${GIT_COMMIT} \ + -X github.com/cosmos/cosmos-sdk/version.BuildTags=${BUILD_TAGS} \ + -w -s -linkmode=external -extldflags '-Wl,-z,muldefs -static'" \ + -trimpath \ + -o /lava/build/lavad \ + /lava/cmd/lavad/main.go + +FROM gcr.io/distroless/static-debian12 + +COPY --from=builder /lava/build/lavad /bin/lavad + +ENV HOME /lava +WORKDIR $HOME + +# lava api +EXPOSE 1317 +# rosetta +EXPOSE 8080 +# grpc +EXPOSE 9090 +# tendermint p2p +EXPOSE 26656 +# tendermint rpc +EXPOSE 26657 + +ENTRYPOINT ["lavad"] \ No newline at end of file diff --git a/cmd/lavap/Dockerfile b/cmd/lavap/Dockerfile new file mode 100644 index 0000000000..2df889dd10 --- /dev/null +++ b/cmd/lavap/Dockerfile @@ -0,0 +1,58 @@ +# syntax=docker/dockerfile:1 + +ARG GO_VERSION="1.20" +ARG BUILD_TAGS="netgo,ledger,muslc" + +FROM golang:${GO_VERSION}-alpine3.18 as builder + +RUN apk add --no-cache \ + ca-certificates \ + build-base \ + linux-headers \ + binutils-gold + +WORKDIR /lava + +COPY go.mod go.sum ./ + +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/root/go/pkg/mod \ + go mod download + +COPY . . + +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/root/go/pkg/mod \ + GOWORK=off go build \ + -mod=readonly \ + -tags "netgo,ledger,muslc" \ + -ldflags \ + "-X github.com/cosmos/cosmos-sdk/version.Name="lava" \ + -X github.com/cosmos/cosmos-sdk/version.AppName="lavap" \ + -X github.com/cosmos/cosmos-sdk/version.Version=${GIT_VERSION} \ + -X github.com/cosmos/cosmos-sdk/version.Commit=${GIT_COMMIT} \ + -X github.com/cosmos/cosmos-sdk/version.BuildTags=${BUILD_TAGS} \ + -w -s -linkmode=external -extldflags '-Wl,-z,muldefs -static'" \ + -trimpath \ + -o /lava/build/lavap \ + /lava/cmd/lavap/main.go + +FROM gcr.io/distroless/static-debian12 + +COPY --from=builder /lava/build/lavap /bin/lavap + +ENV HOME /lava +WORKDIR $HOME + +# lava api +EXPOSE 1317 +# rosetta +EXPOSE 8080 +# grpc +EXPOSE 9090 +# tendermint p2p +EXPOSE 26656 +# tendermint rpc +EXPOSE 26657 + +ENTRYPOINT ["lavap"] \ No newline at end of file