diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml deleted file mode 100644 index 96d5a34f5..000000000 --- a/.github/workflows/build_docker.yml +++ /dev/null @@ -1,27 +0,0 @@ ---- -name: Build Docker Image on PR - -on: - push: - paths: - - "**docker**" - - "**.sh" - - "**.bash" - -jobs: - docker: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - name: Build without push - uses: docker/build-push-action@v4 - with: - context: . - platforms: linux/amd64 - push: false - build-args: arch=x86_64 \ No newline at end of file diff --git a/.github/workflows/goreleaser-latest.yml b/.github/workflows/goreleaser-latest.yml new file mode 100644 index 000000000..584185881 --- /dev/null +++ b/.github/workflows/goreleaser-latest.yml @@ -0,0 +1,49 @@ +name: goreleaser-latest + +on: + push: + branches: + - main + - develop + +permissions: + contents: write + packages: write + +jobs: + goreleaser-latest: + runs-on: ubuntu-latest + steps: + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Fetch all tags + run: git fetch --force --tags + + - name: Release (snapshot) + run: make release-snapshot + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Login to GHCR container register + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push versioned image + uses: docker/build-push-action@v5 + with: + file: contrib/docker/goreleaser.Dockerfile + context: . + push: true + platforms: linux/amd64,linux/arm64 + tags: ghcr.io/composablefi/composable-cosmos:latest diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml new file mode 100644 index 000000000..89257a838 --- /dev/null +++ b/.github/workflows/goreleaser.yml @@ -0,0 +1,55 @@ +name: goreleaser + +on: + push: + tags: + - "*" + +permissions: + contents: write + packages: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Fetch all tags + run: git fetch --force --tags + + - name: Release + run: make release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Get version + id: get_version + uses: battila7/get-version-action@v2 + + - name: Login to GHCR container register + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push versioned image + uses: docker/build-push-action@v5 + with: + file: contrib/docker/goreleaser.Dockerfile + context: . + push: true + platforms: linux/amd64,linux/arm64 + tags: | + ghcr.io/composablefi/composable-cosmos:${{ steps.get_version.outputs.version }} + ghcr.io/composablefi/composable-cosmos:v${{ steps.get_version.outputs.major }} + ghcr.io/composablefi/composable-cosmos:v${{ steps.get_version.outputs.major }}.${{ steps.get_version.outputs.minor }} diff --git a/.github/workflows/push_docker_images.yml b/.github/workflows/push_docker_images.yml deleted file mode 100644 index 9ee8b8b76..000000000 --- a/.github/workflows/push_docker_images.yml +++ /dev/null @@ -1,65 +0,0 @@ -# This workflow pushes new centauri docker images on every new tag. -# -# On every new `vX.Y.Z` tag the following images are pushed: -# -# composablefi/composable-cosmos:X.Y.Z # is pushed -# composablefi/composable-cosmos:X.Y # is updated to X.Y.Z -# composablefi/composable-cosmos:X # is updated to X.Y.Z -# -# All the images above have support for linux/amd64 and linux/arm64. -# -# Due to QEMU virtualization used to build multi-platform docker images -# this workflow might take a while to complete. - -name: Push Docker Images - -on: - release: - types: [published, created, edited] - push: - tags: - - 'v[0-9]+.[0-9]+.[0-9]+' # ignore rc - -permissions: - contents: read - packages: write - -jobs: - feeapp-images: - runs-on: ubuntu-latest - steps: - - name: Check out the repo - uses: actions/checkout@v4 - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Parse tag - id: tag - run: | - VERSION=$(echo ${{ github.ref_name }} | sed "s/v//") - MAJOR_VERSION=$(echo $VERSION | cut -d '.' -f 1) - MINOR_VERSION=$(echo $VERSION | cut -d '.' -f 2) - PATCH_VERSION=$(echo $VERSION | cut -d '.' -f 3) - echo "VERSION=$VERSION" >> $GITHUB_ENV - echo "MAJOR_VERSION=$MAJOR_VERSION" >> $GITHUB_ENV - echo "MINOR_VERSION=$MINOR_VERSION" >> $GITHUB_ENV - echo "PATCH_VERSION=$PATCH_VERSION" >> $GITHUB_ENV - - name: Build and push - id: build_push_image - uses: docker/build-push-action@v3 - with: - file: Dockerfile - context: . - push: true - platforms: linux/amd64,linux/arm64 - tags: | - ghcr.io/composablefi/composable-cosmos:${{ env.MAJOR_VERSION }} - ghcr.io/composablefi/composable-cosmos:${{ env.MAJOR_VERSION }}.${{ env.MINOR_VERSION }} - ghcr.io/composablefi/composable-cosmos:${{ env.MAJOR_VERSION }}.${{ env.MINOR_VERSION }}.${{ env.PATCH_VERSION }} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 756cc1eec..000000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,45 +0,0 @@ ---- - name: Release Binary - - on: - release: - types: [created] - - permissions: - contents: read - packages: write - - jobs: - release: - permissions: write-all - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Docker compose - run: docker-compose up -d - - - name: Copy binary - run: docker cp composable-centauri_node_1:/bin/centaurid ./centaurid - - - name: Save sha256 sum - run: sha256sum ./centaurid > ./centaurid_sha256.txt - - - name: Release - uses: softprops/action-gh-release@v1 - with: - token: ${{ github.token }} - files: | - centaurid - centaurid_sha256.txt - - - name: Dump docker logs on failure - if: failure() - uses: jwalton/gh-docker-logs@v2 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 003f7ba8e..bd65a4ba1 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,9 @@ scripts/temp.sh wasm_client* vue/* bin/* + +dist/ + # Test binary, built with `go test -c` *.test diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 000000000..181b7e9ea --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,81 @@ +# .goreleaser.yml + +project_name: centaurid + +env: + - CGO_ENABLED=1 + +builds: + - id: linux + main: ./cmd/centaurid + binary: centaurid + hooks: + pre: + - cmd: bash scripts/release_pre_linux.sh + output: false # enable for debug + env: + - TARGET={{ .Target }} + goos: + - linux + goarch: + - amd64 + - arm64 + env: + - CC_linux_amd64=x86_64-linux-gnu-gcc + - CC_linux_arm64=aarch64-linux-gnu-gcc + - 'CC={{ index .Env (print "CC_" .Os "_" .Arch) }}' + flags: + - -mod=readonly + - -trimpath + ldflags: + - -X github.com/cosmos/cosmos-sdk/version.Name=centauri + - -X github.com/cosmos/cosmos-sdk/version.AppName=centaurid + - -X github.com/cosmos/cosmos-sdk/version.Version={{ .Version }} + - -X github.com/cosmos/cosmos-sdk/version.Commit={{ .Commit }} + - -X "github.com/cosmos/cosmos-sdk/version.BuildTags=netgo,ledger,muslc" + - -w -s + - -linkmode=external + - -extldflags '-static -lm -lbz2' + tags: + - netgo + - ledger + - muslc + - static + - static_wasm + + # - id: darwin + # main: ./cmd/centaurid + # binary: centaurid + # hooks: + # pre: + # - cmd: bash scripts/release_pre_darwin.sh + # output: false # enable for debug + # env: + # - TARGET={{ .Target }} + # goos: + # - darwin + # goarch: + # - amd64 + # - arm64 + # env: + # - CC_darwin_amd64=o64-clang + # - CC_darwin_arm64=oa64-clang + # - 'CC={{ index .Env (print "CC_" .Os "_" .Arch) }}' + # flags: + # - -mod=readonly + # - -trimpath + # ldflags: + # - -X github.com/cosmos/cosmos-sdk/version.Name=centauri + # - -X github.com/cosmos/cosmos-sdk/version.AppName=centaurid + # - -X github.com/cosmos/cosmos-sdk/version.Version={{ .Version }} + # - -X github.com/cosmos/cosmos-sdk/version.Commit={{ .Commit }} + # - -X "github.com/cosmos/cosmos-sdk/version.BuildTags=netgo,ledger,muslc" + # - -w -s + # - -linkmode=external + # - -extldflags '-static -lm -lbz2' + # tags: + # - netgo + # - ledger + # - muslc + # - static + # - static_wasm diff --git a/Makefile b/Makefile index cde284ab7..26d1cf2b2 100644 --- a/Makefile +++ b/Makefile @@ -158,3 +158,5 @@ ictest-push-wasm: cd tests/interchaintest && go test -race -v -run TestPushWasmClientCode . .PHONY: ictest-start-cosmos ictest-start-polkadot ictest-ibc ictest-push-wasm ictest-all + +include contrib/make/release.mk \ No newline at end of file diff --git a/contrib/docker/goreleaser.Dockerfile b/contrib/docker/goreleaser.Dockerfile new file mode 100644 index 000000000..1793b262a --- /dev/null +++ b/contrib/docker/goreleaser.Dockerfile @@ -0,0 +1,33 @@ +FROM golang:1.20 AS builder + +WORKDIR /root +COPY ./dist/ /root/ + +ARG TARGETARCH +RUN if [ "${TARGETARCH}" = "arm64" ]; then \ + cp linux_linux_arm64/centaurid /root/centaurid; \ + else \ + cp linux_linux_amd64_v1/centaurid /root/centaurid; \ + fi + +FROM alpine:latest + +RUN apk --no-cache add ca-certificates jq +COPY --from=builder /root/centaurid /usr/local/bin/centaurid + +RUN addgroup --gid 1025 -S composable && adduser --uid 1025 -S composable -G composable + +WORKDIR /home/composable +USER composable + +# rest server +EXPOSE 1317 +# tendermint p2p +EXPOSE 26656 +# tendermint rpc +EXPOSE 26657 +# grpc +EXPOSE 9090 + +ENTRYPOINT ["centaurid"] +CMD [ "start" ] diff --git a/contrib/make/release.mk b/contrib/make/release.mk new file mode 100644 index 000000000..1ce0ee899 --- /dev/null +++ b/contrib/make/release.mk @@ -0,0 +1,32 @@ +############################################################################### +### Release ### +############################################################################### + +PACKAGE_NAME := github.com/composable-cosmos/composable-cosmos +GOLANG_CROSS_VERSION ?= v1.20 + +# The `make release` command is running a Docker container with the image +# `gorelease/goreleaser-cross:${GOLANG_CROSS_VERSION}`. This command: +# `-v "$(CURDIR)":/go/src/$(PACKAGE_NAME)`: mounts the current directory +# `release --clean`: executes the release inside the directory +release: + docker run \ + --rm \ + --platform linux/amd64 \ + -v "$(CURDIR)":/go/src/$(PACKAGE_NAME) \ + -w /go/src/$(PACKAGE_NAME) \ + -e CGO_ENABLED=1 \ + -e GITHUB_TOKEN=${GITHUB_TOKEN} \ + goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \ + release --clean + +release-snapshot: + docker run \ + --rm \ + --platform linux/amd64 \ + -v /tmp:/tmp \ + -v "$(CURDIR)":/go/src/$(PACKAGE_NAME) \ + -w /go/src/$(PACKAGE_NAME) \ + -e CGO_ENABLED=1 \ + goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \ + release --clean --snapshot \ No newline at end of file diff --git a/scripts/release_pre_darwin.sh b/scripts/release_pre_darwin.sh new file mode 100644 index 000000000..8e85ce826 --- /dev/null +++ b/scripts/release_pre_darwin.sh @@ -0,0 +1,15 @@ +#!/usr/env/bin bash +# +# This runs in the "hooks.pre" block of .goreleaser.yml. +# We do this because it enables us to dynamically set the $WASMVM_VERSION based +# on go.mod. +# +# It's intended to be used with: +# ```bash +# make release-snapshot +# ``` +set -e + +WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | awk '{sub(/^v/, "", $2); print $2}') + +flock -x /tmp/wasmvm-lock -c "wget -c https://github.com/CosmWasm/wasmvm/releases/download/v${WASMVM_VERSION}/libwasmvmstatic_darwin.a -O /tmp/libwasmvmstatic_darwin.a && [ ! -f /usr/local/osxcross/SDK/MacOSX12.0.sdk/usr/lib/libwasmvmstatic_darwin.a ] && cp /tmp/libwasmvmstatic_darwin.a /usr/local/osxcross/SDK/MacOSX12.0.sdk/usr/lib/libwasmvmstatic_darwin.a; echo 'libwasmvm installed'" diff --git a/scripts/release_pre_linux.sh b/scripts/release_pre_linux.sh new file mode 100644 index 000000000..f9d39d397 --- /dev/null +++ b/scripts/release_pre_linux.sh @@ -0,0 +1,29 @@ +#!/usr/env/bin bash +# +# This runs in the "hooks.pre" block of .goreleaser.yml. +# We do this because it enables us to dynamically set the $WASMVM_VERSION based +# on go.mod. +# +# It's intended to be used with: +# ```bash +# make release-snapshot +# ``` +set -e + +WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | awk '{sub(/^v/, "", $2); print $2}') + +flock -x /tmp/apt-lock -c "[ \"$(ls -A /var/lib/apt/lists)\" ] || apt-get update" + +if [ "$TARGET" == "linux_amd64_v1" ]; then + echo "executing ${TARGET}" + apt-get -o DPkg::Lock::Timeout=60 install --no-install-recommends -y libzstd-dev:amd64 libsnappy-dev:amd64 liblz4-dev:amd64 libbz2-dev:amd64 zlib1g-dev:amd64 + + wget -c https://github.com/CosmWasm/wasmvm/releases/download/v${WASMVM_VERSION}/libwasmvm_muslc.x86_64.a -O /tmp/libwasmvm_muslc.x86_64.a + cp /tmp/libwasmvm_muslc.x86_64.a /usr/lib/x86_64-linux-gnu/libwasmvm_muslc.a +else + echo "executing ${TARGET}" + apt-get -o DPkg::Lock::Timeout=60 install --no-install-recommends -y libzstd-dev:arm64 libsnappy-dev:arm64 liblz4-dev:arm64 libbz2-dev:arm64 zlib1g-dev:arm64 + + wget -c https://github.com/CosmWasm/wasmvm/releases/download/v${WASMVM_VERSION}/libwasmvm_muslc.aarch64.a -O /tmp/libwasmvm_muslc.aarch64.a + cp /tmp/libwasmvm_muslc.aarch64.a /usr/lib/aarch64-linux-gnu/libwasmvm_muslc.a +fi \ No newline at end of file