Skip to content

Commit 9d0c4b3

Browse files
cstocktonChris Stockton
andauthored
feat: improve parallelization in github workflows and Makefile (#2436)
The primary goals of this PR are: * Better parallelization for github workflows and local builds * Allow easily running the github workflows locally Changes: * Makefile now describes dependencies among targets to enable parallel jobs * Created `release` target to be called from the release workflow * Creates temporary build folders to isolate symlinks * Created `release-test` target to be called form the test workflow * Makefile now has a release target which will concurrently build all 4 archives * Added -j flag to Makefile so it may create multiple jobs * This should leverage all cpus 4 cpu machines we will build on * I've made the arch explicit (GOOS=amd64) for x86 binary for safety * For now I've preserved the existing targets for "make build" and "make build-strip", but ideally: * `make build` only builds using `CGO_ENABLED=0 go build` giving native arch for local dev. * `make release` builds all the release binaries, without any env defined values such as `CGO_ENABLED=0 go build` (it is currently doing this now) * I've collapsed the test workflows into one step so they can run concurrently One note is that the go tool chain does make use of multiple cpus. But there should still be measurable benefits on 4 cpu machines with these changes. Related: #2429 --------- Co-authored-by: Chris Stockton <chris.stockton@supabase.io>
1 parent f3425cf commit 9d0c4b3

3 files changed

Lines changed: 80 additions & 48 deletions

File tree

.github/workflows/release.yml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,8 @@ jobs:
9999
run: |
100100
set -ex
101101
102-
RELEASE_VERSION=$RELEASE_VERSION make deps
103-
RELEASE_VERSION=$RELEASE_VERSION make build build-strip
104-
105-
ln -s auth gotrue
106-
tar -czvf auth-v$RELEASE_VERSION-x86.tar.gz auth gotrue migrations/
107-
mv auth-arm64 auth
108-
tar -czvf auth-v$RELEASE_VERSION-arm64.tar.gz auth gotrue migrations/
109-
110-
mv auth-darwin-arm64 auth
111-
tar -czvf auth-v$RELEASE_VERSION-darwin-arm64.tar.gz auth gotrue migrations/
112-
113-
mv auth-arm64-strip auth
114-
tar -cf - auth gotrue migrations/ | xz -T0 -9e -C crc64 > auth-v$RELEASE_VERSION-arm64.tar.xz
102+
MAKE_JOBS="$(nproc 2>/dev/null || echo 4)"
103+
RELEASE_VERSION=$RELEASE_VERSION make -j"$MAKE_JOBS" release
115104
116105
- name: Generate checksums
117106
if: ${{ steps.release.outputs.release_created == 'true' || steps.release.outputs.prs_created == 'true' }}

.github/workflows/test.yml

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,17 @@ jobs:
4242
then
4343
echo 'Make sure to run "gofmt -s -w ." before commit!' && exit 1
4444
fi
45-
- name: Check go vet
46-
run: |
47-
set -x
48-
go vet ./...
49-
- name: Run static check
50-
run: |
51-
set -x
52-
make static
53-
- name: Check gosec
54-
run: |
55-
set -x
56-
make sec
57-
- name: Run govulncheck
58-
run: |
59-
set -x
60-
make vulncheck
6145
- name: Init Database
6246
run: psql -f hack/init_postgres.sql postgresql://postgres:root@localhost:5432/postgres
6347
- name: Run migrations
6448
run: make migrate_dev
65-
- name: Lint and test
66-
run: make test
49+
- name: Run linters and tests
50+
run: |
51+
set -x
52+
53+
MAKE_JOBS="$(nproc 2>/dev/null || echo 4)"
54+
make -j"$MAKE_JOBS" release-test
55+
6756
- name: Cleanup coverage
6857
run: |
6958
set -x

Makefile

Lines changed: 71 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,98 @@
1-
.PHONY: all build deps image migrate test vet sec vulncheck format unused
1+
.PHONY: all build deps image migrate test vet sec vulncheck format unused release
22
.PHONY: check-gosec check-govulncheck check-oapi-codegen check-staticcheck
3-
CHECK_FILES?=./...
3+
CHECK_FILES ?= ./...
44

55
ifdef RELEASE_VERSION
66
VERSION=v$(RELEASE_VERSION)
77
else
88
VERSION=$(shell git describe --tags)
99
endif
1010

11-
FLAGS=-ldflags "-X github.com/supabase/auth/internal/utilities.Version=$(VERSION)" -buildvcs=false
12-
1311
ifneq ($(shell docker compose version 2>/dev/null),)
14-
DOCKER_COMPOSE=docker compose
12+
DOCKER_COMPOSE = docker compose
1513
else
16-
DOCKER_COMPOSE=docker-compose
14+
DOCKER_COMPOSE = docker-compose
1715
endif
1816

19-
DEV_DOCKER_COMPOSE:=docker-compose-dev.yml
17+
DEV_DOCKER_COMPOSE = docker-compose-dev.yml
18+
19+
BUILD_VERSION_PKG = github.com/supabase/auth/internal/utilities
20+
BUILD_LD_FLAGS = -X $(BUILD_VERSION_PKG).Version=$(VERSION)
21+
BUILD_CMD = go build \
22+
-o $(1) \
23+
-buildvcs=false \
24+
-ldflags "$(BUILD_LD_FLAGS)$(2)"
25+
26+
RELEASE_TARGETS = x86 arm64 darwin-arm64 arm64-strip
27+
RELEASE_ARCHIVES = \
28+
auth-$(VERSION)-x86.tar.gz \
29+
auth-$(VERSION)-arm64.tar.gz \
30+
auth-$(VERSION)-darwin-arm64.tar.gz \
31+
auth-$(VERSION)-arm64.tar.xz
32+
2033

2134
help: ## Show this help.
2235
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
2336

2437
all: vet sec static build ## Run the tests and build the binary.
2538

26-
build: deps ## Build the binary.
27-
CGO_ENABLED=0 go build $(FLAGS)
28-
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build $(FLAGS) -o auth-arm64
29-
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build $(FLAGS) -o auth-darwin-arm64
39+
build: auth auth-arm64 auth-darwin-arm64 ## Build the binaries.
40+
41+
build-strip: auth-arm64-strip ## Build a stripped binary, for which the version file needs to be rewritten.
42+
43+
auth: deps
44+
CGO_ENABLED=0 $(call BUILD_CMD,$(@),)
45+
46+
auth-x86: deps
47+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(call BUILD_CMD,$(@),)
48+
49+
auth-arm64: deps
50+
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(call BUILD_CMD,$(@),)
3051

31-
build-strip: deps ## Build a stripped binary, for which the version file needs to be rewritten.
32-
echo "package utilities" > internal/utilities/version.go
33-
echo "const Version = \"$(VERSION)\"" >> internal/utilities/version.go
52+
auth-darwin-arm64: deps
53+
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(call BUILD_CMD,$(@),)
3454

35-
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build \
36-
$(FLAGS) -ldflags "-s -w" -o auth-arm64-strip
55+
auth-arm64-strip: deps
56+
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(call BUILD_CMD,$(@), -s)
3757

3858
deps: ## Install dependencies.
3959
@go mod download
4060
@go mod verify
4161

62+
release-test: \
63+
vet \
64+
static \
65+
sec \
66+
vulncheck \
67+
test
68+
69+
release: $(RELEASE_ARCHIVES)
70+
71+
auth-$(VERSION)-%.tar.gz: \
72+
release-%/auth \
73+
release-%/gotrue | migrations
74+
tar -C $(<D) -czvf $(@) auth gotrue -C ../ migrations/
75+
76+
auth-$(VERSION)-arm64.tar.xz: \
77+
release-arm64-strip/auth \
78+
release-arm64-strip/gotrue | migrations
79+
tar -C $(<D) -cf - auth gotrue -C ../ migrations/ \
80+
| xz -T0 -9e -C crc64 > $(@)
81+
82+
release-%/auth: auth-%
83+
mkdir -p $(@D)
84+
cp -a $(<) $(@)
85+
86+
release-%/gotrue: release-%/auth
87+
ln -sf $(<F) $(@)
88+
4289
migrate_dev: ## Run database migrations for development.
4390
hack/migrate.sh postgres
4491

4592
migrate_test: ## Run database migrations for test.
4693
hack/migrate.sh postgres
4794

48-
test: build ## Run tests.
95+
test: auth ## Run tests.
4996
go test $(CHECK_FILES) -coverprofile=coverage.out -coverpkg ./... -p 1 -race -v -count=1
5097
./hack/coverage.sh
5198

@@ -112,3 +159,10 @@ docker-clean: ## Remove the development containers and volumes
112159

113160
format:
114161
gofmt -s -w .
162+
163+
clean:
164+
rm -rf \
165+
$(addprefix release-,$(RELEASE_TARGETS)) \
166+
$(addprefix auth-,$(RELEASE_TARGETS)) \
167+
$(RELEASE_ARCHIVES) \
168+
auth

0 commit comments

Comments
 (0)