-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
151 lines (130 loc) · 4.88 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
.PHONY: help build run
# Docker image name and tag
DOCKER_IMAGE ?= eu.gcr.io/jenkins-189019/igrant-eudi-wallet
GIT_TAG ?= $(shell git describe --tags --abbrev=0 2>/dev/null)
GIT_COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null)
# Save the name of docker image to be deployed in deploy version file
# When make publish is executed it will push the docker image to the container registry
DEPLOY_VERSION_FILE = ./deploy_version
DEPLOY_VERSION = $(shell test -f $(DEPLOY_VERSION_FILE) && cat $(DEPLOY_VERSION_FILE))
# Settings for server
# Ngrok is only required if needs to expose wallet to internet during development
NGROK_AUTH_TOKEN ?=
DOMAIN ?=
# Kafka settings is mandatory
KAFKA_TOPIC ?= ebsi
KAFKA_BROKER_ADDRESS ?= broker:29092
# To enable debug mode using debugpy
DEBUG ?= false
DEBUG_HOST ?= 0.0.0.0
DEBUG_PORT ?= 5678
# Settings for database
PG_IMAGE ?= postgres:13
PG_CONTAINER_NAME ?= eudi_wallet_postgres
PG_PORT ?= 5432
PG_USER ?= eudiwallet
PG_PASSWORD ?= secret
PG_DB ?= eudiwalletdb
PG_VOLUME ?= eudi_wallet_pgdata
help: ## Print a help message.
@echo "=================================================="
@echo " EUDI Wallet "
@echo "=================================================="
@echo ""
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
build: ## Build the base container image.
$(eval DOCKER_TAG=$(shell date +%Y%m%d%H%M%S)-$(if $(GIT_TAG),$(GIT_TAG),$(if $(GIT_COMMIT),$(GIT_COMMIT),latest)))
@echo "Building Docker image with tag: $(DOCKER_TAG)"
docker build -f ./resources/docker/server/Dockerfile -t $(DOCKER_IMAGE):$(DOCKER_TAG) .
echo "$(DOCKER_IMAGE):$(DOCKER_TAG)" > $(DEPLOY_VERSION_FILE)
run: ## Run the server
$(eval DOCKER_TAG=$(shell cat deploy_version))
@echo "Running Docker container with image: $(DOCKER_TAG)"
docker run \
--name eudiwallet \
-e "PORT=9000" \
-e "DOMAIN=$(DOMAIN)" \
-e "DEBUG=$(DEBUG)" \
-e "DEBUG_HOST=$(DEBUG_HOST)" \
-e "DEBUG_PORT=$(DEBUG_PORT)" \
-e DATABASE_USER=$(PG_USER) \
-e DATABASE_PASSWORD=$(PG_PASSWORD) \
-e DATABASE_HOST=$(PG_CONTAINER_NAME) \
-e DATABASE_PORT=$(PG_PORT) \
-e DATABASE_DB=$(PG_DB) \
-p 9000:9000 \
--link=$(PG_CONTAINER_NAME) \
$(DOCKER_TAG)
run-config: ## Run the server
$(eval DOCKER_TAG=$(shell cat deploy_version))
@echo "Running Docker container with image: $(DOCKER_TAG)"
docker run \
--name eudiwallet-config \
-e "ROUTE_PERMITTED=config" \
-e "PORT=9000" \
-e "DOMAIN=$(DOMAIN)" \
-e "DEBUG=$(DEBUG)" \
-e "DEBUG_HOST=$(DEBUG_HOST)" \
-e "DEBUG_PORT=$(DEBUG_PORT)" \
-e DATABASE_USER=$(PG_USER) \
-e DATABASE_PASSWORD=$(PG_PASSWORD) \
-e DATABASE_HOST=$(PG_CONTAINER_NAME) \
-e DATABASE_PORT=$(PG_PORT) \
-e DATABASE_DB=$(PG_DB) \
-p 8080:9000 \
--link=$(PG_CONTAINER_NAME) \
$(DOCKER_TAG)
run-service: ## Run the server
$(eval DOCKER_TAG=$(shell cat deploy_version))
@echo "Running Docker container with image: $(DOCKER_TAG)"
docker run \
--name eudiwallet-service \
-e "PORT=9000" \
-e "ROUTE_PERMITTED=service" \
-e "DOMAIN=$(DOMAIN)" \
-e "DEBUG=$(DEBUG)" \
-e "DEBUG_HOST=$(DEBUG_HOST)" \
-e "DEBUG_PORT=$(DEBUG_PORT)" \
-e DATABASE_USER=$(PG_USER) \
-e DATABASE_PASSWORD=$(PG_PASSWORD) \
-e DATABASE_HOST=$(PG_CONTAINER_NAME) \
-e DATABASE_PORT=$(PG_PORT) \
-e DATABASE_DB=$(PG_DB) \
-p 9000:9000 \
--link=$(PG_CONTAINER_NAME) \
$(DOCKER_TAG)
run-db: ## Start the PostgreSQL database
@echo "Starting PostgreSQL database..."
docker run -d \
--name $(PG_CONTAINER_NAME) \
-e POSTGRES_USER=$(PG_USER) \
-e POSTGRES_PASSWORD=$(PG_PASSWORD) \
-e POSTGRES_DB=$(PG_DB) \
-p 5442:$(PG_PORT) \
-v $(PG_VOLUME):/var/lib/postgresql/data \
$(PG_IMAGE)
stop-config: ## Stop the config server
@echo "Stopping config server..."
docker stop eudiwallet-config && docker rm eudiwallet-config
stop-service: ## Stop the service server
@echo "Stopping service server..."
docker stop eudiwallet-service && docker rm eudiwallet-service
stop: ## Stop the server
@echo "Stopping server..."
docker stop eudiwallet && docker rm eudiwallet
stop-db: ## Stop the PostgreSQL database
@echo "Stopping PostgreSQL database..."
docker stop $(PG_CONTAINER_NAME) && docker rm $(PG_CONTAINER_NAME)
create-db-volume: ## Create Docker volume for PostgreSQL data
@echo "Creating Docker volume..."
docker volume create $(PG_VOLUME)
destroy-db-volume: ## Destroy Docker volume and all associated data
@echo "Destroying Docker volume..."
docker volume rm $(PG_VOLUME)
.PHONY: publish
publish: $(DEPLOY_VERSION_FILE) ## Publish latest production Docker image to docker hub
docker push $(DEPLOY_VERSION)
deploy: $(DEPLOY_VERSION_FILE) ## Deploy to K8s cluster (e.g. make deploy/{preview,staging,production})
kubectl set image deployment/config-ew config-ew=$(DEPLOY_VERSION) -n eudiwallet
kubectl set image deployment/service-ew service-ew=$(DEPLOY_VERSION) -n eudiwallet
.DEFAULT_GOAL := help