-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
52 lines (44 loc) · 1.8 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
# Load variable definitions from variables.env
include variables.env
# Variables
DOCKERFILE := Dockerfile
# Docker commands
DOCKER := docker
DOCKER_BUILD := $(DOCKER) build
DOCKER_TAG := $(DOCKER) tag
# Certificate generation commands
ROOT_CA_DIR := rootCA
CERT_DIR := certs
ROOT_KEY := $(ROOT_CA_DIR)/global.key
ROOT_CA := $(ROOT_CA_DIR)/global.crt
CERT_KEY := $(CERT_DIR)/ca.key
CERT_CSR := $(CERT_DIR)/ca.csr
CERT_PEM := $(CERT_DIR)/ca.crt
CERT_DER := $(CERT_DIR)/ca.der
# Targets
.PHONY: build tag help
build:
mkdir -p $(CERT_DIR)
mkdir -p $(ROOT_CA_DIR)
# Generate root CA keys
openssl genrsa -out $(ROOT_KEY) 4096
openssl req -new -x509 -days 365 -subj "/C=US/ST=State/L=City/O=Organization/CN=$(IMAGE_NAME)" -key $(ROOT_KEY) -out $(ROOT_CA)
# Generate the certificates using OpenSSL
openssl genrsa -out $(CERT_KEY) 2048
openssl rsa -in $(CERT_KEY) -outform DER -out $(CERT_DER)
openssl req -new -key $(CERT_KEY) -out $(CERT_CSR) -subj "/C=US/ST=State/L=City/O=Organization/CN=localhost"
# generate PEM for NGINX and DER for LUA
openssl x509 -req -in $(CERT_CSR) -out $(CERT_PEM) -CA $(ROOT_CA) -CAkey $(ROOT_KEY) -CAcreateserial -days 360
# Build the Docker image with the specified version
$(DOCKER_BUILD) --build-arg VERSION=$(VERSION) -t $(IMAGE_NAME):$(VERSION) -f $(DOCKERFILE) .
tag:
$(DOCKER_TAG) $(IMAGE_NAME):$(VERSION) $(IMAGE_NAME):latest
help:
@echo "Available targets:"
@echo " build: Generate certificates and build the Docker image with the specified version."
@echo " tag: Tag the built image with 'latest'."
@echo " help: /* Build project: make build"
@echo " /* Tag as latest (optional): make tag"
@echo " /* Docker network is not created by default. You can create by youself. Check compose file"
# Default target
.DEFAULT_GOAL := help