Skip to content

Commit

Permalink
Merge pull request #2714 from brave-intl/master
Browse files Browse the repository at this point in the history
Production 2024-11-19_01
  • Loading branch information
pavelbrm authored Nov 20, 2024
2 parents 343eed2 + 36136d6 commit e2745c6
Show file tree
Hide file tree
Showing 65 changed files with 2,322 additions and 1,427 deletions.
25 changes: 7 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:

env:
GO111MODULE: on
GOTOOLCHAIN: local
TEST_TAGS: integration
DATABASE_MIGRATIONS_URL: file://$(pwd)/migrations
GEMINI_SUBMIT_TYPE: hmac
Expand Down Expand Up @@ -46,6 +47,7 @@ jobs:
matrix:
goversion:
- 1.19
- 1.22

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

- name: Ensure Module Path
run: mkdir -p /opt/go/pkg/mod

- name: Copy From Module Cache
if: steps.setup-go.outputs.cache-hit == 'true'
run: |
rsync -au "/home/runner/go/pkg/" "/opt/go/pkg"
- name: Install Docker Compose
uses: KengoTODA/actions-setup-docker-compose@92cbaf8ac8c113c35e1cedd1182f217043fbdd00
with:
Expand All @@ -87,13 +83,6 @@ jobs:
- name: Run Tests
run: |
export VAULT_TOKEN=$(docker logs grant-vault 2>&1 | grep "Root Token" | tail -1 | cut -d ' ' -f 3 );
docker compose -f docker-compose.yml -f docker-compose.dev.yml run --rm -v /opt/go/pkg:/go/pkg dev make
export GOMODCACHE=$(go env GOMODCACHE)
docker compose -f docker-compose.yml -f docker-compose.dev.yml run --rm -v $GOMODCACHE:/go/pkg/mod dev make
- name: Ensure Module Directory
if: steps.setup-go.outputs.cache-hit != 'true'
run: mkdir -p /home/runner/go/pkg

- name: Copy To Module Cache
run: |
sudo rsync -au "/opt/go/pkg/" "/home/runner/go/pkg"
sudo chown -R runner:runner /home/runner/go/pkg
20 changes: 10 additions & 10 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.19'
go-version: '1.22'
- name: golangci-lint-libs
uses: golangci/golangci-lint-action@v3
with:
working-directory: libs
version: v1.50.1
version: v1.57.2
args: --timeout 3m

golangci-services:
Expand All @@ -34,12 +34,12 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.19'
go-version: '1.22'
- name: golangci-lint-services
uses: golangci/golangci-lint-action@v3
with:
working-directory: services
version: v1.50.1
version: v1.57.2
args: --timeout 3m

golangci-tools:
Expand All @@ -49,12 +49,12 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.19'
go-version: '1.22'
- name: golangci-lint-tools
uses: golangci/golangci-lint-action@v3
with:
working-directory: tools
version: v1.50.1
version: v1.57.2
args: --timeout 3m

golangci-cmd:
Expand All @@ -64,12 +64,12 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.19'
go-version: '1.22'
- name: golangci-lint-cmd
uses: golangci/golangci-lint-action@v3
with:
working-directory: cmd
version: v1.50.1
version: v1.57.2
args: --timeout 3m

golangci-main:
Expand All @@ -79,10 +79,10 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.19'
go-version: '1.22'
- name: golangci-lint-main
uses: golangci/golangci-lint-action@v3
with:
working-directory: main
version: v1.50.1
version: v1.57.2
args: --timeout 3m
36 changes: 22 additions & 14 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
run:
go: "1.19"
go: "1.22"
timeout: 3m

linters-settings:
Expand All @@ -18,19 +18,27 @@ linters-settings:
# Default: false
check-type-assertions: true

gocritic:
# Settings passed to gocritic.
# The settings key is the name of a supported gocritic checker.
# The list of supported checkers can be find in https://go-critic.github.io/overview.
settings:
captLocal:
# Whether to restrict checker to params only.
# Default: true
paramsOnly: false
underef:
# Whether to skip (*x).method() calls where x is a pointer receiver.
# Default: true
skipRecvDeref: false
gocritic:
# Settings passed to gocritic.
# The settings key is the name of a supported gocritic checker.
# The list of supported checkers can be find in https://go-critic.github.io/overview.
settings:
captLocal:
# Whether to restrict checker to params only.
# Default: true
paramsOnly: false
underef:
# Whether to skip (*x).method() calls where x is a pointer receiver.
# Default: true
skipRecvDeref: false

revive:
rules:
- name: if-return
disabled: true

- name: unused-parameter
disabled: true

varcheck:
# Check usage of exported fields and variables.
Expand Down
13 changes: 5 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.19-alpine as builder
FROM golang:1.22-alpine as builder

# Put certs in builder image.
RUN apk update
Expand All @@ -12,25 +12,22 @@ ARG COMMIT
WORKDIR /src
COPY . ./

RUN chown -R nobody:nobody /src/ && mkdir /.cache && chown -R nobody:nobody /.cache

USER nobody

RUN cd main && go mod download && CGO_ENABLED=0 GOOS=linux go build \
RUN cd main && go mod download && CGO_ENABLED=0 GOOS=linux GOTOOLCHAIN=local go build \
-ldflags "-w -s -X main.version=${VERSION} -X main.buildTime=${BUILD_TIME} -X main.commit=${COMMIT}" \
-o bat-go main.go

# golang:1.19-alpine is based on alpine:3.18.
FROM alpine:3.18 as base
FROM alpine:3.19 as base

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

FROM base as payments
USER nobody
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"]

FROM base as artifact
COPY --from=builder /src/migrations/ /migrations/
USER nobody
EXPOSE 3333
CMD ["bat-go", "serve", "grant", "--enable-job-workers", "true"]
22 changes: 7 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ all: test create-json-schema buildcmd
codeql: download-mod buildcmd

buildcmd:
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
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

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

docker-refresh-dev:
$(eval VAULT_TOKEN = $(shell docker logs grant-vault 2>&1 | grep "Root Token" | tail -1 | cut -d ' ' -f 3 ))
VAULT_TOKEN=$(VAULT_TOKEN) docker compose -f docker-compose.yml -f docker-compose.dev-refresh.yml up -d dev-refresh

docker-refresh-skus:
$(eval VAULT_TOKEN = $(shell docker logs grant-vault 2>&1 | grep "Root Token" | tail -1 | cut -d ' ' -f 3 ))
VAULT_TOKEN=$(VAULT_TOKEN) docker compose -f docker-compose.yml -f docker-compose.skus-refresh.yml up -d skus-refresh

settlement-tools:
$(eval GOOS?=darwin)
$(eval GOARCH?=amd64)
Expand All @@ -138,7 +130,7 @@ settlement-tools:
cp tools/settlement/config.hcl target/settlement-tools/
cp tools/settlement/README.md target/settlement-tools/
cp tools/settlement/hashicorp.asc target/settlement-tools/
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
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
GOOS=$(GOOS) GOARCH=$(GOARCH) make download-vault

docker-settlement-tools:
Expand Down Expand Up @@ -190,11 +182,11 @@ format-lint:
make format && make lint

lint: ensure-gomod-volume
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 ./...
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 ./...
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 ./...
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 ./...
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 ./...
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 ./...
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 ./...
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 ./...
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 ./...
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 ./...

download-mod:
cd ./cmd && go mod download && cd ..
Expand Down
21 changes: 3 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

## Developer Setup

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

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

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

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

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

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

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

### Rapid Iteration dev Environment

On occasion it is desirable to re-run the development environment at will quickly. To this
end you can run `make docker-refresh-dev` which will spin up the bat-go services including a
container named `grant-refresh-dev`. If you want to recompile this service you merely need to
perform a `docker restart grant-refresh-dev` and it will recompile and run the service.

A particularly interesting use case is marrying this with utilities such as `fswatch` to watch
for file changes. There is an example below which will restart this `grant-refresh-dev` container
on any file change in the source directory:

```bash
fswatch . | xargs -I {} sh -c '$(docker ps -f "name=grant-refresh-dev" --format "docker restart {{.ID}}")'
```

## Building a prod image using docker

You can build a docker image without installing the go toolchain. Ensure docker
Expand Down
4 changes: 2 additions & 2 deletions cmd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/throttled/throttled v2.2.5+incompatible // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
10 changes: 5 additions & 5 deletions cmd/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -378,7 +378,7 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -449,8 +449,8 @@ golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
Loading

0 comments on commit e2745c6

Please sign in to comment.