forked from armadaproject/armada
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
170 lines (139 loc) · 6.77 KB
/
makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# Determine which platform we're on based on the kernel name
platform := $(shell uname -s || echo unknown)
# Check that all necessary executables are present
# Using 'where' on Windows and 'which' on Unix-like systems, respectively
# We do not check for 'date', since it's a cmdlet on Windows, which do not show up with where
# (:= assignment is necessary to force immediate evaluation of expression)
EXECUTABLES = go git docker
ifeq ($(platform),windows32)
K := $(foreach exec,$(EXECUTABLES),$(if $(shell where $(exec)),some string,$(error "No $(exec) in PATH")))
else
K := $(foreach exec,$(EXECUTABLES),$(if $(shell which $(exec)),some string,$(error "No $(exec) in PATH")))
endif
# Get the current date and time (to insert into go build)
# On Windows, we need to use the powershell date command (alias of Get-Date) to get the full date-time string
ifeq ($(platform),unknown)
date := $(unknown)
else ifeq ($(platform),windows32)
date := $(shell powershell -c date || unknown)
else
date := $(shell date || unknown)
endif
BUILD_TIME = $(strip $(date)) # Strip leading/trailing whitespace (added by powershell)
# Get go version
# (using subst to change, e.g., 'go version go1.17.2 windows/amd64' to 'go1.17.2 windows/amd64')
GO_VERSION = $(strip $(subst go version,,$(shell go version)))
# Get most recent git commit (to insert into go build)
GIT_COMMIT := $(shell git rev-list --abbrev-commit -1 HEAD)
# The RELEASE_VERSION environment variable is set by circleci (to insert into go build and output filenames)
ifndef RELEASE_VERSION
override RELEASE_VERSION = UNKNOWN_VERSION
endif
# use bash for running:
export SHELL:=/bin/bash
export SHELLOPTS:=$(if $(SHELLOPTS),$(SHELLOPTS):)pipefail:errexit
gobuildlinux = GOOS=linux GARCH=amd64 CGO_ENABLED=0 go build -ldflags="-s -w"
gobuild = go build
build-server:
$(gobuild) -o ./bin/server cmd/armada/main.go
build-executor:
$(gobuild) -o ./bin/executor cmd/executor/main.go
build-fakeexecutor:
$(gobuild) -o ./bin/executor cmd/fakeexecutor/main.go
ARMADACTL_BUILD_PACKAGE := github.com/G-Research/armada/internal/armadactl/build
define ARMADACTL_LDFLAGS
-X '$(ARMADACTL_BUILD_PACKAGE).BuildTime=$(BUILD_TIME)' \
-X '$(ARMADACTL_BUILD_PACKAGE).ReleaseVersion=$(RELEASE_VERSION)' \
-X '$(ARMADACTL_BUILD_PACKAGE).GitCommit=$(GIT_COMMIT)' \
-X '$(ARMADACTL_BUILD_PACKAGE).GoVersion=$(GO_VERSION)'
endef
build-armadactl:
$(gobuild) -ldflags="$(ARMADACTL_LDFLAGS)" -o ./bin/armadactl cmd/armadactl/main.go
build-armadactl-multiplatform:
go install github.com/mitchellh/gox@v1.0.1
gox -ldflags="$(ARMADACTL_LDFLAGS)" -output="./bin/{{.OS}}-{{.Arch}}/armadactl" -arch="amd64" -os="windows linux darwin" ./cmd/armadactl/
build-armadactl-release: build-armadactl-multiplatform
mkdir ./dist || true
tar -czvf ./dist/armadactl-$(RELEASE_VERSION)-linux-amd64.tar.gz -C ./bin/linux-amd64/ armadactl
tar -czvf ./dist/armadactl-$(RELEASE_VERSION)-darwin-amd64.tar.gz -C ./bin/darwin-amd64/ armadactl
zip -j ./dist/armadactl-$(RELEASE_VERSION)-windows-amd64.zip ./bin/windows-amd64/armadactl.exe
build-binoculars:
$(gobuild) -o ./bin/binoculars cmd/binoculars/main.go
build-load-tester:
$(gobuild) -o ./bin/armada-load-tester cmd/armada-load-tester/main.go
build: build-server build-executor build-fakeexecutor build-armadactl build-load-tester build-binoculars
build-docker-server:
$(gobuildlinux) -o ./bin/linux/server cmd/armada/main.go
docker build $(dockerFlags) -t armada -f ./build/armada/Dockerfile .
build-docker-executor:
$(gobuildlinux) -o ./bin/linux/executor cmd/executor/main.go
docker build $(dockerFlags) -t armada-executor -f ./build/executor/Dockerfile .
build-docker-armada-load-tester:
$(gobuildlinux) -o ./bin/linux/armada-load-tester cmd/armada-load-tester/main.go
docker build $(dockerFlags) -t armada-load-tester -f ./build/armada-load-tester/Dockerfile .
build-docker-armadactl:
$(gobuildlinux) -o ./bin/linux/armadactl cmd/armadactl/main.go
docker build $(dockerFlags) -t armadactl -f ./build/armadactl/Dockerfile .
build-docker-fakeexecutor:
$(gobuildlinux) -o ./bin/linux/fakeexecutor cmd/fakeexecutor/main.go
docker build $(dockerFlags) -t armada-fakeexecutor -f ./build/fakeexecutor/Dockerfile .
build-docker-lookout:
(cd ./internal/lookout/ui/ && npm ci && npm run openapi && npm run build)
$(gobuildlinux) -o ./bin/linux/lookout cmd/lookout/main.go
docker build $(dockerFlags) -t armada-lookout -f ./build/lookout/Dockerfile .
build-docker-binoculars:
$(gobuildlinux) -o ./bin/linux/binoculars cmd/binoculars/main.go
docker build $(dockerFlags) -t armada-binoculars -f ./build/binoculars/Dockerfile .
build-docker: build-docker-server build-docker-executor build-docker-armadactl build-docker-armada-load-tester build-docker-fakeexecutor build-docker-lookout build-docker-binoculars
build-ci: gobuild=$(gobuildlinux)
build-ci: build-docker build-armadactl build-armadactl-multiplatform build-load-tester
.ONESHELL:
tests:
docker run -d --name=test-redis -p=6379:6379 redis
docker run -d --name=postgres -p 5432:5432 -e POSTGRES_PASSWORD=psw postgres
function tearDown {
docker stop test-redis postgres
docker rm test-redis postgres
}
trap tearDown EXIT
go test -v ./internal/...
go test -v ./pkg/...
go test -v ./cmd/...
e2e-start-cluster:
./e2e/setup/setup_cluster_ci.sh
./e2e/setup/setup_kube_config_ci.sh
KUBECONFIG=.kube/config kubectl apply -f ./e2e/setup/namespace-with-anonymous-user.yaml
docker run -d --name nats -p 4223:4223 -p 8223:8223 nats-streaming -p 4223 -m 8223
e2e-stop-cluster:
docker stop kube nats
docker rm kube nats
.ONESHELL:
tests-e2e: e2e-start-cluster build-docker
docker run -d --name redis -p=6379:6379 redis
docker run -d --name server --network=host -p=50051:50051 \
-v $(shell pwd)/e2e:/e2e \
armada ./server --config /e2e/setup/insecure-armada-auth-config.yaml --config /e2e/setup/nats/armada-config.yaml
docker run -d --name executor --network=host -v $(shell pwd)/.kube/config:/kube/config \
-e KUBECONFIG=/kube/config \
-e ARMADA_KUBERNETES_IMPERSONATEUSERS=true \
-e ARMADA_KUBERNETES_STUCKPODEXPIRY=15s \
armada-executor
function tearDown {
echo -e "\nexecutor logs:"
docker logs executor
echo -e "\nserver logs:"
docker logs server
docker stop executor server redis
docker rm executor server redis
}
trap tearDown EXIT
sleep 10
echo -e "\nrunning test:"
INTEGRATION_ENABLED=true PATH=${PATH}:${PWD}/bin go test -v ./e2e/test/... -count=1
proto:
docker build $(dockerFlags) -t armada-proto -f ./build/proto/Dockerfile .
docker run -it --rm -v $(shell pwd):/go/src/armada -w /go/src/armada armada-proto ./scripts/proto.sh
generate:
go run github.com/rakyll/statik \
-dest=internal/lookout/repository/schema/ -src=internal/lookout/repository/schema/ -include=\*.sql -ns=lookout/sql -Z -f -m
go run golang.org/x/tools/cmd/goimports -w -local "github.com/G-Research/armada" internal/lookout/repository/schema/statik