Skip to content
This repository was archived by the owner on Oct 31, 2021. It is now read-only.

Commit 5f24f8a

Browse files
committed
Chart improvements and makefile optimizations.
1 parent 43200e3 commit 5f24f8a

11 files changed

+183
-141
lines changed

Chart.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 0.0.0
18+
version: "2021.9.0"
1919

2020
# This is the version number of the application being deployed. This version number should be
2121
# incremented each time you make changes to the application. Versions are not expected to

Makefile

+48-37
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ BUILD_TIME=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
77
RELEASE_REVISION=$(shell git rev-parse HEAD)
88
MONETR_CLI_PACKAGE = github.com/monetr/rest-api/pkg/cmd
99
COVERAGE_TXT = $(PWD)/coverage.txt
10-
LICENSE=$(LOCAL_BIN)/golicense
10+
11+
ifndef ENVIRONMENT
12+
ENVIRONMENT = Staging
13+
endif
14+
15+
ENV_LOWER = $(shell echo $(ENVIRONMENT) | tr A-Z a-z)
1116

1217
PATH+=\b:$(GOPATH)/bin:$(LOCAL_BIN):$(NODE_MODULES_BIN)
1318

@@ -33,18 +38,26 @@ define warningMsg
3338
@echo "\033[1;33m[$@] $(1)\033[0m"
3439
endef
3540

41+
GO_SRC_DIR=$(PWD)/pkg
42+
ALL_GO_FILES=$(wildcard $(GO_SRC_DIR)/**/*.go)
43+
APP_GO_FILES=$(filter-out $(GO_SRC_DIR)/**/*_test.go, $(ALL_GO_FILES))
44+
TEST_GO_FILES=$(wildcard $(GO_SRC_DIR)/**/*_test.go)
45+
46+
GO_DEPS=go.mod go.sum
3647

37-
default: build test
48+
include $(PWD)/scripts/*.mk
3849

39-
dependencies: go.mod go.sum
50+
default: build
51+
52+
dependencies: $(GO_DEPS)
4053
$(call infoMsg,Installing dependencies for monetrs rest-api)
4154
go get ./...
4255

43-
build: dependencies $(wildcard $(PWD)/pkg/**/*.go)
56+
build: dependencies $(APP_GO_FILES)
4457
$(call infoMsg,Building rest-api binary)
4558
go build -o $(LOCAL_BIN)/monetr $(MONETR_CLI_PACKAGE)
4659

47-
test:
60+
test: dependencies $(ALL_GO_FILES)
4861
$(call infoMsg,Running go tests for monetr rest-api)
4962
ifndef CI
5063
go run $(MONETR_CLI_PACKAGE) database migrate -d $(POSTGRES_DB) -U $(POSTGRES_USER) -H $(POSTGRES_HOST)
@@ -53,57 +66,55 @@ endif
5366
go tool cover -func=$(COVERAGE_TXT)
5467

5568
clean:
56-
echo $$PATH
57-
rm -rf $(LOCAL_BIN) || true
58-
rm -rf $(COVERAGE_TXT) || true
59-
rm -rf $(NODE_MODULES_DIR) || true
60-
rm -rf $(VENDOR_DIR) || true
61-
rm -rf $(LOCAL_TMP) || true
62-
63-
.PHONY: docs
64-
docs:
65-
swag init -d pkg/controller -g controller.go --parseDependency --parseDepth 5 --parseInternal
69+
-rm -rf $(LOCAL_BIN)
70+
-rm -rf $(COVERAGE_TXT)
71+
-rm -rf $(NODE_MODULES_DIR)
72+
-rm -rf $(VENDOR_DIR)
73+
-rm -rf $(LOCAL_TMP)
74+
75+
docs: $(SWAG) $(APP_GO_FILES)
76+
$(SWAG) init -d $(GO_SRC_DIR)/controller -g controller.go \
77+
--parseDependency \
78+
--parseDepth 5 \
79+
--parseInternal \
80+
--output $(PWD)/docs
6681

6782
docs-local: docs
6883
redoc-cli serve $(PWD)/docs/swagger.yaml
6984

70-
docker:
85+
docker: Dockerfile $(APP_GO_FILES)
7186
docker build \
7287
--build-arg REVISION=$(RELEASE_REVISION) \
7388
--build-arg BUILD_TIME=$(BUILD_TIME) \
74-
-t harder-rest-api -f Dockerfile .
89+
-t monetr-rest-api -f Dockerfile .
7590

7691
docker-work-web-ui:
7792
docker build -t workwebui -f Dockerfile.work .
7893

79-
$(LOCAL_BIN):
80-
mkdir $(LOCAL_BIN)
81-
82-
$(LOCAL_TMP):
83-
mkdir $(LOCAL_TMP)
84-
85-
$(LICENSE):
86-
@if [ ! -f "$(LICENSE)" ]; then make install-$(LICENSE); fi
87-
88-
LICENSE_REPO=https://github.com/mitchellh/golicense.git
89-
LICENSE_TMP=$(LOCAL_TMP)/golicense
90-
install-$(LICENSE): $(LOCAL_BIN) $(LOCAL_TMP)
91-
$(call infoMsg,Installing golicense to $(LICENSE))
92-
rm -rf $(LICENSE_TMP) || true
93-
git clone $(LICENSE_REPO) $(LICENSE_TMP)
94-
cd $(LICENSE_TMP) && go build -o $(LICENSE) .
95-
rm -rf $(LICENSE_TMP) || true
96-
97-
.PHONY: license
9894
ifdef GITHUB_TOKEN
9995
license: $(LICENSE) build
10096
$(call infoMsg,Checking dependencies for open source licenses)
101-
- $(LICENSE) $(PWD)/licenses.hcl $(LOCAL_BIN)/monetr
97+
-$(LICENSE) $(PWD)/licenses.hcl $(LOCAL_BIN)/monetr
10298
else
99+
.PHONY: license
103100
license:
104101
$(call warningMsg,GITHUB_TOKEN is required to check licenses)
105102
endif
106103

104+
generate: OUTPUT_DIR = $(PWD)/generated/$(ENV_LOWER)
105+
generate: IMAGE_TAG=$(shell git rev-parse HEAD)
106+
generate: VALUES_FILE=$(PWD)/values.$(ENV_LOWER).yaml
107+
generate: $(HELM) $(SPLIT_YAML)
108+
$(call infoMsg,Generating Kubernetes yaml using Helm output to: $(OUTPUT_DIR))
109+
$(call infoMsg,Environment: $(ENVIRONMENT))
110+
$(call infoMsg,Using values file: $(VALUES_FILE))
111+
$(HELM) template rest-api ./ \
112+
--dry-run \
113+
--set image.tag="$(IMAGE_TAG)" \
114+
--set podAnnotations."monetr\.dev/date"="$(shell date)" \
115+
--set podAnnotations."monetr\.dev/sha"="$(IMAGE_TAG)" \
116+
--values=values.$(ENV_LOWER).yaml | $(SPLIT_YAML) --outdir $(OUTPUT_DIR) -
117+
107118
ifdef GITLAB_CI
108119
include Makefile.gitlab-ci
109120
include Makefile.deploy

Makefile.deploy

+1-62
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,7 @@
1-
LOCAL_TMP = $(PWD)/tmp
2-
LOCAL_BIN = $(PWD)/bin
3-
PATH:=$(PATH):$(LOCAL_BIN)
4-
HELM_VERSION = 3.5.4
5-
ARCH = amd64
6-
OS = $(shell uname -s | tr A-Z a-z)
7-
8-
ifndef ENVIRONMENT
9-
ENVIRONMENT = Staging
10-
endif
11-
12-
ENV_LOWER = $(shell echo $(ENVIRONMENT) | tr A-Z a-z)
13-
141
default-deploy:
152
echo "Please run a specific target."
163

17-
clean-deploy:
18-
rm -rf $(LOCAL_BIN) || true
19-
rm -rf $(LOCAL_TMP) || true
20-
21-
SPLIT_YAML = kubernetes-split-yaml
22-
HELM = helm
23-
dependencies-maybe:
24-
which $(SPLIT_YAML) || make dependencies-split-yaml
25-
which $(HELM) || make dependencies-helm
26-
rm -rf $(LOCAL_TMP) || true
27-
28-
directories-maybe:
29-
mkdir -p $(LOCAL_TMP)
30-
mkdir -p $(LOCAL_BIN)
31-
32-
SPLIT_YAML_REPO = https://github.com/mogensen/kubernetes-split-yaml.git
33-
dependencies-split-yaml: directories-maybe
34-
$(eval SPLIT_YAML_DIR := "$(LOCAL_TMP)/$(SPLIT_YAML)")
35-
rm -rfd $(SPLIT_YAML_DIR) || true
36-
git clone $(SPLIT_YAML_REPO) $(SPLIT_YAML_DIR)
37-
cd $(SPLIT_YAML_DIR) && go build ./...
38-
cp $(SPLIT_YAML_DIR)/$(SPLIT_YAML) $(LOCAL_BIN)/$(SPLIT_YAML)
39-
rm -rfd $(SPLIT_YAML_DIR)
40-
41-
HELM_DIR = $(LOCAL_TMP)/$(HELM)
42-
HELM_TAR = $(HELM_DIR)/$(HELM).tar.gz
43-
HELM_URL = "https://get.helm.sh/helm-v$(HELM_VERSION)-$(OS)-$(ARCH).tar.gz"
44-
HELM_BIN_DIR = $(OS)-$(ARCH)
45-
dependencies-helm: directories-maybe
46-
rm -rf $(HELM_DIR) || true
47-
mkdir -p $(HELM_DIR)
48-
curl -SsL $(HELM_URL) --output $(HELM_TAR)
49-
tar -xzf $(HELM_TAR) -C $(HELM_DIR)
50-
cp $(HELM_DIR)/$(HELM_BIN_DIR)/$(HELM) $(LOCAL_BIN)/$(HELM)
51-
rm -rf $(HELM_DIR)
52-
53-
ENVIRONMENT_DIR = $(PWD)/generated/$(ENV_LOWER)
54-
IMAGE_TAG = $(shell git rev-parse HEAD)
55-
generate: dependencies-maybe
56-
$(eval REPO_SHA = $(shell git rev-parse HEAD))
57-
$(eval REPO_NAME = $(shell git config --get remote.origin.url))
58-
helm template rest-api ./ \
59-
--dry-run \
60-
--set image.tag="$(IMAGE_TAG)" \
61-
--set podAnnotations."monetr\.dev/date"="$(shell date)" \
62-
--set podAnnotations."monetr\.dev/sha"="$(REPO_SHA)" \
63-
--values=values.$(ENV_LOWER).yaml | kubernetes-split-yaml \
64-
--outdir $(ENVIRONMENT_DIR) -
65-
4+
ENVIRONMENT_DIR=$(PWD)/generated/$(ENV_LOWER)
665
NAMESPACE = monetr-$(ENV_LOWER)
676
dry:
687
kubectl apply -f $(ENVIRONMENT_DIR) -n $(NAMESPACE) --dry-run=server

Makefile.local

+3-39
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@ ARCH = amd64
55
OS = $(shell uname -s | tr A-Z a-z)
66

77
# Tools used to run the application locally
8-
HELM=helm
9-
HOSTESS=$(LOCAL_BIN)/hostess
108
JQ=$(LOCAL_BIN)/jq
119
KUBECTL=minikube kubectl --
12-
SPLIT_YAML=kubernetes-split-yaml
1310
YQ=$(LOCAL_BIN)/yq
1411
VAULT=vault
15-
MKCERT=mkcert
1612
PGO=$(LOCAL_BIN)/pgo
1713

1814
# This is the domain that is used for local development. You can change it to anything you want here and run init-mini
@@ -50,7 +46,7 @@ clean-mini: stop-mini clean-certificates
5046
rm -rf $(LOCAL_TMP) || true
5147
rm -rf $(LOCAL_BIN) || true
5248

53-
init-mini: info local-dependencies-maybe
49+
init-mini: info
5450
$(call infoMsg,Setting stuff up)
5551
$(MAKE) setup-certificates
5652
(minikube status | grep "minikube start") && $(MAKE) start-minikube
@@ -108,7 +104,7 @@ clean-certificates:
108104

109105
NGINX_DEPLOYMENT=ingress-nginx-controller
110106
TLS_SECRET_NAME=monetr-tls
111-
setup-certificates: $(LOCAL_DIR)
107+
setup-certificates: $(LOCAL_DIR) $(MKCERT)
112108
mkdir -p $(LOCAL_CERTS)
113109
$(MKCERT) -install
114110
$(MKCERT) -key-file $(KEY_PATH) -cert-file $(CERT_PATH) $(LOCAL_DOMAIN) *.$(LOCAL_DOMAIN)
@@ -186,32 +182,13 @@ pg-tls-values: $(YQ)
186182
$(YQ) e '.api.customEnv[0].valueFrom.secretKeyRef.key = "password"' -i $(VALUES)
187183
$(YQ) e '.api.customEnv[0].valueFrom.secretKeyRef.name = "postgres-postgres-secret"' -i $(VALUES)
188184

189-
local-dependencies-maybe:
190-
$(call infoMsg,Getting any dependencies needed to run everything locally)
191-
which minikube || $(MAKE) dependencies-minikube
192-
which $(HELM) || $(MAKE) dependencies-helm
193-
which $(SPLIT_YAML) || $(MAKE) dependencies-split-yaml
194-
which $(MKCERT) || $(MAKE) dependencies-mkcert
195-
196185
MINIKUBE_VERSION=latest
197186
dependencies-minikube:
198187
rm -rf $(PWD)/minikube-$(OS)-$(ARCH) || true
199188
curl -LO https://storage.googleapis.com/minikube/releases/$(MINIKUBE_VERSION)/minikube-$(OS)-$(ARCH)
200189
sudo install minikube-$(OS)-$(ARCH) $(LOCAL_BIN)/minikube
201190
rm -rf $(PWD)/minikube-$(OS)-$(ARCH)
202191

203-
HOSTESS_REPO=https://github.com/cbednarski/hostess
204-
$(HOSTESS):
205-
@if [ ! -f "$(HOSTESS)" ]; then make install-$(HOSTESS); fi
206-
207-
HOSTESS_DIR=$(LOCAL_TMP)/hostess
208-
install-$(HOSTESS): $(LOCAL_BIN) $(LOCAL_TMP)
209-
$(call infoMsg,Installing hostess to $(HOSTESS))
210-
rm -rf $(HOSTESS_DIR) || true
211-
git clone $(HOSTESS_REPO) $(HOSTESS_DIR)
212-
cd $(HOSTESS_DIR) && go build -o $(HOSTESS) .
213-
rm -rf $(HOSTESS_DIR)
214-
215192
ifeq ($(OS),darwin)
216193
JQ_OS=osx
217194
else
@@ -246,17 +223,6 @@ install-$(YQ): $(LOCAL_BIN) $(LOCAL_TMP)
246223
mv $(YQ_DIR)/yq_$(OS)_$(ARCH) $(YQ)
247224
rm -rf $(YQ_DIR) || true
248225

249-
250-
MKCERT_REPO=https://github.com/FiloSottile/mkcert
251-
MKCERT_DIR=$(LOCAL_TMP)/$(MKCERT)
252-
dependencies-mkcert: $(LOCAL_TMP) $(LOCAL_BIN)
253-
$(call infoMsg,Installing $(MKCERT) to $(LOCAL_BIN)/$(MKCERT))
254-
rm -rf $(MKCERT_DIR) || true
255-
git clone https://github.com/FiloSottile/mkcert $(MKCERT_DIR)
256-
cd $(MKCERT_DIR) && go build -ldflags "-X main.Version=$$(git describe --tags)"
257-
cp $(MKCERT_DIR)/$(MKCERT) $(LOCAL_BIN)/$(MKCERT)
258-
rm -rf $(MKCERT_DIR) || true
259-
260226
update-coredns:
261227
$(call infoMsg,Updating CoreDNS config)
262228
$(KUBECTL) apply -f $(PWD)/minikube/coredns-config.yaml --namespace=kube-system
@@ -334,8 +300,6 @@ shell:
334300
--rm -ti --image=$(SHELL_IMAGE) \
335301
-n $(MINIKUBE_NAMESPACE) --
336302

337-
values-file: local-dependencies-maybe $(VALUES)
338-
339303
$(LOCAL_REST_API_DEPLOY):
340304
mkdir -p $(LOCAL_REST_API_DEPLOY)
341305

@@ -356,7 +320,7 @@ build-rest-api-mini: wait-for-docker $(YQ)
356320
docker push $(BASE_IMAGE_NAME):latest
357321
$(YQ) e '.image.tag = "$(GO_HASH)"' -i $(VALUES)
358322

359-
deploy-mini-application: $(VALUES) $(LOCAL_REST_API_DEPLOY) build-rest-api-mini $(YQ)
323+
deploy-mini-application: $(HELM) $(VALUES) $(LOCAL_REST_API_DEPLOY) build-rest-api-mini $(YQ)
360324
$(eval CONFIG_HASH = $(shell md5 -q $(VALUES)))
361325
CONFIG_HASH=$(CONFIG_HASH) $(YQ) e '.podAnnotations.configHash = strenv(CONFIG_HASH)' -i $(VALUES)
362326
$(HELM) template $(REST_API_IMAGE_NAME) $(PWD) \

pkg/controller/controller.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ func NewController(
113113

114114
// @contact.name Support
115115
// @contact.url http://github.com/monetr/rest-api
116-
117116
// @license.name Business Source License 1.1
118117
// @license.url https://github.com/monetr/rest-api/blob/main/LICENSE
119-
120118
// @host api.monetr.app
121119

120+
121+
122122
// @tag.name Funding Schedules
123123
// @tag.description Funding Schedules are created by the user to tell us when money should be taken from their account to fund their goals and expenses.
124124

0 commit comments

Comments
 (0)