*/Dockerfile.template: Replace ADD with COPY
[dockerfile.git] / x.509 / Makefile-server
1 # Create self-signed certificates with GnuTLS [1]
2 #
3 # This is useful for testing with the nginx-proxy container.
4 #
5 # You should probably write your own templates [2], but if you don't
6 # this Makefile will use ORGANIZATION to create a very basic template.
7 #
8 # [1]: http://www.gnutls.org/
9 # [2]: http://www.gnutls.org/manual/html_node/certtool-Invocation.html#Certtool_0027s-template-file-format
10
11 ORGANIZATION ?= Example, Inc.
12 DOMAIN ?= example.com
13 HOSTS ?= www static media kibana es
14 DEFAULT ?= www.$(DOMAIN)
15 FQDNS ?= $(patsubst %, %.$(DOMAIN), $(HOSTS))
16
17 CA_KEY ?= /etc/ssl/ca/key.pem
18 CA_CERT ?= /etc/ssl/ca/ca.pem
19
20 KEYS = $(patsubst %, %.key, $(FQDNS))
21 CERTS = $(patsubst %, %.cert, $(FQDNS))
22 CHAINED_CERTS = $(patsubst %, %.pem, $(FQDNS))
23
24 .PRECIOUS: %.tmpl %.key %.cert %.pem
25
26 all: $(KEYS) $(CHAINED_CERTS) nginx.key nginx.pem
27
28 clean:
29         rm -f *.tmpl *.key *.cert *.pem
30
31 %.tmpl:
32         echo 'organization = $(ORGANIZATION)' > "$@"
33         echo 'cn = $*' >> "$@"
34         echo 'dns_name = $*' >> "$@"
35         echo 'tls_www_server' >> "$@"
36         echo 'encryption_key' >> "$@"
37
38 $(KEYS): %.key:
39         certtool --generate-privkey --outfile "$@"
40
41 $(CERTS): %.cert: %.tmpl %.key $(CA_KEY) $(CA_CERT)
42         certtool --generate-certificate \
43                 --template "$*.tmpl" \
44                 --load-privkey "$*.key" \
45                 --load-ca-privkey "$(CA_KEY)" \
46                 --load-ca-certificate "$(CA_CERT)" \
47                 --outfile "$@"
48
49 $(CHAINED_CERTS): %.pem: %.cert $(CA_CERT)
50         cat $^ > "$@"
51
52 nginx.%: $(DEFAULT).%
53         ln -s "$<" "$@"