This repository has been archived by the owner on Dec 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 84
/
Makefile
176 lines (147 loc) · 5.78 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
171
172
173
174
175
176
VERSION := $(shell git describe --always)
GIT_SHA := $(shell git rev-parse HEAD)
GIT_SHORT_SHA := $(shell git rev-parse --short HEAD)
BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
BUILD_CONTEXT ?= .
GO_BUILD_LDFLAGS := -ldflags "-X github.com/skygeario/skygear-server/pkg/server/skyversion.version=$(VERSION)"
GO_TEST_TIMEOUT := 1m30s
GO_TEST_PACKAGE := ./pkg/core/... ./pkg/auth/... ./pkg/gateway/... ./pkg/asset/...
SHELL := /bin/bash
ifeq (1,${GO_TEST_VERBOSE})
GO_TEST_ARGS_VERBOSE := -v
endif
DOCKER_COMPOSE_CMD := docker-compose -f docker-compose.make.yml
ifeq (1,${WITH_DOCKER})
DOCKER_RUN := ${DOCKER_COMPOSE_CMD} run --rm app
endif
DOCKER_REGISTRY :=
DOCKER_ORG_NAME := skygeario
DOCKER_IMAGE_AUTH := skygear-auth
DOCKER_IMAGE_GATEWAY := skygear-gateway
DOCKER_IMAGE_ASSET := skygear-asset
DOCKER_IMAGE_MIGRATE := skygear-migrate
DOCKER_TAG := git-$(shell git rev-parse --short HEAD)
PUSH_DOCKER_TAG := $(VERSION)
IMAGE_NAME = $(DOCKER_REGISTRY)$(DOCKER_ORG_NAME)/$(1):$(DOCKER_TAG)
VERSIONED_IMAGE_NAME = $(DOCKER_REGISTRY)$(DOCKER_ORG_NAME)/$(1):$(PUSH_DOCKER_TAG)
AUTH_IMAGE_NAME = $(call IMAGE_NAME,$(DOCKER_IMAGE_AUTH))
AUTH_VERSIONED_IMAGE_NAME = $(call VERSIONED_IMAGE_NAME,$(DOCKER_IMAGE_AUTH))
GATEWAY_IMAGE_NAME = $(call IMAGE_NAME,$(DOCKER_IMAGE_GATEWAY))
GATEWAY_VERSIONED_IMAGE_NAME = $(call VERSIONED_IMAGE_NAME,$(DOCKER_IMAGE_GATEWAY))
ASSET_IMAGE_NAME = $(call IMAGE_NAME,$(DOCKER_IMAGE_ASSET))
ASSET_VERSIONED_IMAGE_NAME = $(call VERSIONED_IMAGE_NAME,$(DOCKER_IMAGE_ASSET))
MIGRATE_IMAGE_NAME = $(call IMAGE_NAME,$(DOCKER_IMAGE_MIGRATE))
MIGRATE_VERSIONED_IMAGE_NAME = $(call VERSIONED_IMAGE_NAME,$(DOCKER_IMAGE_MIGRATE))
GO_BUILD_ARGS := $(GO_BUILD_TAGS) $(GO_BUILD_LDFLAGS)
GO_TEST_ARGS := $(GO_BUILD_ARGS) -cover -timeout $(GO_TEST_TIMEOUT) $(GO_TEST_ARGS_VERBOSE)
.PHONY: vendor
vendor:
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $$(go env GOPATH)/bin v1.22.2
go mod download
go install golang.org/x/tools/cmd/stringer
go install golang.org/x/tools/cmd/cover
go install github.com/tinylib/msgp
go install github.com/mitchellh/gox
go install github.com/golang/mock/mockgen
go install tools/nextimportslint.go
go install github.com/google/wire/cmd/wire
go install github.com/skygeario/openapi3-gen/cmd/openapi3-gen
.PHONY: go-generate
go-generate:
$(DOCKER_RUN) go generate ./pkg/...
.PHONY: go-lint
go-lint:
$(DOCKER_RUN) golangci-lint run ./cmd/... ./pkg/...
$(DOCKER_RUN) nextimportslint
.PHONY: generate
generate: go-generate
.PHONY: tidy
tidy:
go mod tidy
.PHONY: test
test:
# Run `go install` to compile packages for caching and catch compilation error.
$(DOCKER_RUN) go install $(GO_BUILD_ARGS) ./cmd/...
$(DOCKER_RUN) go test $(GO_TEST_ARGS) $(GO_TEST_PACKAGE)
.PHONY: lint
lint: go-lint
.PHONY: fmt
fmt:
${DOCKER_RUN} gofmt -w cmd/**/main.go ./pkg
.PHONY: update-version
update-version:
sed -i "" "s/const MajorVersion = .*/const MajorVersion = $(shell echo $$SKYGEAR_VERSION | cut -d . -f 1)/" pkg/core/apiversion/apiversion.go
sed -i "" "s/const MinorVersion = .*/const MinorVersion = $(shell echo $$SKYGEAR_VERSION | cut -d . -f 2)/" pkg/core/apiversion/apiversion.go
.PHONY: docker-build-image
docker-build-image:
docker build \
-f $(DOCKER_FILE) \
-t $(IMAGE_NAME) \
--build-arg sha=$(GIT_SHA) \
--build-arg version=$(VERSION) \
--build-arg build_date=$(BUILD_DATE) \
$(BUILD_CONTEXT)
.PHONY: docker-build-auth
docker-build-auth:
$(MAKE) docker-build-image DOCKER_FILE=cmd/auth/Dockerfile IMAGE_NAME=$(AUTH_IMAGE_NAME)
.PHONY: docker-build-gateway
docker-build-gateway:
$(MAKE) docker-build-image DOCKER_FILE=cmd/gateway/Dockerfile IMAGE_NAME=$(GATEWAY_IMAGE_NAME)
.PHONY: docker-build-asset
docker-build-asset:
$(MAKE) docker-build-image DOCKER_FILE=cmd/asset/Dockerfile IMAGE_NAME=$(ASSET_IMAGE_NAME)
.PHONY: docker-build-migrate
docker-build-migrate:
$(MAKE) docker-build-image DOCKER_FILE=./migrate/cmd/migrate/Dockerfile IMAGE_NAME=$(MIGRATE_IMAGE_NAME) BUILD_CONTEXT=./migrate
.PHONY: docker-build
docker-build: docker-build-auth docker-build-gateway docker-build-migrate docker-build-asset
.PHONY: docker-push
docker-push:
docker push $(AUTH_IMAGE_NAME)
docker push $(GATEWAY_IMAGE_NAME)
docker push $(ASSET_IMAGE_NAME)
docker push $(MIGRATE_IMAGE_NAME)
.PHONY: docker-push-version
docker-push-version:
docker tag $(AUTH_IMAGE_NAME) $(AUTH_VERSIONED_IMAGE_NAME)
docker tag $(GATEWAY_IMAGE_NAME) $(GATEWAY_VERSIONED_IMAGE_NAME)
docker tag $(ASSET_IMAGE_NAME) $(ASSET_VERSIONED_IMAGE_NAME)
docker tag $(MIGRATE_IMAGE_NAME) $(MIGRATE_VERSIONED_IMAGE_NAME)
docker push $(AUTH_VERSIONED_IMAGE_NAME)
docker push $(GATEWAY_VERSIONED_IMAGE_NAME)
docker push $(ASSET_VERSIONED_IMAGE_NAME)
docker push $(MIGRATE_VERSIONED_IMAGE_NAME)
.PHONY: release-commit
release-commit:
./scripts/release-commit.sh
.PHONY: preview-doc-auth
preview-doc-auth:
./scripts/preview-doc.sh auth
.PHONY: preview-doc-asset
preview-doc-asset:
./scripts/preview-doc.sh asset
.PHONY: generate-doc-auth
generate-doc-auth:
@openapi3-gen -output "$(DOC_PATH)" ./cmd/auth/... ./pkg/auth/...
.PHONY: generate-doc-asset
generate-doc-asset:
@openapi3-gen -output "$(DOC_PATH)" ./cmd/asset/... ./pkg/asset/...
.PHONY: generate-static-asset
generate-static-asset:
cd ./scripts/deploy-asset; \
npm ci; \
rm -rf dist/; \
mkdir -p "dist/git-$(GIT_SHORT_SHA)"; \
cp -R ../../static/. "dist/git-$(GIT_SHORT_SHA)"; \
npx postcss \
'../../static/**/*.css' \
--base '../../static' \
--dir "dist/git-$(GIT_SHORT_SHA)" \
--config postcss.config.js
# Compile html email and print to stdout.
# You should capture the output and update the default template in Go code.
# For example,
# make html-email NAME=scripts/html-email/templates/forgot_password_email.mjml | pbcopy
.PHONY: html-email
html-email:
@./scripts/html-email/node_modules/.bin/mjml -l strict $(NAME)