Skip to content

Commit e2745c6

Browse files
authored
Merge pull request #2714 from brave-intl/master
Production 2024-11-19_01
2 parents 343eed2 + 36136d6 commit e2745c6

Some content is hidden

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

65 files changed

+2322
-1427
lines changed

.github/workflows/ci.yml

+7-18
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010

1111
env:
1212
GO111MODULE: on
13+
GOTOOLCHAIN: local
1314
TEST_TAGS: integration
1415
DATABASE_MIGRATIONS_URL: file://$(pwd)/migrations
1516
GEMINI_SUBMIT_TYPE: hmac
@@ -46,6 +47,7 @@ jobs:
4647
matrix:
4748
goversion:
4849
- 1.19
50+
- 1.22
4951

5052
steps:
5153
- name: Checkout repository
@@ -61,17 +63,11 @@ jobs:
6163
id: setup-go
6264
uses: actions/setup-go@v4
6365
with:
64-
go-version: ${{ matrix.goversion }}
66+
# Run both CI jobs explicitly with 1.22.
67+
# The 1.19 job is currently marked as required, but it needs to pass before it can be removed.
68+
go-version: 1.22
6569
cache-dependency-path: "**/go.sum"
6670

67-
- name: Ensure Module Path
68-
run: mkdir -p /opt/go/pkg/mod
69-
70-
- name: Copy From Module Cache
71-
if: steps.setup-go.outputs.cache-hit == 'true'
72-
run: |
73-
rsync -au "/home/runner/go/pkg/" "/opt/go/pkg"
74-
7571
- name: Install Docker Compose
7672
uses: KengoTODA/actions-setup-docker-compose@92cbaf8ac8c113c35e1cedd1182f217043fbdd00
7773
with:
@@ -87,13 +83,6 @@ jobs:
8783
- name: Run Tests
8884
run: |
8985
export VAULT_TOKEN=$(docker logs grant-vault 2>&1 | grep "Root Token" | tail -1 | cut -d ' ' -f 3 );
90-
docker compose -f docker-compose.yml -f docker-compose.dev.yml run --rm -v /opt/go/pkg:/go/pkg dev make
86+
export GOMODCACHE=$(go env GOMODCACHE)
87+
docker compose -f docker-compose.yml -f docker-compose.dev.yml run --rm -v $GOMODCACHE:/go/pkg/mod dev make
9188
92-
- name: Ensure Module Directory
93-
if: steps.setup-go.outputs.cache-hit != 'true'
94-
run: mkdir -p /home/runner/go/pkg
95-
96-
- name: Copy To Module Cache
97-
run: |
98-
sudo rsync -au "/opt/go/pkg/" "/home/runner/go/pkg"
99-
sudo chown -R runner:runner /home/runner/go/pkg

.github/workflows/golangci-lint.yml

+10-10
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ jobs:
1919
- uses: actions/checkout@v3
2020
- uses: actions/setup-go@v3
2121
with:
22-
go-version: '1.19'
22+
go-version: '1.22'
2323
- name: golangci-lint-libs
2424
uses: golangci/golangci-lint-action@v3
2525
with:
2626
working-directory: libs
27-
version: v1.50.1
27+
version: v1.57.2
2828
args: --timeout 3m
2929

3030
golangci-services:
@@ -34,12 +34,12 @@ jobs:
3434
- uses: actions/checkout@v3
3535
- uses: actions/setup-go@v3
3636
with:
37-
go-version: '1.19'
37+
go-version: '1.22'
3838
- name: golangci-lint-services
3939
uses: golangci/golangci-lint-action@v3
4040
with:
4141
working-directory: services
42-
version: v1.50.1
42+
version: v1.57.2
4343
args: --timeout 3m
4444

4545
golangci-tools:
@@ -49,12 +49,12 @@ jobs:
4949
- uses: actions/checkout@v3
5050
- uses: actions/setup-go@v3
5151
with:
52-
go-version: '1.19'
52+
go-version: '1.22'
5353
- name: golangci-lint-tools
5454
uses: golangci/golangci-lint-action@v3
5555
with:
5656
working-directory: tools
57-
version: v1.50.1
57+
version: v1.57.2
5858
args: --timeout 3m
5959

6060
golangci-cmd:
@@ -64,12 +64,12 @@ jobs:
6464
- uses: actions/checkout@v3
6565
- uses: actions/setup-go@v3
6666
with:
67-
go-version: '1.19'
67+
go-version: '1.22'
6868
- name: golangci-lint-cmd
6969
uses: golangci/golangci-lint-action@v3
7070
with:
7171
working-directory: cmd
72-
version: v1.50.1
72+
version: v1.57.2
7373
args: --timeout 3m
7474

7575
golangci-main:
@@ -79,10 +79,10 @@ jobs:
7979
- uses: actions/checkout@v3
8080
- uses: actions/setup-go@v3
8181
with:
82-
go-version: '1.19'
82+
go-version: '1.22'
8383
- name: golangci-lint-main
8484
uses: golangci/golangci-lint-action@v3
8585
with:
8686
working-directory: main
87-
version: v1.50.1
87+
version: v1.57.2
8888
args: --timeout 3m

.golangci.yaml

+22-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
run:
2-
go: "1.19"
2+
go: "1.22"
33
timeout: 3m
44

55
linters-settings:
@@ -18,19 +18,27 @@ linters-settings:
1818
# Default: false
1919
check-type-assertions: true
2020

21-
gocritic:
22-
# Settings passed to gocritic.
23-
# The settings key is the name of a supported gocritic checker.
24-
# The list of supported checkers can be find in https://go-critic.github.io/overview.
25-
settings:
26-
captLocal:
27-
# Whether to restrict checker to params only.
28-
# Default: true
29-
paramsOnly: false
30-
underef:
31-
# Whether to skip (*x).method() calls where x is a pointer receiver.
32-
# Default: true
33-
skipRecvDeref: false
21+
gocritic:
22+
# Settings passed to gocritic.
23+
# The settings key is the name of a supported gocritic checker.
24+
# The list of supported checkers can be find in https://go-critic.github.io/overview.
25+
settings:
26+
captLocal:
27+
# Whether to restrict checker to params only.
28+
# Default: true
29+
paramsOnly: false
30+
underef:
31+
# Whether to skip (*x).method() calls where x is a pointer receiver.
32+
# Default: true
33+
skipRecvDeref: false
34+
35+
revive:
36+
rules:
37+
- name: if-return
38+
disabled: true
39+
40+
- name: unused-parameter
41+
disabled: true
3442

3543
varcheck:
3644
# Check usage of exported fields and variables.

Dockerfile

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.19-alpine as builder
1+
FROM golang:1.22-alpine as builder
22

33
# Put certs in builder image.
44
RUN apk update
@@ -12,25 +12,22 @@ ARG COMMIT
1212
WORKDIR /src
1313
COPY . ./
1414

15-
RUN chown -R nobody:nobody /src/ && mkdir /.cache && chown -R nobody:nobody /.cache
16-
17-
USER nobody
18-
19-
RUN cd main && go mod download && CGO_ENABLED=0 GOOS=linux go build \
15+
RUN cd main && go mod download && CGO_ENABLED=0 GOOS=linux GOTOOLCHAIN=local go build \
2016
-ldflags "-w -s -X main.version=${VERSION} -X main.buildTime=${BUILD_TIME} -X main.commit=${COMMIT}" \
2117
-o bat-go main.go
2218

23-
# golang:1.19-alpine is based on alpine:3.18.
24-
FROM alpine:3.18 as base
19+
FROM alpine:3.19 as base
2520

2621
# Put certs in artifact from builder.
2722
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
2823
COPY --from=builder /src/main/bat-go /bin/
2924

3025
FROM base as payments
26+
USER nobody
3127
CMD ["bat-go", "serve", "nitro", "inside-enclave", "--log-address", "vm(3):2345", "--egress-address", "vm(3):1234", "--upstream-url", "http://0.0.0.0:8080", "--address", ":8080"]
3228

3329
FROM base as artifact
3430
COPY --from=builder /src/migrations/ /migrations/
31+
USER nobody
3532
EXPOSE 3333
3633
CMD ["bat-go", "serve", "grant", "--enable-job-workers", "true"]

Makefile

+7-15
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ all: test create-json-schema buildcmd
2424
codeql: download-mod buildcmd
2525

2626
buildcmd:
27-
cd main && CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags "-w -s -X main.version=${GIT_VERSION} -X main.buildTime=${BUILD_TIME} -X main.commit=${GIT_COMMIT}" -o ${OUTPUT}/bat-go main.go
27+
cd main && CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) GOTOOLCHAIN=local go build -ldflags "-w -s -X main.version=${GIT_VERSION} -X main.buildTime=${BUILD_TIME} -X main.commit=${GIT_COMMIT}" -o ${OUTPUT}/bat-go main.go
2828

2929
mock:
3030
cd services && mockgen -source=./promotion/claim.go -destination=promotion/mockclaim.go -package=promotion
@@ -122,14 +122,6 @@ docker-dev:
122122
$(eval VAULT_TOKEN = $(shell docker logs grant-vault 2>&1 | grep "Root Token" | tail -1 | cut -d ' ' -f 3 ))
123123
VAULT_TOKEN=$(VAULT_TOKEN) docker compose -f docker-compose.yml -f docker-compose.dev.yml run --rm -p 3333:3333 dev /bin/bash
124124

125-
docker-refresh-dev:
126-
$(eval VAULT_TOKEN = $(shell docker logs grant-vault 2>&1 | grep "Root Token" | tail -1 | cut -d ' ' -f 3 ))
127-
VAULT_TOKEN=$(VAULT_TOKEN) docker compose -f docker-compose.yml -f docker-compose.dev-refresh.yml up -d dev-refresh
128-
129-
docker-refresh-skus:
130-
$(eval VAULT_TOKEN = $(shell docker logs grant-vault 2>&1 | grep "Root Token" | tail -1 | cut -d ' ' -f 3 ))
131-
VAULT_TOKEN=$(VAULT_TOKEN) docker compose -f docker-compose.yml -f docker-compose.skus-refresh.yml up -d skus-refresh
132-
133125
settlement-tools:
134126
$(eval GOOS?=darwin)
135127
$(eval GOARCH?=amd64)
@@ -138,7 +130,7 @@ settlement-tools:
138130
cp tools/settlement/config.hcl target/settlement-tools/
139131
cp tools/settlement/README.md target/settlement-tools/
140132
cp tools/settlement/hashicorp.asc target/settlement-tools/
141-
cd main/ && CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -v -ldflags "-w -s -X main.version=${GIT_VERSION} -X main.buildTime=${BUILD_TIME} -X main.commit=${GIT_COMMIT}" -o ../target/settlement-tools/bat-cli
133+
cd main/ && CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) GOTOOLCHAIN=local go build -v -ldflags "-w -s -X main.version=${GIT_VERSION} -X main.buildTime=${BUILD_TIME} -X main.commit=${GIT_COMMIT}" -o ../target/settlement-tools/bat-cli
142134
GOOS=$(GOOS) GOARCH=$(GOARCH) make download-vault
143135

144136
docker-settlement-tools:
@@ -190,11 +182,11 @@ format-lint:
190182
make format && make lint
191183

192184
lint: ensure-gomod-volume
193-
docker run --rm -v "$$(pwd):/app" -v batgo_lint_gomod:/go/pkg --workdir /app/main golangci/golangci-lint:v1.49.0 golangci-lint run -v ./...
194-
docker run --rm -v "$$(pwd):/app" -v batgo_lint_gomod:/go/pkg --workdir /app/cmd golangci/golangci-lint:v1.49.0 golangci-lint run -v ./...
195-
docker run --rm -v "$$(pwd):/app" -v batgo_lint_gomod:/go/pkg --workdir /app/libs golangci/golangci-lint:v1.49.0 golangci-lint run -v ./...
196-
docker run --rm -v "$$(pwd):/app" -v batgo_lint_gomod:/go/pkg --workdir /app/services golangci/golangci-lint:v1.49.0 golangci-lint run -v ./...
197-
docker run --rm -v "$$(pwd):/app" -v batgo_lint_gomod:/go/pkg --workdir /app/tools golangci/golangci-lint:v1.49.0 golangci-lint run -v ./...
185+
docker run --rm -v "$$(pwd):/app" -v batgo_lint_gomod:/go/pkg --workdir /app/main golangci/golangci-lint:v1.57.2 golangci-lint run -v ./...
186+
docker run --rm -v "$$(pwd):/app" -v batgo_lint_gomod:/go/pkg --workdir /app/cmd golangci/golangci-lint:v1.57.2 golangci-lint run -v ./...
187+
docker run --rm -v "$$(pwd):/app" -v batgo_lint_gomod:/go/pkg --workdir /app/libs golangci/golangci-lint:v1.57.2 golangci-lint run -v ./...
188+
docker run --rm -v "$$(pwd):/app" -v batgo_lint_gomod:/go/pkg --workdir /app/services golangci/golangci-lint:v1.57.2 golangci-lint run -v ./...
189+
docker run --rm -v "$$(pwd):/app" -v batgo_lint_gomod:/go/pkg --workdir /app/tools golangci/golangci-lint:v1.57.2 golangci-lint run -v ./...
198190

199191
download-mod:
200192
cd ./cmd && go mod download && cd ..

README.md

+3-18
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
## Developer Setup
77

8-
1. [Install Go 1.12](https://golang.org/doc/install) (NOTE: Go 1.10 and earlier will not work!)
8+
1. [Install Go](https://golang.org/doc/install) (Go 1.22 or later)
99

1010
2. [Install GolangCI-Lint](https://github.com/golangci/golangci-lint#install)
1111

12-
3. `go get -u github.com/hexdigest/gowrap/cmd/gowrap`
12+
3. `go install github.com/hexdigest/gowrap/cmd/gowrap@latest`
1313

1414
4. Clone this repo via `git clone https://github.com/brave-intl/bat-go`
1515

@@ -54,25 +54,10 @@ You can run all the unit and integration tests by setting the env `TEST_TAGS=int
5454
`make docker-dev`
5555

5656
Services are split up for testing:
57-
`cd /src/grant-server/payment ; > go test --tags=integration -v`
57+
`cd /src/services/payments ; go test --tags=integration -v`
5858

5959
For example in `promotion` you can run specific tests by running a command similar to `go test --tags=integration -run TestControllersTestSuite/TestCreateOrder`.
6060

61-
### Rapid Iteration dev Environment
62-
63-
On occasion it is desirable to re-run the development environment at will quickly. To this
64-
end you can run `make docker-refresh-dev` which will spin up the bat-go services including a
65-
container named `grant-refresh-dev`. If you want to recompile this service you merely need to
66-
perform a `docker restart grant-refresh-dev` and it will recompile and run the service.
67-
68-
A particularly interesting use case is marrying this with utilities such as `fswatch` to watch
69-
for file changes. There is an example below which will restart this `grant-refresh-dev` container
70-
on any file change in the source directory:
71-
72-
```bash
73-
fswatch . | xargs -I {} sh -c '$(docker ps -f "name=grant-refresh-dev" --format "docker restart {{.ID}}")'
74-
```
75-
7661
## Building a prod image using docker
7762

7863
You can build a docker image without installing the go toolchain. Ensure docker

cmd/go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ require (
4747
github.com/spf13/pflag v1.0.5 // indirect
4848
github.com/subosito/gotenv v1.4.1 // indirect
4949
github.com/throttled/throttled v2.2.5+incompatible // indirect
50-
golang.org/x/crypto v0.17.0 // indirect
51-
golang.org/x/sys v0.15.0 // indirect
50+
golang.org/x/crypto v0.21.0 // indirect
51+
golang.org/x/sys v0.18.0 // indirect
5252
golang.org/x/text v0.14.0 // indirect
5353
google.golang.org/protobuf v1.28.1 // indirect
5454
gopkg.in/ini.v1 v1.67.0 // indirect

cmd/go.sum

+5-5
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
307307
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
308308
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
309309
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
310-
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
311-
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
310+
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
311+
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
312312
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
313313
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
314314
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@@ -378,7 +378,7 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
378378
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
379379
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
380380
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
381-
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
381+
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
382382
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
383383
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
384384
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -449,8 +449,8 @@ golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBc
449449
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
450450
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
451451
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
452-
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
453-
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
452+
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
453+
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
454454
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
455455
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
456456
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

0 commit comments

Comments
 (0)