Skip to content

Commit

Permalink
ops: golang ci improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
protolambda committed Oct 20, 2023
1 parent 7591f19 commit e02310c
Show file tree
Hide file tree
Showing 36 changed files with 588 additions and 396 deletions.
457 changes: 333 additions & 124 deletions .circleci/config.yml

Large diffs are not rendered by default.

20 changes: 19 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
COMPOSEFLAGS=-d
ITESTS_L2_HOST=http://localhost:9545
BEDROCK_TAGS_REMOTE?=origin
OP_STACK_GO_BUILDER?=us-docker.pkg.dev/oplabs-tools-artifacts/images/op_stack_go:latest

build: build-go build-ts
.PHONY: build

build-go: submodules op-node op-proposer op-batcher
.PHONY: build-go

lint-go:
golangci-lint run -E goimports,sqlclosecheck,bodyclose,asciicheck,misspell,errorlint --timeout 5m -e "errors.As" -e "errors.Is" ./...
.PHONY: lint-go

build-ts: submodules
if [ -n "$$NVM_DIR" ]; then \
. $$NVM_DIR/nvm.sh && nvm use; \
Expand All @@ -19,6 +24,13 @@ build-ts: submodules
ci-builder:
docker build -t ci-builder -f ops/docker/ci-builder/Dockerfile .

golang-docker:
DOCKER_BUILDKIT=1 docker build -t op-stack-go \
--build-arg GIT_COMMIT=$$(git rev-parse HEAD) \
--build-arg GIT_DATE=$$(git show -s --format='%ct') \
-f ops/docker/op-stack-go/Dockerfile .
.PHONY: golang-docker

submodules:
# CI will checkout submodules on its own (and fails on these commands)
if [ -z "$$GITHUB_ENV" ]; then \
Expand Down Expand Up @@ -163,4 +175,10 @@ bedrock-markdown-links:
--exclude-mail /input/README.md "/input/specs/**/*.md"

install-geth:
go install github.com/ethereum/go-ethereum/cmd/geth@$(shell cat .gethrc)
./ops/scripts/geth-version-checker.sh && \
(echo "Geth versions match, not installing geth..."; true) || \
(echo "Versions do not match, installing geth!"; \
go install -v github.com/ethereum/go-ethereum/cmd/geth@$(shell cat .gethrc); \
echo "Installed geth!"; true)
.PHONY: install-geth

4 changes: 3 additions & 1 deletion bedrock-devnet/devnet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ def main():

log.info('Building docker images')
run_command(['docker', 'compose', 'build', '--progress', 'plain'], cwd=paths.ops_bedrock_dir, env={
'PWD': paths.ops_bedrock_dir
'PWD': paths.ops_bedrock_dir,
'DOCKER_BUILDKIT': '1', # (should be available by default in later versions, but explicitly enable it anyway)
'COMPOSE_DOCKER_CLI_BUILD': '1' # use the docker cache
})

log.info('Devnet starting')
Expand Down
7 changes: 2 additions & 5 deletions cannon/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GITCOMMIT := $(shell git rev-parse HEAD)
GITDATE := $(shell git show -s --format='%ct')
GITCOMMIT ?= $(shell git rev-parse HEAD)
GITDATE ?= $(shell git show -s --format='%ct')
VERSION := v0.0.0

LDFLAGSSTRING +=-X main.GitCommit=$(GITCOMMIT)
Expand All @@ -20,9 +20,6 @@ elf:
test: elf
go test -v ./...

lint:
golangci-lint run -E goimports,sqlclosecheck,bodyclose,asciicheck,misspell,errorlint --timeout 5m -e "errors.As" -e "errors.Is"

fuzz:
go test -run NOTAREALTEST -v -fuzztime 10s -fuzz=FuzzStateSyscallBrk ./mipsevm
go test -run NOTAREALTEST -v -fuzztime 10s -fuzz=FuzzStateSyscallClone ./mipsevm
Expand Down
4 changes: 2 additions & 2 deletions endpoint-monitor/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GITCOMMIT := $(shell git rev-parse HEAD)
GITDATE := $(shell git show -s --format='%ct')
GITCOMMIT ?= $(shell git rev-parse HEAD)
GITDATE ?= $(shell git show -s --format='%ct')
VERSION := v0.0.0

LDFLAGSSTRING +=-X main.GitCommit=$(GITCOMMIT)
Expand Down
33 changes: 5 additions & 28 deletions op-batcher/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,9 @@
FROM --platform=$BUILDPLATFORM golang:1.21.1-alpine3.18 as builder

ARG VERSION=v0.0.0

RUN apk add --no-cache make gcc musl-dev linux-headers git jq bash

COPY ./go.mod /app/go.mod
COPY ./go.sum /app/go.sum

WORKDIR /app

RUN go mod download

# build op-batcher with the shared go.mod & go.sum files
COPY ./op-batcher /app/op-batcher
COPY ./op-bindings /app/op-bindings
COPY ./op-node /app/op-node
COPY ./op-service /app/op-service

COPY ./.git /app/.git

WORKDIR /app/op-batcher

ARG TARGETOS TARGETARCH

RUN make op-batcher VERSION="$VERSION" GOOS=$TARGETOS GOARCH=$TARGETARCH
ARG OP_STACK_GO_BUILDER=us-docker.pkg.dev/oplabs-tools-artifacts/images/op_stack_go:latest
FROM $OP_STACK_GO_BUILDER as builder
# See "make golang-docker" and /ops/docker/op-stack-go

FROM alpine:3.18

COPY --from=builder /app/op-batcher/bin/op-batcher /usr/local/bin
COPY --from=builder /usr/local/bin/op-batcher /usr/local/bin/op-batcher

ENTRYPOINT ["op-batcher"]
CMD ["op-batcher"]
2 changes: 2 additions & 0 deletions op-batcher/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# ignore everything but the dockerfile, the op-stack-go base image performs the build
*
8 changes: 2 additions & 6 deletions op-batcher/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GITCOMMIT := $(shell git rev-parse HEAD)
GITDATE := $(shell git show -s --format='%ct')
GITCOMMIT ?= $(shell git rev-parse HEAD)
GITDATE ?= $(shell git show -s --format='%ct')
VERSION := v0.0.0

LDFLAGSSTRING +=-X main.GitCommit=$(GITCOMMIT)
Expand All @@ -16,9 +16,6 @@ clean:
test:
go test -v ./...

lint:
golangci-lint run -E goimports,sqlclosecheck,bodyclose,asciicheck,misspell,errorlint --timeout 5m -e "errors.As" -e "errors.Is" ./...

fuzz:
go test -run NOTAREALTEST -v -fuzztime 10s -fuzz FuzzChannelConfig_CheckTimeout ./batcher
go test -run NOTAREALTEST -v -fuzztime 10s -fuzz FuzzDurationZero ./batcher
Expand All @@ -33,5 +30,4 @@ fuzz:
op-batcher \
clean \
test \
lint \
fuzz
3 changes: 0 additions & 3 deletions op-bindings/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ bindings-build:
-package $(pkg) \
-monorepo-base $(monorepo-base)

lint:
golangci-lint run -E goimports,sqlclosecheck,bodyclose,asciicheck,misspell,errorlint --timeout 5m -e "errors.As" -e "errors.Is" ./...

mkdir:
mkdir -p $(pkg)

Expand Down
10 changes: 3 additions & 7 deletions op-bootnode/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GITCOMMIT := $(shell git rev-parse HEAD)
GITDATE := $(shell git show -s --format='%ct')
GITCOMMIT ?= $(shell git rev-parse HEAD)
GITDATE ?= $(shell git show -s --format='%ct')
VERSION := v0.0.0

LDFLAGSSTRING +=-X main.GitCommit=$(GITCOMMIT)
Expand All @@ -16,11 +16,7 @@ clean:
test:
go test -v ./...

lint:
golangci-lint run -E goimports,sqlclosecheck,bodyclose,asciicheck,misspell,errorlint --timeout 5m -e "errors.As" -e "errors.Is" ./...

.PHONY: \
op-bootnode \
clean \
test \
lint
test
3 changes: 0 additions & 3 deletions op-chain-ops/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ check-l2:
test:
go test ./...

lint:
golangci-lint run -E goimports,sqlclosecheck,bodyclose,asciicheck,misspell,errorlint --timeout 5m -e "errors.As" -e "errors.Is" ./...

fuzz:
go test -run NOTAREALTEST -v -fuzztime 10s -fuzz=FuzzEncodeDecodeWithdrawal ./crossdomain
go test -run NOTAREALTEST -v -fuzztime 10s -fuzz=FuzzEncodeDecodeLegacyWithdrawal ./crossdomain
Expand Down
51 changes: 6 additions & 45 deletions op-challenger/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,56 +1,17 @@
FROM --platform=$BUILDPLATFORM golang:1.21.1-alpine3.18 as builder

ARG VERSION=v0.0.0

RUN apk add --no-cache make gcc musl-dev linux-headers git jq bash

COPY ./go.mod /app/go.mod
COPY ./go.sum /app/go.sum

WORKDIR /app

RUN go mod download

# build op-challenger with the shared go.mod & go.sum files
COPY ./op-challenger /app/op-challenger
COPY ./op-program /app/op-program
COPY ./op-preimage /app/op-preimage
COPY ./op-bindings /app/op-bindings
COPY ./op-node /app/op-node
COPY ./op-service /app/op-service
COPY ./.git /app/.git

# Copy cannon and its dependencies
COPY ./cannon /app/cannon
COPY ./op-preimage /app/op-preimage
COPY ./op-chain-ops /app/op-chain-ops

WORKDIR /app/op-program

ARG TARGETOS TARGETARCH

RUN make op-program-host VERSION="$VERSION" GOOS=$TARGETOS GOARCH=$TARGETARCH

WORKDIR /app/cannon

ARG TARGETOS TARGETARCH

RUN make cannon VERSION="$VERSION" GOOS=$TARGETOS GOARCH=$TARGETARCH

WORKDIR /app/op-challenger

RUN make op-challenger VERSION="$VERSION" GOOS=$TARGETOS GOARCH=$TARGETARCH
ARG OP_STACK_GO_BUILDER=us-docker.pkg.dev/oplabs-tools-artifacts/images/op_stack_go:latest
FROM $OP_STACK_GO_BUILDER as builder
# See "make golang-docker" and /ops/docker/op-stack-go

FROM alpine:3.18

# Make the bundled op-program the default cannon server
COPY --from=builder /app/op-program/bin/op-program /usr/local/bin
COPY --from=builder /usr/local/bin/op-program /usr/local/bin/op-program
ENV OP_CHALLENGER_CANNON_SERVER /usr/local/bin/op-program

# Make the bundled cannon the default cannon executable
COPY --from=builder /app/cannon/bin/cannon /usr/local/bin
COPY --from=builder /usr/local/bin/cannon /usr/local/bin/cannon
ENV OP_CHALLENGER_CANNON_BIN /usr/local/bin/cannon

COPY --from=builder /app/op-challenger/bin/op-challenger /usr/local/bin
COPY --from=builder /usr/local/bin/op-challenger /usr/local/bin/op-challenger

CMD ["op-challenger"]
2 changes: 2 additions & 0 deletions op-challenger/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# ignore everything but the dockerfile, the op-stack-go base image performs the build
*
7 changes: 2 additions & 5 deletions op-challenger/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GITCOMMIT := $(shell git rev-parse HEAD)
GITDATE := $(shell git show -s --format='%ct')
GITCOMMIT ?= $(shell git rev-parse HEAD)
GITDATE ?= $(shell git show -s --format='%ct')
VERSION := v0.0.0

LDFLAGSSTRING +=-X main.GitCommit=$(GITCOMMIT)
Expand All @@ -16,9 +16,6 @@ clean:
test:
go test -v ./...

lint:
golangci-lint run -E goimports,sqlclosecheck,bodyclose,asciicheck,misspell,errorlint --timeout 5m -e "errors.As" -e "errors.Is" ./...

visualize:
./scripts/visualize.sh

Expand Down
4 changes: 0 additions & 4 deletions op-e2e/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,3 @@ clean:
rm -r ../.devnet
rm -r ../op-program/bin
.PHONY: clean

lint:
golangci-lint run -E goimports,sqlclosecheck,bodyclose,asciicheck,misspell,errorlint --timeout 5m -e "errors.As" -e "errors.Is" ./...
.PHONY: lint
21 changes: 4 additions & 17 deletions op-heartbeat/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
FROM golang:1.21.1-alpine3.18 as builder

RUN apk add --no-cache make gcc musl-dev linux-headers git jq bash

# build op-heartbeat with local monorepo go modules
COPY ./op-heartbeat /app/op-heartbeat
COPY ./op-node /app/op-node
COPY ./op-service /app/op-service
COPY ./go.mod /app/go.mod
COPY ./go.sum /app/go.sum

COPY ./.git /app/.git

WORKDIR /app/op-heartbeat

RUN make op-heartbeat
ARG OP_STACK_GO_BUILDER=us-docker.pkg.dev/oplabs-tools-artifacts/images/op_stack_go:latest
FROM $OP_STACK_GO_BUILDER as builder
# See "make golang-docker" and /ops/docker/op-stack-go

FROM alpine:3.18

COPY --from=builder /app/op-heartbeat/bin/op-heartbeat /usr/local/bin
COPY --from=builder /usr/local/bin/op-heartbeat /usr/local/bin/op-heartbeat

CMD ["op-heartbeat"]
2 changes: 2 additions & 0 deletions op-heartbeat/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# ignore everything but the dockerfile, the op-stack-go base image performs the build
*
7 changes: 2 additions & 5 deletions op-heartbeat/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GITCOMMIT := $(shell git rev-parse HEAD)
GITDATE := $(shell git show -s --format='%ct')
GITCOMMIT ?= $(shell git rev-parse HEAD)
GITDATE ?= $(shell git show -s --format='%ct')
VERSION := v0.0.0

LDFLAGSSTRING +=-X main.GitCommit=$(GITCOMMIT)
Expand All @@ -16,9 +16,6 @@ clean:
test:
go test -v ./...

lint:
golangci-lint run -E goimports,sqlclosecheck,bodyclose,asciicheck,misspell,errorlint --timeout 5m -e "errors.As" -e "errors.Is" ./...

.PHONY: \
clean \
op-heartbeat \
Expand Down
30 changes: 4 additions & 26 deletions op-node/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,9 @@
FROM --platform=$BUILDPLATFORM golang:1.21.1-alpine3.18 as builder

ARG VERSION=v0.0.0

RUN apk add --no-cache make gcc musl-dev linux-headers git jq bash

COPY ./go.mod /app/go.mod
COPY ./go.sum /app/go.sum

WORKDIR /app

RUN go mod download

# build op-node with the shared go.mod & go.sum files
COPY ./op-node /app/op-node
COPY ./op-chain-ops /app/op-chain-ops
COPY ./op-service /app/op-service
COPY ./op-bindings /app/op-bindings
COPY ./.git /app/.git

WORKDIR /app/op-node

ARG TARGETOS TARGETARCH

RUN make op-node VERSION="$VERSION" GOOS=$TARGETOS GOARCH=$TARGETARCH
ARG OP_STACK_GO_BUILDER=us-docker.pkg.dev/oplabs-tools-artifacts/images/op_stack_go:latest
FROM $OP_STACK_GO_BUILDER as builder
# See "make golang-docker" and /ops/docker/op-stack-go

FROM alpine:3.18

COPY --from=builder /app/op-node/bin/op-node /usr/local/bin
COPY --from=builder /usr/local/bin/op-node /usr/local/bin/op-node

CMD ["op-node"]
2 changes: 2 additions & 0 deletions op-node/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# ignore everything but the dockerfile, the op-stack-go base image performs the build
*
7 changes: 2 additions & 5 deletions op-node/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GITCOMMIT := $(shell git rev-parse HEAD)
GITDATE := $(shell git show -s --format='%ct')
GITCOMMIT ?= $(shell git rev-parse HEAD)
GITDATE ?= $(shell git show -s --format='%ct')
VERSION := v0.0.0

LDFLAGSSTRING +=-X main.GitCommit=$(GITCOMMIT)
Expand All @@ -17,9 +17,6 @@ clean:
test:
go test -v ./...

lint:
golangci-lint run -E goimports,sqlclosecheck,bodyclose,asciicheck,misspell,errorlint --timeout 5m -e "errors.As" -e "errors.Is" ./...

fuzz:
go test -run NOTAREALTEST -v -fuzztime 10s -fuzz FuzzL1InfoRoundTrip ./rollup/derive
go test -run NOTAREALTEST -v -fuzztime 10s -fuzz FuzzL1InfoAgainstContract ./rollup/derive
Expand Down
Loading

0 comments on commit e02310c

Please sign in to comment.