2022-05-02 19:04:45 +00:00
|
|
|
.DEFAULT_GOAL := build
|
|
|
|
|
2022-06-18 19:47:10 +00:00
|
|
|
# Use a single bash shell for each job, and immediately exit on failure
|
|
|
|
SHELL := bash
|
|
|
|
.SHELLFLAGS = -ceu
|
|
|
|
.ONESHELL:
|
|
|
|
|
|
|
|
# This doesn't work on directories.
|
|
|
|
# See https://stackoverflow.com/questions/25752543/make-delete-on-error-for-directory-targets
|
|
|
|
.DELETE_ON_ERROR:
|
|
|
|
|
2022-02-11 04:32:00 +00:00
|
|
|
INSTALL_DIR=$(shell go env GOPATH)/bin
|
2022-02-28 17:16:44 +00:00
|
|
|
GOOS=$(shell go env GOOS)
|
|
|
|
GOARCH=$(shell go env GOARCH)
|
2022-06-18 19:47:10 +00:00
|
|
|
VERSION=$(shell ./scripts/version.sh)
|
2022-02-11 04:32:00 +00:00
|
|
|
|
2022-05-27 13:34:32 +00:00
|
|
|
bin: $(shell find . -not -path './vendor/*' -type f -name '*.go') go.mod go.sum $(shell find ./examples/templates)
|
2022-06-18 19:47:10 +00:00
|
|
|
@echo "== This builds slim binaries for command-line usage."
|
2022-05-02 19:04:45 +00:00
|
|
|
@echo "== Use \"make build\" to embed the site."
|
|
|
|
|
2022-06-18 19:47:10 +00:00
|
|
|
mkdir -p ./dist
|
|
|
|
rm -rf ./dist/coder-slim_*
|
2022-06-23 14:16:27 +00:00
|
|
|
rm -f ./site/out/bin/coder*
|
2022-06-18 19:47:10 +00:00
|
|
|
./scripts/build_go_slim.sh \
|
2022-06-23 14:16:27 +00:00
|
|
|
--compress 6 \
|
2022-06-18 19:47:10 +00:00
|
|
|
--version "$(VERSION)" \
|
|
|
|
--output ./dist/ \
|
|
|
|
linux:amd64,armv7,arm64 \
|
|
|
|
windows:amd64,arm64 \
|
|
|
|
darwin:amd64,arm64
|
|
|
|
.PHONY: bin
|
|
|
|
|
|
|
|
build: site/out/index.html $(shell find . -not -path './vendor/*' -type f -name '*.go') go.mod go.sum $(shell find ./examples/templates)
|
|
|
|
rm -rf ./dist
|
|
|
|
mkdir -p ./dist
|
2022-06-23 14:16:27 +00:00
|
|
|
rm -f ./site/out/bin/coder*
|
2022-06-18 19:47:10 +00:00
|
|
|
|
|
|
|
# build slim artifacts and copy them to the site output directory
|
|
|
|
./scripts/build_go_slim.sh \
|
|
|
|
--version "$(VERSION)" \
|
2022-06-21 16:53:36 +00:00
|
|
|
--compress 6 \
|
2022-06-18 19:47:10 +00:00
|
|
|
--output ./dist/ \
|
|
|
|
linux:amd64,armv7,arm64 \
|
|
|
|
windows:amd64,arm64 \
|
|
|
|
darwin:amd64,arm64
|
|
|
|
|
|
|
|
# build not-so-slim artifacts with the default name format
|
|
|
|
./scripts/build_go_matrix.sh \
|
|
|
|
--version "$(VERSION)" \
|
|
|
|
--output ./dist/ \
|
|
|
|
--archive \
|
|
|
|
--package-linux \
|
|
|
|
linux:amd64,armv7,arm64 \
|
|
|
|
windows:amd64,arm64 \
|
|
|
|
darwin:amd64,arm64
|
2022-01-18 21:13:19 +00:00
|
|
|
.PHONY: build
|
|
|
|
|
2022-01-05 15:20:56 +00:00
|
|
|
# Runs migrations to output a dump of the database.
|
2022-08-29 11:56:51 +00:00
|
|
|
coderd/database/dump.sql: coderd/database/gen/dump/main.go $(wildcard coderd/database/migrations/*.sql)
|
|
|
|
go run coderd/database/gen/dump/main.go
|
2022-01-05 15:20:56 +00:00
|
|
|
|
|
|
|
# Generates Go code for querying the database.
|
2022-08-29 11:56:51 +00:00
|
|
|
coderd/database/querier.go: coderd/database/sqlc.yaml coderd/database/dump.sql $(wildcard coderd/database/queries/*.sql) coderd/database/gen/enum/main.go
|
2022-04-01 20:45:23 +00:00
|
|
|
coderd/database/generate.sh
|
2022-01-05 15:20:56 +00:00
|
|
|
|
2022-01-04 02:54:27 +00:00
|
|
|
fmt/prettier:
|
|
|
|
@echo "--- prettier"
|
2022-06-18 19:47:10 +00:00
|
|
|
cd site
|
2022-01-04 02:54:27 +00:00
|
|
|
# Avoid writing files in CI to reduce file write activity
|
|
|
|
ifdef CI
|
2022-06-18 19:47:10 +00:00
|
|
|
yarn run format:check
|
2022-01-04 02:54:27 +00:00
|
|
|
else
|
2022-06-18 19:47:10 +00:00
|
|
|
yarn run format:write
|
2022-01-04 02:54:27 +00:00
|
|
|
endif
|
|
|
|
.PHONY: fmt/prettier
|
|
|
|
|
2022-04-11 21:06:15 +00:00
|
|
|
fmt/terraform: $(wildcard *.tf)
|
|
|
|
terraform fmt -recursive
|
2022-05-02 19:04:45 +00:00
|
|
|
.PHONY: fmt/terraform
|
2022-04-11 21:06:15 +00:00
|
|
|
|
2022-05-27 17:15:19 +00:00
|
|
|
fmt/shfmt: $(shell shfmt -f .)
|
|
|
|
@echo "--- shfmt"
|
|
|
|
# Only do diff check in CI, errors on diff.
|
|
|
|
ifdef CI
|
|
|
|
shfmt -d $(shell shfmt -f .)
|
|
|
|
else
|
|
|
|
shfmt -w $(shell shfmt -f .)
|
|
|
|
endif
|
2022-06-18 19:47:10 +00:00
|
|
|
.PHONY: fmt/shfmt
|
2022-05-27 17:15:19 +00:00
|
|
|
|
|
|
|
fmt: fmt/prettier fmt/terraform fmt/shfmt
|
2022-01-05 15:20:56 +00:00
|
|
|
.PHONY: fmt
|
2022-01-08 17:24:02 +00:00
|
|
|
|
2022-05-02 18:23:13 +00:00
|
|
|
gen: coderd/database/querier.go peerbroker/proto/peerbroker.pb.go provisionersdk/proto/provisioner.pb.go provisionerd/proto/provisionerd.pb.go site/src/api/typesGenerated.ts
|
2022-06-18 19:47:10 +00:00
|
|
|
.PHONY: gen
|
|
|
|
|
|
|
|
install: site/out/index.html $(shell find . -not -path './vendor/*' -type f -name '*.go') go.mod go.sum $(shell find ./examples/templates)
|
|
|
|
@output_file="$(INSTALL_DIR)/coder"
|
2022-01-08 17:24:02 +00:00
|
|
|
|
2022-06-18 19:47:10 +00:00
|
|
|
@if [[ "$(GOOS)" == "windows" ]]; then
|
|
|
|
@output_file="$${output_file}.exe"
|
|
|
|
@fi
|
|
|
|
|
|
|
|
@echo "-- Building CLI for $(GOOS) $(GOARCH) at $$output_file"
|
|
|
|
|
|
|
|
./scripts/build_go.sh \
|
|
|
|
--version "$(VERSION)" \
|
|
|
|
--output "$$output_file" \
|
|
|
|
--os "$(GOOS)" \
|
|
|
|
--arch "$(GOARCH)"
|
|
|
|
|
|
|
|
@echo
|
2022-02-11 04:32:00 +00:00
|
|
|
.PHONY: install
|
|
|
|
|
2022-05-27 17:15:19 +00:00
|
|
|
lint: lint/shellcheck lint/go
|
2022-06-18 19:47:10 +00:00
|
|
|
.PHONY: lint
|
2022-05-27 17:15:19 +00:00
|
|
|
|
|
|
|
lint/go:
|
2022-08-19 17:49:08 +00:00
|
|
|
./scripts/check_enterprise_imports.sh
|
2022-03-28 20:21:00 +00:00
|
|
|
golangci-lint run
|
2022-05-27 17:15:19 +00:00
|
|
|
.PHONY: lint/go
|
|
|
|
|
|
|
|
# Use shfmt to determine the shell files, takes editorconfig into consideration.
|
|
|
|
lint/shellcheck: $(shell shfmt -f .)
|
|
|
|
@echo "--- shellcheck"
|
2022-06-01 19:15:09 +00:00
|
|
|
shellcheck --external-sources $(shell shfmt -f .)
|
2022-06-18 19:47:10 +00:00
|
|
|
.PHONY: lint/shellcheck
|
2022-03-28 20:21:00 +00:00
|
|
|
|
2022-05-02 18:23:13 +00:00
|
|
|
peerbroker/proto/peerbroker.pb.go: peerbroker/proto/peerbroker.proto
|
2022-01-29 23:52:14 +00:00
|
|
|
protoc \
|
2022-01-11 15:28:41 +00:00
|
|
|
--go_out=. \
|
|
|
|
--go_opt=paths=source_relative \
|
|
|
|
--go-drpc_out=. \
|
|
|
|
--go-drpc_opt=paths=source_relative \
|
2022-01-29 23:52:14 +00:00
|
|
|
./peerbroker/proto/peerbroker.proto
|
2022-01-11 15:28:41 +00:00
|
|
|
|
2022-05-02 18:23:13 +00:00
|
|
|
provisionerd/proto/provisionerd.pb.go: provisionerd/proto/provisionerd.proto
|
2022-01-29 23:52:14 +00:00
|
|
|
protoc \
|
|
|
|
--go_out=. \
|
|
|
|
--go_opt=paths=source_relative \
|
|
|
|
--go-drpc_out=. \
|
|
|
|
--go-drpc_opt=paths=source_relative \
|
|
|
|
./provisionerd/proto/provisionerd.proto
|
|
|
|
|
2022-05-02 18:23:13 +00:00
|
|
|
provisionersdk/proto/provisioner.pb.go: provisionersdk/proto/provisioner.proto
|
2022-01-29 23:52:14 +00:00
|
|
|
protoc \
|
2022-01-08 17:24:02 +00:00
|
|
|
--go_out=. \
|
|
|
|
--go_opt=paths=source_relative \
|
|
|
|
--go-drpc_out=. \
|
|
|
|
--go-drpc_opt=paths=source_relative \
|
2022-01-29 23:52:14 +00:00
|
|
|
./provisionersdk/proto/provisioner.proto
|
2022-01-18 21:13:19 +00:00
|
|
|
|
2022-05-04 14:47:48 +00:00
|
|
|
site/out/index.html: $(shell find ./site -not -path './site/node_modules/*' -type f -name '*.tsx') $(shell find ./site -not -path './site/node_modules/*' -type f -name '*.ts') site/package.json
|
2022-02-20 19:52:14 +00:00
|
|
|
./scripts/yarn_install.sh
|
2022-06-18 19:47:10 +00:00
|
|
|
cd site
|
|
|
|
yarn typegen
|
|
|
|
yarn build
|
2022-03-08 01:50:37 +00:00
|
|
|
# Restores GITKEEP files!
|
2022-06-18 19:47:10 +00:00
|
|
|
git checkout HEAD out
|
2022-05-02 18:23:13 +00:00
|
|
|
|
2022-05-10 07:44:09 +00:00
|
|
|
site/src/api/typesGenerated.ts: scripts/apitypings/main.go $(shell find codersdk -type f -name '*.go')
|
2022-05-02 18:23:13 +00:00
|
|
|
go run scripts/apitypings/main.go > site/src/api/typesGenerated.ts
|
2022-06-18 19:47:10 +00:00
|
|
|
cd site
|
|
|
|
yarn run format:types
|
2022-03-28 19:14:40 +00:00
|
|
|
|
2022-05-20 23:39:51 +00:00
|
|
|
test: test-clean
|
2022-03-28 20:21:00 +00:00
|
|
|
gotestsum -- -v -short ./...
|
2022-06-18 19:47:10 +00:00
|
|
|
.PHONY: test
|
2022-05-20 23:39:51 +00:00
|
|
|
|
2022-07-22 09:47:03 +00:00
|
|
|
# When updating -timeout for this test, keep in sync with
|
|
|
|
# test-go-postgres (.github/workflows/coder.yaml).
|
2022-06-27 17:07:39 +00:00
|
|
|
test-postgres: test-clean test-postgres-docker
|
2022-06-28 21:42:19 +00:00
|
|
|
DB=ci DB_FROM=$(shell go run scripts/migrate-ci/main.go) gotestsum --junitfile="gotests.xml" --packages="./..." -- \
|
2022-07-22 09:47:03 +00:00
|
|
|
-covermode=atomic -coverprofile="gotests.coverage" -timeout=20m \
|
2022-07-25 16:55:19 +00:00
|
|
|
-coverpkg=./... \
|
2022-07-08 04:14:35 +00:00
|
|
|
-count=1 -race -failfast
|
2022-06-18 19:47:10 +00:00
|
|
|
.PHONY: test-postgres
|
2022-05-20 23:39:51 +00:00
|
|
|
|
|
|
|
test-postgres-docker:
|
2022-06-27 17:07:39 +00:00
|
|
|
docker rm -f test-postgres-docker || true
|
2022-05-20 23:39:51 +00:00
|
|
|
docker run \
|
|
|
|
--env POSTGRES_PASSWORD=postgres \
|
|
|
|
--env POSTGRES_USER=postgres \
|
|
|
|
--env POSTGRES_DB=postgres \
|
|
|
|
--env PGDATA=/tmp \
|
2022-06-17 19:57:38 +00:00
|
|
|
--tmpfs /tmp \
|
2022-05-20 23:39:51 +00:00
|
|
|
--publish 5432:5432 \
|
|
|
|
--name test-postgres-docker \
|
2022-06-17 19:57:38 +00:00
|
|
|
--restart no \
|
2022-05-20 23:39:51 +00:00
|
|
|
--detach \
|
2022-06-27 17:07:39 +00:00
|
|
|
postgres:13 \
|
2022-05-20 23:39:51 +00:00
|
|
|
-c shared_buffers=1GB \
|
2022-06-17 19:57:38 +00:00
|
|
|
-c max_connections=1000 \
|
|
|
|
-c fsync=off \
|
|
|
|
-c synchronous_commit=off \
|
|
|
|
-c full_page_writes=off
|
2022-06-27 17:07:39 +00:00
|
|
|
while ! pg_isready -h 127.0.0.1
|
|
|
|
do
|
|
|
|
echo "$(date) - waiting for database to start"
|
|
|
|
sleep 0.5
|
|
|
|
done
|
2022-06-18 19:47:10 +00:00
|
|
|
.PHONY: test-postgres-docker
|
2022-05-20 23:39:51 +00:00
|
|
|
|
|
|
|
test-clean:
|
|
|
|
go clean -testcache
|
2022-06-18 19:47:10 +00:00
|
|
|
.PHONY: test-clean
|