-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
128 lines (104 loc) · 4.18 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
# Configuration
# -------------
APP_NAME ?= `grep 'app:' mix.exs | sed -e 's/\[//g' -e 's/ //g' -e 's/app://' -e 's/[:,]//g'`
APP_VERSION := $(shell grep 'version:' mix.exs | cut -d '"' -f2)
DOCKER_IMAGE_TAG ?= $(APP_VERSION)
GIT_REVISION ?= `git rev-parse HEAD`
CLIENT_ID=:sbompoc
MQTT_HOST=34.86.117.113
MQTT_PORT=1883
USER_NAME=plug
PASSWORD=fest
# Introspection targets
# ---------------------
.PHONY: help
help: header targets
.PHONY: header
header:
@echo "\033[34mEnvironment\033[0m"
@echo "\033[34m---------------------------------------------------------------\033[0m"
@printf "\033[33m%-23s\033[0m" "APP_NAME"
@printf "\033[35m%s\033[0m" $(APP_NAME)
@echo ""
@printf "\033[33m%-23s\033[0m" "APP_VERSION"
@printf "\033[35m%s\033[0m" $(APP_VERSION)
@echo ""
@printf "\033[33m%-23s\033[0m" "GIT_REVISION"
@printf "\033[35m%s\033[0m" $(GIT_REVISION)
@echo ""
@printf "\033[33m%-23s\033[0m" "DOCKER_IMAGE_TAG"
@printf "\033[35m%s\033[0m" $(DOCKER_IMAGE_TAG)
@echo "\n"
.PHONY: targets
targets:
@echo "\033[34mTargets\033[0m"
@echo "\033[34m---------------------------------------------------------------\033[0m"
@perl -nle'print $& if m{^[a-zA-Z_-]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-22s\033[0m %s\n", $$1, $$2}'
.PHONY: compile
compile: ## compile the project
mix compile
.PHONY: lint-compile
lint-compile: ## check for warnings in functions used in the project
mix compile --warnings-as-errors --force
.PHONY: lint-format
lint-format: ## Check if the project is well formated using elixir formatter
mix format --dry-run --check-formatted
.PHONY: lint-credo
lint-credo: ## Use credo to ensure formatting styles
mix credo --strict
.PHONY: lint
lint: lint-compile lint-format lint-credo ## Check if the project follows set conventions such as formatting
.PHONY: test
test: ## Run the test suite
mix test
.PHONY: format
format: mix format ## Run formatting tools on the code
.PHONY: sbom
sbom: ## creates sbom for both npm and hex dependancies
mix deps.get && mix sbom.cyclonedx -o elixir_bom.xml
cd assets/ && npm install && npm install -g @cyclonedx/bom && cyclonedx-bom -o ../bom.xml -a ../elixir_bom.xml && cd ..
./cyclonedx-cli convert --input-file bom.xml --output-file bom.json
release: ## Build a release of the application with MIX_ENV=prod
MIX_ENV=prod mix deps.get --only prod
MIX_ENV=prod mix compile
npm install --prefix ./assets
npm run deploy --prefix ./assets
mkdir -p priv/static
MIX_ENV=prod mix phx.digest
MIX_ENV=prod mix release
.PHONY: docker-image
docker-image:
docker build . -t sbom:$(APP_VERSION) --no-cache \
--build-arg CLIENT_ID=$(CLIENT_ID) \
--build-arg MQTT_HOST=$(MQTT_HOST) \
--build-arg MQTT_PORT=$(MQTT_PORT) \
--build-arg USER_NAME=$(USER_NAME) \
--build-arg PASSWORD=$(PASSWORD) \
.PHONY: push-image-gcp push-and-serve deploy-existing-image
push-image-gcp: ## push image to gcp
@if [[ "$(docker images -q gcr.io/twinklymaha/sbom:$(APP_VERSION)> /dev/null)" != "" ]]; then \
@echo "Removing previous image $(APP_VERSION) from your machine..."; \
docker rmi gcr.io/twinklymaha/sbom:$(APP_VERSION);\
fi
docker build . -t gcr.io/twinklymaha/sbom:$(APP_VERSION) \
--build-arg CLIENT_ID=$(CLIENT_ID) \
--build-arg MQTT_HOST=$(MQTT_HOST) \
--build-arg MQTT_PORT=$(MQTT_PORT) \
--build-arg USER_NAME=$(USER_NAME) \
--build-arg PASSWORD=$(PASSWORD) \
gcloud container images delete gcr.io/twinklymaha/sbom:$(APP_VERSION) --force-delete-tags || echo "no image to delete on the remote"
docker push gcr.io/twinklymaha/sbom:$(APP_VERSION)
push-and-serve-gcp: push-image-gcp deploy-existing-image
deploy-existing-image:
gcloud compute instances create-with-container $(instance-name) \
--container-image=gcr.io/twinklymaha/sbom:$(DOCKER_IMAGE_TAG) \
--machine-type=e2-micro \
--subnet=default \
--network-tier=PREMIUM \
--metadata=google-logging-enabled=true \
--tags=http-server,https-server \
--labels=project=sbom \
--container-env=CLIENT_ID=$(CLIENT_ID),MQTT_HOST=$(MQTT_HOST),MQTT_PORT=$(MQTT_PORT),USER_NAME=$(USER_NAME),PASSWORD=$(PASSWORD)
.PHONY: update-instance
update-instance:
gcloud compute instances update-container $(instance-name) --container-image gcr.io/twinklymaha/sbom:$(image-tag)