Skip to content

Commit bdbeefa

Browse files
authored
Merge pull request #830 from jshufro/jms/monorepo-devnet3
Import history
2 parents f31b331 + 15c6712 commit bdbeefa

609 files changed

Lines changed: 67899 additions & 4009 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@ jobs:
1717
- uses: actions/setup-go@v4
1818
with:
1919
go-version: 1.21.8
20-
- run: cd ${GITHUB_WORKSPACE}/rocketpool-cli && go build .
21-
- run: cd ${GITHUB_WORKSPACE}/rocketpool && go build .
20+
- run: make NO_DOCKER=true

.github/workflows/lint.yml

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,41 @@ permissions:
1313
# Optional: allow read access to pull request. Use with `only-new-issues` option.
1414
# pull-requests: read
1515
jobs:
16-
golangci:
17-
name: lint
16+
detect-modules:
1817
runs-on: ubuntu-latest
18+
outputs:
19+
modules: ${{ steps.set-modules.outputs.modules }}
1920
steps:
20-
- uses: actions/setup-go@v4
21+
- uses: actions/checkout@v4
22+
- uses: actions/setup-go@v5
2123
with:
2224
go-version: 1.21.8
23-
- uses: actions/checkout@v3
24-
- name: golangci-lint
25-
uses: golangci/golangci-lint-action@v4
25+
- id: set-modules
26+
run: echo "modules=$(go list -m -json | jq -s '.' | jq -c '[.[].Dir]')" >> $GITHUB_OUTPUT
27+
golangci-lint:
28+
needs: detect-modules
29+
runs-on: ubuntu-latest
30+
strategy:
31+
max-parallel: 1
32+
matrix:
33+
modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }}
34+
steps:
35+
- uses: actions/checkout@v4
36+
- uses: actions/setup-go@v5
37+
with:
38+
go-version: 1.21.8
39+
- name: golangci-lint ${{ matrix.modules }}
40+
uses: golangci/golangci-lint-action@v8
2641
with:
2742
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
28-
version: latest
43+
version: v2.1
2944

3045
# Optional: working directory, useful for monorepos
31-
# working-directory: somedir
46+
working-directory: ${{ matrix.modules }}
3247

3348
# Optional: golangci-lint command line arguments.
3449
# args: --issues-exit-code=0
3550

36-
# For now, Smart Node will only enforce goimports linting
37-
args: --disable-all --enable goimports
38-
3951
# Optional: show only new issues if it's a pull request. The default value is `false`.
4052
# only-new-issues: true
4153

.github/workflows/unit-tests.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ jobs:
1313
build:
1414
runs-on: ubuntu-latest
1515
steps:
16-
- uses: actions/checkout@v3
17-
- uses: actions/setup-go@v4
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-go@v5
1818
with:
1919
go-version: 1.21.8
20-
- run: go test ./... -timeout 30m
20+
cache-dependency-path: go.work.sum
21+
- run: make test

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ Dockerfile
1717
/rocketpool/rocketpool-daemon-darwin-arm64
1818
/rocketpool/rocketpool-daemon-linux-arm64
1919
.vscode-ctags
20-
build/
20+
build/

.golangci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: "2"
2+
linters:
3+
default: none
4+
formatters:
5+
enable:
6+
- goimports
7+
run:
8+
relative-path-mode: cfg
9+
go: '1.21.8'
10+
output:
11+
formats:
12+
text:
13+
path: stderr

Makefile

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
VERSION=v$(shell cat shared/version.txt)
2+
LOCAL_OS=$(shell go env GOOS)-$(shell go env GOARCH)
3+
4+
BUILD_DIR=build
5+
BIN_DIR=${BUILD_DIR}/${VERSION}/bin
6+
DOCKER_DIR=${BUILD_DIR}/${VERSION}/docker
7+
8+
CLI_TARGET_OOS:=linux darwin
9+
ARCHS:=arm64 amd64
10+
11+
CLI_TARGET_STRINGS:=$(foreach oos,$(CLI_TARGET_OOS), $(foreach arch,$(ARCHS),${BIN_DIR}/rocketpool-cli-$(oos)-$(arch)))
12+
DAEMON_TARGET_STRINGS:=$(foreach arch,$(ARCHS),${BIN_DIR}/rocketpool-daemon-linux-$(arch))
13+
TREEGEN_TARGET_STRINGS:=$(foreach arch,$(ARCHS),${BIN_DIR}/treegen-linux-$(arch))
14+
15+
MODULES:=$(foreach path,$(shell find . -name go.mod),$(dir $(path)))
16+
MODULE_GLOBS:=$(foreach module,$(MODULES),$(module)...)
17+
TEST_GLOBS:=$(filter-out ./bindings/...,$(MODULE_GLOBS))
18+
19+
define rocketpool-cli-template
20+
.PHONY: ${BIN_DIR}/rocketpool-cli-$1-$2
21+
${BIN_DIR}/rocketpool-cli-$1-$2: ${bin_deps}
22+
@echo "Building rocketpool-cli-$1-$2"
23+
ifndef NO_DOCKER
24+
docker run --rm -v ./:/src --user $(shell id -u):$(shell id -g) -e CGO_ENABLED=0 \
25+
-e GOARCH=$2 -e GOOS=$1 --workdir /src -v ~/.cache:/.cache rocketpool/smartnode-builder:${VERSION} \
26+
go build -o $$@ rocketpool-cli/rocketpool-cli.go
27+
else
28+
CGO_ENABLED=0 GOOS=$1 GOARCH=$2 go build -o $$@ ./rocketpool-cli/rocketpool-cli.go
29+
endif
30+
endef
31+
32+
# Must be first- so `make` runs this.
33+
.PHONY: default
34+
default: ${BUILD_DIR}/rocketpool-cli ${BUILD_DIR}/rocketpool-daemon ${BUILD_DIR}/treegen lint
35+
36+
.PHONY: all
37+
all: ${BUILD_DIR}/rocketpool-cli ${BUILD_DIR}/rocketpool-daemon ${BUILD_DIR}/treegen lint
38+
39+
.PHONY: release
40+
release: ${CLI_TARGET_STRINGS} ${DAEMON_TARGET_STRINGS} ${TREEGEN_TARGET_STRINGS} ${BUILD_DIR}/rocketpool-cli ${BUILD_DIR}/rocketpool-daemon ${BUILD_DIR}/treegen
41+
42+
# Target for build/rocketpool-cli which is a symlink to an os-specific build
43+
${BUILD_DIR}/rocketpool-cli: ${BIN_DIR}/rocketpool-cli-${LOCAL_OS}
44+
ln -sf $(shell pwd)/${BIN_DIR}/rocketpool-cli-${LOCAL_OS} ${BUILD_DIR}/rocketpool-cli
45+
46+
47+
# Target for build/rocketpool-daemon which is a symlink to an os-specific build
48+
${BUILD_DIR}/rocketpool-daemon: ${BIN_DIR}/rocketpool-daemon-${LOCAL_OS}
49+
ln -sf $(shell pwd)/${BIN_DIR}/rocketpool-daemon-${LOCAL_OS} ${BUILD_DIR}/rocketpool-daemon
50+
51+
# Target for build/treegen which is a symlink to a version-specific build
52+
${BUILD_DIR}/treegen: ${BIN_DIR}/treegen-${LOCAL_OS}
53+
ln -sf $(shell pwd)/${BIN_DIR}/treegen-${LOCAL_OS} ${BUILD_DIR}/treegen
54+
55+
# docker-builder container
56+
.PHONY: docker-builder
57+
docker-builder:
58+
VERSION=${VERSION} docker bake -f docker/daemon-bake.hcl builder
59+
60+
bin_deps = ${BIN_DIR}
61+
ifndef NO_DOCKER
62+
bin_deps += docker-builder
63+
endif
64+
65+
docker_build_cmd_amd64 = docker run --rm -v ./:/src --user $(shell id -u):$(shell id -g) -e CGO_ENABLED=1 -e CGO_C_FLAGS="-O -D__BLST_PORTABLE__" \
66+
-e GOARCH=amd64 -e GOOS=linux --workdir /src -v ~/.cache:/.cache rocketpool/smartnode-builder:${VERSION} \
67+
go build
68+
local_build_cmd_amd64 = CGO_ENABLED=1 CGO_C_FLAGS="-O -D__BLST_PORTABLE__" GOARCH=amd64 GOOS=linux go build
69+
docker_build_cmd_arm64 = docker run --rm -v ./:/src --user $(shell id -u):$(shell id -g) -e CGO_ENABLED=1 -e CGO_C_FLAGS="-O -D__BLST_PORTABLE__" \
70+
-e CC=aarch64-linux-gnu-gcc -e CXX=aarch64-linux-gnu-cpp -e CGO_C_FLAGS="-O -D__BLST_PORTABLE__" -e GOARCH=arm64 -e GOOS=linux \
71+
--workdir /src -v ~/.cache:/.cache rocketpool/smartnode-builder:${VERSION} \
72+
go build
73+
local_build_cmd_arm64 = CGO_ENABLED=1 CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-cpp CGO_C_FLAGS="-O -D__BLST_PORTABLE__" GOARCH=arm64 GOOS=linux go build
74+
# amd64 daemon build
75+
.PHONY: ${BIN_DIR}/rocketpool-daemon-linux-amd64
76+
${BIN_DIR}/rocketpool-daemon-linux-amd64: ${bin_deps}
77+
ifndef NO_DOCKER
78+
${docker_build_cmd_amd64} -o $@ rocketpool/rocketpool.go
79+
else
80+
${local_build_cmd_amd64} -o $@ rocketpool/rocketpool.go
81+
endif
82+
83+
# arm64 daemon build
84+
.PHONY: ${BIN_DIR}/rocketpool-daemon-linux-arm64
85+
${BIN_DIR}/rocketpool-daemon-linux-arm64: ${bin_deps}
86+
ifndef NO_DOCKER
87+
${docker_build_cmd_arm64} -o $@ rocketpool/rocketpool.go
88+
else
89+
${local_build_cmd_arm64} -o $@ rocketpool/rocketpool.go
90+
endif
91+
92+
${BIN_DIR}:
93+
mkdir -p ${BIN_DIR}
94+
${DOCKER_DIR}:
95+
mkdir -p ${DOCKER_DIR}
96+
97+
$(foreach oos,$(CLI_TARGET_OOS),$(foreach arch,$(ARCHS),$(eval $(call rocketpool-cli-template,$(oos),$(arch)))))
98+
99+
# amd64 treegen build
100+
.PHONY: ${BIN_DIR}/treegen-linux-amd64
101+
${BIN_DIR}/treegen-linux-amd64: ${bin_deps}
102+
ifndef NO_DOCKER
103+
${docker_build_cmd_amd64} -o $@ ./treegen/.
104+
else
105+
${local_build_cmd_amd64} -o $@ ./treegen/.
106+
endif
107+
108+
# arm64 treegen build
109+
.PHONY: ${BIN_DIR}/treegen-linux-arm64
110+
${BIN_DIR}/treegen-linux-arm64: ${bin_deps}
111+
ifndef NO_DOCKER
112+
${docker_build_cmd_arm64} -o $@ ./treegen/.
113+
else
114+
${local_build_cmd_arm64} -o $@ ./treegen/.
115+
endif
116+
117+
# Docker containers
118+
.PHONY: docker
119+
docker: ${DOCKER_DIR}
120+
VERSION=${VERSION} docker bake -f docker/daemon-bake.hcl smartnode
121+
122+
.PHONY: docker-push
123+
docker-push: docker
124+
echo
125+
echo -n "Publishing smartnode:${VERSION} containers. Continue? [yN]: " && read ans && if [ $${ans:-'N'} != 'y' ]; then exit 1; fi
126+
rm -rf ~/.docker/manifests/docker.io_rocketpool_smartnode-${VERSION}
127+
docker push rocketpool/smartnode:${VERSION}-amd64
128+
docker push rocketpool/smartnode:${VERSION}-arm64
129+
docker manifest create rocketpool/smartnode:${VERSION} --amend rocketpool/smartnode:${VERSION}-amd64 --amend rocketpool/smartnode:${VERSION}-arm64
130+
docker manifest push --purge rocketpool/smartnode:${VERSION}
131+
echo "Done!"
132+
133+
.PHONY: docker-latest
134+
docker-latest: docker-push
135+
echo
136+
echo -n "Publishing smartnode:${VERSION} as latest. Continue? [yN]: " && read ans && if [ $${ans:-'N'} != 'y' ]; then exit 1; fi
137+
rm -rf ~/.docker/manifests/docker.io_rocketpool_smartnode-latest
138+
docker manifest create rocketpool/smartnode:latest --amend rocketpool/smartnode:${VERSION}-amd64 --amend rocketpool/smartnode:${VERSION}-arm64
139+
docker manifest push --purge rocketpool/smartnode:latest
140+
141+
.PHONY: docker-prune
142+
docker-prune:
143+
docker system prune -af
144+
docker buildx prune -af
145+
146+
define lint-template
147+
.PHONY: lint-$1
148+
lint-$1:
149+
docker run -e GOCACHE=/go/.cache/go-build -e GOLANGCI_LINT_CACHE=/go/.cache/golangci-lint --user $(shell id -u):$(shell id -g) --rm -v ~/.cache:/go/.cache -v .:/smartnode --workdir /smartnode/$1 golangci/golangci-lint:v2.1-alpine golangci-lint fmt --diff
150+
endef
151+
$(foreach module,$(MODULES),$(eval $(call lint-template,$(module))))
152+
.PHONY: lint
153+
lint: $(foreach module,$(MODULES),lint-$(module))
154+
155+
.PHONY: test
156+
test:
157+
go test -test.timeout 20m $(TEST_GLOBS)
158+
159+
.PHONY: clean
160+
clean:
161+
rm -rf ${BUILD_DIR}

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,29 @@ See the [Rocket Pool dockerhub](https://hub.docker.com/u/rocketpool) page for a
2424

2525
See the [Smartnode Installer](https://github.com/rocket-pool/smartnode-install) repository for supported platforms and installation instructions.
2626

27+
## Development
28+
29+
A [Makefile](./Makefile) is included for building, testing, and linting.
30+
31+
* `make` or `make default` will build rocketpool-cli, rocketpool-daemon, treegen, and run the linter.
32+
* build/rocketpool-cli and build/rocketpool-daemon will be symlinked to the version and architecture specific binaries in build/
33+
* `make all` will build rocketpool-cli, rocketpool-daemon, treegen, and run the linter.
34+
* symlinks will be created for the first 3 binaries in build/
35+
* `make release` will build all architecture specific binaries as well as docker images and manifests
36+
* It will tag docker images as latest as well as the version in `shared/version.txt`
37+
* It will put cli and native mode binaries in build/\<version\>
38+
* `make build/rocketpool-cli` builds just the cli
39+
* The build is done in docker, unless you run `make NO_DOCKER=true \<cmd\>`
40+
* `make build/rocketpool-daemon` builds just the daemon
41+
* The build is done in docker, unless you run `make NO_DOCKER=true \<cmd\>`
42+
* `make build/treegen` builds just the treegen stand-alone binary.
43+
* The build is done in docker, unless you run `make NO_DOCKER=true \<cmd\>`
44+
* `make docker` builds the rocketpool/smartnode containers for all supported architectures and saves them in build/\<version\>/docker
45+
* `make docker-push` builds, loads, pushes, creates a multi-arch manifest, and pushes the smartnode containers and manifest.
46+
* `make docker-latest` does the same as docker-push, but tags latest which is also pushed.
47+
* `make lint` runs the linter.
48+
* `make test` runs all unit tests.
49+
* `make clean` deletes any binaries. It does not clear your go caches. It does not clean up old docker images.
2750

2851
## CLI Commands
2952

addons/go.mod

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module github.com/rocket-pool/smartnode/addons
2+
3+
go 1.21
4+
5+
require (
6+
github.com/ethereum/go-ethereum v1.13.5
7+
google.golang.org/protobuf v1.34.2
8+
)
9+
10+
require (
11+
github.com/google/go-cmp v0.6.0 // indirect
12+
golang.org/x/crypto v0.26.0 // indirect
13+
golang.org/x/sys v0.24.0 // indirect
14+
)

0 commit comments

Comments
 (0)