-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
84 lines (71 loc) · 3.37 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
SHELL := /bin/bash
BUILD_OUTPUT=main
BUILD_FOLDER=build
APP_PORT?=8080
APP_IMAGE_NAME=jwt_auth
APP_CONTAINER_PORT=8080
APP_CONTAINER_NAME=jwt
gencert:
@echo "make gencert - Create a self-signed X.509 certificate (dev only)"
rm -f server.crt
rm -f server.key
rm -f $(BUILD_FOLDER)/server.crt
rm -f $(BUILD_FOLDER)/server.key
# Key considerations for algorithm "RSA" ≥ 2048-bit
openssl genrsa -out server.key 2048
# Key considerations for algorithm "ECDSA" ≥ secp384r1
# List ECDSA the supported curves (openssl ecparam -list_curves)
openssl ecparam -genkey -name secp384r1 -out server.key
# Generation of self-signed(x509) public key (PEM-encodings .pem|.crt) based on the private (.key)
openssl req -new -x509 -sha256 -key server.key -out server.crt -days 3650
.PHONY: build
build:
@echo "make build - Build the binary"
go build -a -o $(BUILD_FOLDER)/$(BUILD_OUTPUT)
cp server.crt $(BUILD_FOLDER)/server.crt
cp server.key $(BUILD_FOLDER)/server.key
cp config.yaml $(BUILD_FOLDER)/config_for_host.yaml
chmod 755 $(BUILD_FOLDER)/$(BUILD_OUTPUT)
run:
@echo "make run - Run the binary with an available config.yaml"
./$(BUILD_FOLDER)/$(BUILD_OUTPUT) -config=config_for_host.yaml
clean:
@echo "make clean - Clean the build output"
@if [[ -e "$(BUILD_FOLDER)" ]]; then \
rm -rf $(BUILD_FOLDER)/*; \
fi
killapp:
@echo "make killapp - Kill process of the app on configured port"
lsof -ti tcp:$(APP_PORT) | xargs kill
# run_example:
# export TOKEN=$(curl "https://localhost:8080/signin" -k -X POST -H "Accept: application/json" -d "@example/creds.json" -v 2>&1 | grep -Fi token | awk -F"=|;" '{print $2}'); \
# curl "https://localhost:8080/welcome" -k -v -X POST -H "Accept: application/json" -H "Authorization: Bearer $$TOKEN"
###################################################################
###################################################################
###################################################################
docker-build:
docker build -t $(APP_IMAGE_NAME) . --no-cache
docker-run:
docker rm -f $(APP_CONTAINER_NAME) || true && \
docker run -p $(APP_PORT):$(APP_CONTAINER_PORT) --name $(APP_CONTAINER_NAME) $(APP_IMAGE_NAME)
docker-rm:
docker rm -f $(APP_CONTAINER_NAME)
###################################################################
###################################################################
###################################################################
help:
@echo "============================================================================="
@echo "Build commands: "
@echo " make build - Build the binary "
@echo " make clean - Clean the build output "
@echo " make gencert - Create a self-signed X.509 certificate (dev only) "
@echo " make help - Show current build info "
@echo " make killapp - Kill process of the app on the configured port "
@echo " make run - Run the binary with available config.yaml "
@echo "============================================================================="
@echo "Docker-related commands: "
@echo " make docker-build - Build application image "
@echo " make docker-run - Run application container "
@echo " make docker-rm - Remove forcefully application container "
@echo "============================================================================="
.SILENT: