Skip to content

Commit 843a3fc

Browse files
committed
multi: dockerize tools
1 parent ebb5e94 commit 843a3fc

File tree

8 files changed

+1466
-48
lines changed

8 files changed

+1466
-48
lines changed

.golangci.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
run:
2+
# timeout for analysis
3+
deadline: 4m
4+
5+
build-tags:
6+
- autopilotrpc
7+
- signrpc
8+
- walletrpc
9+
- chainrpc
10+
- invoicesrpc
11+
- watchtowerrpc
12+
- neutrinorpc
13+
- peersrpc
14+
15+
linters-settings:
16+
govet:
17+
# Don't report about shadowed variables
18+
check-shadowing: false
19+
gofmt:
20+
# simplify code: gofmt with `-s` option, true by default
21+
simplify: true
22+
tagliatelle:
23+
case:
24+
rules:
25+
json: snake
26+
whitespace:
27+
multi-func: true
28+
multi-if: true
29+
gosec:
30+
excludes:
31+
- G402 # Look for bad TLS connection settings.
32+
- G306 # Poor file permissions used when writing to a new file.
33+
staticcheck:
34+
go: "1.18"
35+
checks: ["-SA1019"]
36+
37+
linters:
38+
enable:
39+
- gofmt
40+
- tagliatelle
41+
- whitespace
42+
- gosec
43+
44+
issues:
45+
exclude-rules:
46+
# Exclude gosec from running for tests so that tests with weak randomness
47+
# (math/rand) will pass the linter.
48+
- path: _test\.go
49+
linters:
50+
- gosec
51+
- path: internal/test/.*
52+
linters:
53+
- gosec
54+
# Fix false positives because of build flags in itest directory.
55+
- path: itest/.*
56+
linters:
57+
- unused
58+
- deadcode
59+
- varcheck

Makefile

+30-34
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ LOOP_PKG := github.com/lightninglabs/loop
55
POOL_PKG := github.com/lightninglabs/pool
66
BTCD_PKG := github.com/btcsuite/btcd
77

8-
LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
9-
GOVERALLS_PKG := github.com/mattn/goveralls
108
GOACC_PKG := github.com/ory/go-acc
9+
GOIMPORTS_PKG := github.com/rinchsan/gosimports/cmd/gosimports
10+
TOOLS_DIR := tools
1111

1212
GO_BIN := ${GOPATH}/bin
13-
GOVERALLS_BIN := $(GO_BIN)/goveralls
14-
LINT_BIN := $(GO_BIN)/golangci-lint
1513
GOACC_BIN := $(GO_BIN)/go-acc
14+
GOIMPORTS_BIN := $(GO_BIN)/gosimports
1615

1716
COMMIT := $(shell git describe --abbrev=40 --dirty --tags)
1817
COMMIT_HASH := $(shell git rev-parse HEAD)
@@ -30,16 +29,12 @@ POOL_COMMIT := $(shell cat go.mod | \
3029
awk -F " " '{ print $$2 }' | \
3130
awk -F "/" '{ print $$1 }')
3231

33-
LINT_COMMIT := v1.18.0
34-
GOACC_COMMIT := ddc355013f90fea78d83d3a6c71f1d37ac07ecd5
35-
36-
DEPGET := cd /tmp && go get -v
3732
GOBUILD := go build -v
3833
GOINSTALL := go install -v
3934
GOTEST := go test -v
4035
GOMOD := go mod
4136

42-
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
37+
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -name "*pb.go" -not -name "*pb.gw.go" -not -name "*.pb.json.go")
4338
GOLIST := go list -deps $(PKG)/... | grep '$(PKG)'| grep -v '/vendor/'
4439
GOLISTCOVER := $(shell go list -deps -f '{{.ImportPath}}' ./... | grep '$(PKG)' | sed -e 's/^$(ESCPKG)/./')
4540

@@ -74,6 +69,14 @@ LDFLAGS := $(call make_ldflags, $(LND_RELEASE_TAGS))
7469
# and omit the DWARF symbol table (-w). Also we clear the build ID.
7570
RELEASE_LDFLAGS := $(call make_ldflags, $(LND_RELEASE_TAGS), -s -w -buildid=)
7671

72+
# Linting uses a lot of memory, so keep it under control by limiting the number
73+
# of workers if requested.
74+
ifneq ($(workers),)
75+
LINT_WORKERS = --concurrency=$(workers)
76+
endif
77+
78+
DOCKER_TOOLS = docker run -v $$(pwd):/build litd-tools
79+
7780
ITEST_TAGS := rpctest itest $(LND_RELEASE_TAGS)
7881
ITEST_LDFLAGS := $(call make_ldflags, $(ITEST_TAGS))
7982

@@ -91,17 +94,13 @@ all: scratch check install
9194
# DEPENDENCIES
9295
# ============
9396

94-
$(GOVERALLS_BIN):
95-
@$(call print, "Fetching goveralls.")
96-
go get -u $(GOVERALLS_PKG)
97-
98-
$(LINT_BIN):
99-
@$(call print, "Fetching linter")
100-
$(DEPGET) $(LINT_PKG)@$(LINT_COMMIT)
101-
10297
$(GOACC_BIN):
103-
@$(call print, "Fetching go-acc")
104-
$(DEPGET) $(GOACC_PKG)@$(GOACC_COMMIT)
98+
@$(call print, "Installing go-acc.")
99+
cd $(TOOLS_DIR); go install -trimpath -tags=tools $(GOACC_PKG)
100+
101+
$(GOIMPORTS_BIN):
102+
@$(call print, "Installing goimports.")
103+
cd $(TOOLS_DIR); go install -trimpath $(GOIMPORTS_PKG)
105104

106105
yarn-install:
107106
@$(call print, "Installing app dependencies with yarn")
@@ -139,6 +138,10 @@ release: app-build
139138
@$(call print, "Creating release of lightning-terminal.")
140139
./release.sh build-release "$(VERSION_TAG)" "$(BUILD_SYSTEM)" "$(LND_RELEASE_TAGS)" "$(RELEASE_LDFLAGS)"
141140

141+
docker-tools:
142+
@$(call print, "Building tools docker image.")
143+
docker build -q -t litd-tools $(TOOLS_DIR)
144+
142145
scratch: build
143146

144147
# =======
@@ -161,16 +164,6 @@ unit-race:
161164
mkdir -p app/build && touch app/build/index.html
162165
env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(UNIT_RACE) -tags="$(LND_RELEASE_TAGS)"
163166

164-
goveralls: $(GOVERALLS_BIN)
165-
@$(call print, "Sending coverage report.")
166-
$(GOVERALLS_BIN) -coverprofile=coverage.txt -service=travis-ci
167-
168-
travis-race: lint unit-race
169-
170-
travis-cover: lint unit-cover goveralls
171-
172-
travis-itest: lint
173-
174167
build-itest: app-build
175168
@$(call print, "Building itest btcd and litd.")
176169
CGO_ENABLED=0 $(GOBUILD) -tags="$(ITEST_TAGS)" -o itest/btcd-itest -ldflags "$(ITEST_LDFLAGS)" $(BTCD_PKG)
@@ -197,13 +190,15 @@ flake-unit:
197190
# =========
198191
# UTILITIES
199192
# =========
200-
fmt:
193+
fmt: $(GOIMPORTS_BIN)
194+
@$(call print, "Fixing imports.")
195+
gosimports -w $(GOFILES_NOVENDOR)
201196
@$(call print, "Formatting source.")
202197
gofmt -l -w -s $(GOFILES_NOVENDOR)
203198

204-
lint: $(LINT_BIN)
199+
lint: docker-tools
205200
@$(call print, "Linting source.")
206-
$(LINT)
201+
$(DOCKER_TOOLS) golangci-lint run -v $(LINT_WORKERS)
207202

208203
mod:
209204
@$(call print, "Tidying modules.")
@@ -231,9 +226,10 @@ protos:
231226

232227
protos-check: protos
233228
@$(call print, "Verifying compiled protos.")
234-
if test -n "$$(git describe --dirty | grep dirty)"; then echo "Protos not properly formatted or not compiled with v3.4.0"; git status; git diff; exit 1; fi
229+
if test -n "$$(git describe --dirty | grep dirty)"; then echo "Protos not properly formatted or not compiled with correct version"; git status; git diff; exit 1; fi
235230

236231
clean:
237232
@$(call print, "Cleaning source.$(NC)")
238-
$(RM) ./lightning-terminal-debug
233+
$(RM) ./litcli-debug
234+
$(RM) ./litd-debug
239235
$(RM) coverage.txt

deps.go

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//go:build deps
2+
// +build deps
3+
4+
package terminal
5+
6+
// This is a workaround to make sure go mod keeps around the dependencies in the
7+
// go.sum file that we only use during compilation of the CLI binaries that are
8+
// delivered together with LiT.
9+
import (
10+
_ "github.com/lightninglabs/faraday/cmd/frcli"
11+
_ "github.com/lightninglabs/loop/cmd/loop"
12+
_ "github.com/lightninglabs/pool/cmd/pool"
13+
_ "github.com/lightningnetwork/lnd/cmd/lncli"
14+
)

tools.go

-14
This file was deleted.

tools/Dockerfile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM golang:1.18.0-buster
2+
3+
RUN apt-get update && apt-get install -y git
4+
ENV GOCACHE=/tmp/build/.cache
5+
ENV GOMODCACHE=/tmp/build/.modcache
6+
7+
COPY . /tmp/tools
8+
9+
RUN cd /tmp \
10+
&& mkdir -p /tmp/build/.cache \
11+
&& mkdir -p /tmp/build/.modcache \
12+
&& cd /tmp/tools \
13+
&& go install -trimpath -tags=tools github.com/golangci/golangci-lint/cmd/golangci-lint \
14+
&& chmod -R 777 /tmp/build/
15+
16+
WORKDIR /build

0 commit comments

Comments
 (0)