From 4627b6c853181a820ba6b28c7d24e0c34fe54ddf Mon Sep 17 00:00:00 2001 From: Niccolo Raspa Date: Tue, 9 Jul 2024 11:07:57 +0200 Subject: [PATCH 1/5] Improve .gitignore --- .gitignore | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index a40e0dc..162e5b2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,29 @@ -build -snapshots/ -here/ -vendor/ \ No newline at end of file +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work +go.work.sum + +# env file +.env* + +# Custom +dist/ +build/ \ No newline at end of file From c9fb3f58404cde7a13d30e897ea620a8c534c844 Mon Sep 17 00:00:00 2001 From: Niccolo Raspa Date: Tue, 9 Jul 2024 11:08:09 +0200 Subject: [PATCH 2/5] Rename and improve Makefile --- Makefile | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ makefile | 27 ---------------------- 2 files changed, 69 insertions(+), 27 deletions(-) create mode 100644 Makefile delete mode 100644 makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8217374 --- /dev/null +++ b/Makefile @@ -0,0 +1,69 @@ +VERSION := $(shell git describe --tags) +COMMIT := $(shell git log -1 --format='%H') +GO_VERSION := $(shell cat go.mod | grep -E 'go [0-9].[0-9]+' | cut -d ' ' -f 2) + +all: install + +build: + @echo "Building cosmprund" + @go build -mod readonly $(BUILD_FLAGS) -o build/cosmprund main.go + +clean: + rm -rf build + +.PHONY: all lint test race msan tools clean build + +############################################################################### +### Docker ### +############################################################################### + +docker-build: + docker build -t cosmprund:local . + +docker-run: + docker run cosmprund:local + +############################################################################### +### Release ### +############################################################################### +GORELEASER_IMAGE := ghcr.io/goreleaser/goreleaser-cross:v$(GO_VERSION) + +ifdef GITHUB_TOKEN +release: + docker run \ + --rm \ + -e GITHUB_TOKEN=$(GITHUB_TOKEN) \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v `pwd`:/go/src/diffusion \ + -w /go/src/diffusion \ + $(GORELEASER_IMAGE) \ + release \ + --clean +else +release: + @echo "Error: GITHUB_TOKEN is not defined. Please define it before running 'make release'." +endif + +release-dry-run: + docker run \ + --rm \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v `pwd`:/go/src/diffusion \ + -w /go/src/diffusion \ + $(GORELEASER_IMAGE) \ + release \ + --clean \ + --skip=publish + +release-snapshot: + docker run \ + --rm \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v `pwd`:/go/src/osmosisd \ + -w /go/src/osmosisd \ + $(GORELEASER_IMAGE) \ + release \ + --clean \ + --snapshot \ + --skip=validate \ + --skip=publish \ No newline at end of file diff --git a/makefile b/makefile deleted file mode 100644 index adc03c1..0000000 --- a/makefile +++ /dev/null @@ -1,27 +0,0 @@ -VERSION := $(shell git describe --tags) -COMMIT := $(shell git log -1 --format='%H') - -all: install - -LD_FLAGS = -X github.com/strangelove-ventures/lens/cmd.Version=$(VERSION) \ - -X github.com/strangelove-ventures/lens/cmd.Commit=$(COMMIT) \ - -BUILD_FLAGS := -ldflags '$(LD_FLAGS)' - -docker: - @echo "Building Docker Image" - @read -p "Enter the tag: " tag; \ - docker build -t czarcas7ic/cosmpruned:$$tag -f Dockerfile . - -build: - @echo "Building Pruning" - @go build -mod readonly $(BUILD_FLAGS) -o build/cosmprund main.go - -install: - @echo "Installing Lens" - @go install -mod readonly $(BUILD_FLAGS) ./... - -clean: - rm -rf build - -.PHONY: all lint test race msan tools clean build From 29160a25b294c81bcc6de9882e41fbdc14696753 Mon Sep 17 00:00:00 2001 From: Niccolo Raspa Date: Tue, 9 Jul 2024 11:08:25 +0200 Subject: [PATCH 3/5] Update Dockerfile --- Dockerfile | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7bedd4c..bdbbcb5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,33 @@ -# 1st stage, build app -FROM golang:1.21-alpine as builder +# ---------------------------------------------------------------- +# Builder Stage +# ---------------------------------------------------------------- +ARG GO_VERSION="1.21" -COPY . /app +FROM golang:${GO_VERSION}-alpine AS builder +# Download go dependencies WORKDIR /app +COPY go.mod go.sum ./ +RUN go mod download -RUN go build -o cosmprund +# Copy the remaining files +COPY cmd /app/cmd +COPY internal /app/internal +COPY *.go /app/ +# Build binary +RUN go build \ + -mod=readonly \ + -ldflags "-w -s" \ + -trimpath \ + -o /app/build/cosmprund -FROM alpine +# ---------------------------------------------------------------- +# Final image for Running +# ---------------------------------------------------------------- -COPY --from=builder /app/cosmprund /usr/bin/cosmprund +FROM alpine:3.19 + +COPY --from=builder /app/build/cosmprund /usr/bin/cosmprund ENTRYPOINT [ "/usr/bin/cosmprund" ] From 2854b74be12f02cd59fd61738e61a643402e03fa Mon Sep 17 00:00:00 2001 From: Niccolo Raspa Date: Tue, 9 Jul 2024 11:08:36 +0200 Subject: [PATCH 4/5] Update README.md --- .github/workflows/release.yml | 30 ++++++++++++++++++ .goreleaser.yaml | 59 +++++++++++++++++++++++++++++++++++ README.md | 51 +++++------------------------- 3 files changed, 96 insertions(+), 44 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 .goreleaser.yaml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..2bf4964 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,30 @@ +# This workflow creates a release using goreleaser +# via the 'make release' command. + +name: Create release + +on: + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' # ignore rc + +permissions: + contents: write + +jobs: + release: + name: Create release + runs-on: buildjet-4vcpu-ubuntu-2204 + steps: + - + name: Check out repository code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ github.ref }} + - + name: Make release + run: | + make release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..fba9eca --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,59 @@ +project_name: cosmprund + +env: + - CGO_ENABLED=0 + +before: + hooks: + - go mod tidy + +builds: + - id: cosmprund + binary: cosmprund + flags: + # - -mod=readonly + - -trimpath + goos: + - linux + - darwin + goarch: + - amd64 + - arm64 + ldflags: + - -s + - -w + +archives: + - id: zipped + builds: + - cosmprund + name_template: "{{.ProjectName}}-{{.Os}}-{{.Arch}}" + format: tar.gz + files: + - none* + - id: binaries + builds: + - cosmprund + name_template: "{{.ProjectName}}-{{.Os}}-{{.Arch}}" + format: binary + files: + - none* + +release: + github: + owner: osmosis-labs + name: cosmprund + header: | + osmprund release {{ .Version }} + footer: | + ## 🐳 Docker + + The following Docker images are available in our registry: + + | Image | Tag | + |-------------------------------------|----------------| + | `osmolabs/cosmprund:{{ .Version }}` | {{ .Version }} | + + name_template: "cosmprund v{{.Version}}" + mode: replace + draft: true diff --git a/README.md b/README.md index 0baa7ef..4b84ee5 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,20 @@ # Cosmos-Pruner -The goal of this project is to be able to prune a tendermint data base of blocks and an Cosmos-sdk application DB of all but the last X versions. This will allow people to not have to state sync every x days. +The goal of this project is to be able to prune a tendermint data base of blocks and an Cosmos-sdk application DB of all but the last X versions. This will allow people to not have to state sync every x days. -This tool works with a subset of modules. While an application may have modules outside the scope of this tool , this tool will prune the default sdk module, and osmosis added module. +This tool works with a subset of modules. While an application may have modules outside the scope of this tool , this tool will prune the default sdk module, and osmosis added module. ## WARNING -Due to inefficiencies of iavl and the simple approach of this tool, it can take ages to prune the data of a large node. +Due to inefficiencies of iavl and the simple approach of this tool, it can take ages to prune the data of a large node. We are working on integrating this natively into the Cosmos-sdk and Tendermint ## How to use -Cosmprund works of a data directory that has the same structure of a normal cosmos-sdk/tendermint node. By default it will prune all but 10 blocks from tendermint, and all but 10 versions of application state. +Cosmprund works of a data directory that has the same structure of a normal cosmos-sdk/tendermint node. By default it will prune all but 10 blocks from tendermint, and all but 10 versions of application state. -> Note: Application pruning can take a very long time dependent on the size of the db. +> Note: Application pruning can take a very long time dependent on the size of the db. ``` @@ -26,11 +26,11 @@ make build # stop daemon/cosmovisor sudo systemctl stop cosmovisor -# run cosmprund +# run cosmprund ./build/cosmprund prune ~/.gaiad/data --cosmos-sdk=false ``` -Flags: +Flags: - `data-dir`: path to data directory if not default - `blocks`: amount of blocks to keep on the node (Default 10) @@ -42,43 +42,6 @@ Flags: #### Supported Apps: - osmosis: Osmosis -- starname: Starname -- regen: Regen -- akash: Akash -- cosmoshub: Gaia -- sentinel: Sentinel -- emoney: E-Money -- ixo: Ixo -- juno: Juno -- sifchain: Sifchain -- likecoin: Likecoin -- kichain: Ki -- cyber: Cyber -- cheqd: Cheqd -- stargaze: Stargaze -- bandchain: Band -- chihuahua: Chihuahua -- kava: Kava -- bitcanna: BitCanna -- konstellation: Konstellation -- omniflixhub: Omniflix -- terra: Terra -- vidulum: Vidulum -- provenance: Provenance -- dig: Dig -- gravitybridge: Gravity-Bridge -- comdex: Comdex -- cerberus: Cerberus -- bitsong: BitSong -- assetmantle: AssetMantle -- fetchhub: FetchAI -- evmos: Evmos -- persistent: Persistence -- cryptoorgchain: Crypto.org -- irisnet: IRISnet -- axelar: Axelar -- umee: Umee - ### Note To use this with RocksDB you must: From 9fb20e6794e545d58d6ed236e5ef2f8f3d2bde7a Mon Sep 17 00:00:00 2001 From: Niccolo Raspa Date: Tue, 9 Jul 2024 11:10:22 +0200 Subject: [PATCH 5/5] Add -mod=readonly to goreleaser --- .goreleaser.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index fba9eca..f923688 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -11,7 +11,7 @@ builds: - id: cosmprund binary: cosmprund flags: - # - -mod=readonly + - -mod=readonly - -trimpath goos: - linux