Skip to content

Commit d82865b

Browse files
committed
add docker compose for nginx and add cert generator
1 parent f956843 commit d82865b

File tree

9 files changed

+191
-34
lines changed

9 files changed

+191
-34
lines changed

Dockerfile

Lines changed: 0 additions & 23 deletions
This file was deleted.

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ CURRENT_DIR=$(shell pwd)
99
clean:
1010
@echo "Clean"
1111
rm -rf build
12+
docker volume rm ccn-coverage-vis_certs
13+
docker rmi $(docker images --filter=reference='ccn-coverage-vis*' -q)
1214

1315
.PHONY: build
1416
build:

README.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,10 @@ To install this service, the fist time, you will need to:
1010

1111
1. Required tools and versions:
1212
1. Install `node` and `npm` according to the directions at https://nodejs.org/en/download/package-manager
13-
2. Install `pm2` using: `npm install pm2 -g` (as per https://www.npmjs.com/package/pm2#installing-pm2)
1413
2. Clone the service: `https://github.com/Local-Connectivity-Lab/ccn-coverage-vis`
15-
2. Configure:
14+
3. Configure:
1615
1. `cd cd ccn-coverage-vis`
1716
1. Edit `src/utils/config.ts` and set the correct URL for your API host (if you're testing or you're deploying to a new URL).
18-
4. Deploy as below.
19-
5. When starting the ccn-coverage-vis service the first time, use:
20-
```
21-
pm2 start --name "Vis Server" npm -- run start
22-
```
23-
This will register ccn-coverage-vis with [PM2](https://pm2.keymetrics.io/docs/usage/quick-start/).
2417

2518

2619
## Deploying
@@ -135,6 +128,3 @@ npm install
135128
- Toggle Active
136129
- Better compatibility with local development
137130

138-
# Maybe
139-
140-
- More map information

cert.dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM ubuntu:latest
2+
3+
WORKDIR /
4+
5+
RUN apt-get update && apt-get install -y openssl
6+
7+
COPY scripts/generate-certs.sh .
8+
9+
RUN chmod +x generate-certs.sh
10+
CMD ["./generate-certs.sh"]

configs/nginx.conf

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# HTTP server - redirects to HTTPS
2+
server {
3+
listen 80;
4+
server_name localhost;
5+
6+
# Redirect all HTTP requests to HTTPS
7+
return 301 https://$host$request_uri;
8+
}
9+
10+
# HTTPS server
11+
server {
12+
listen 443 ssl;
13+
server_name localhost;
14+
15+
# SSL certificate configuration
16+
ssl_certificate /etc/nginx/ssl/certs/certificate.pem;
17+
ssl_certificate_key /etc/nginx/ssl/certs/private-key.pem;
18+
19+
# SSL protocols and ciphers for improved security
20+
ssl_protocols TLSv1.2 TLSv1.3;
21+
ssl_prefer_server_ciphers on;
22+
ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384';
23+
ssl_session_timeout 1d;
24+
ssl_session_cache shared:SSL:50m;
25+
26+
# HSTS (HTTP Strict Transport Security)
27+
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
28+
29+
# Compression settings for better performance
30+
gzip on;
31+
gzip_vary on;
32+
gzip_min_length 10240;
33+
gzip_proxied expired no-cache no-store private auth;
34+
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml application/javascript;
35+
gzip_disable "MSIE [1-6]\.";
36+
37+
# Caching settings for static assets
38+
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
39+
root /usr/share/nginx/html;
40+
expires 1y;
41+
add_header Cache-Control "public, max-age=31536000, immutable";
42+
try_files $uri =404;
43+
}
44+
45+
location / {
46+
root /usr/share/nginx/html;
47+
try_files $uri $uri/ /index.html;
48+
}
49+
50+
# Error pages
51+
error_page 404 /index.html;
52+
error_page 500 502 503 504 /50x.html;
53+
location = /50x.html {
54+
root /usr/share/nginx/html;
55+
}
56+
}

docker-compose.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
services:
2+
cert-generator:
3+
build:
4+
context: .
5+
dockerfile: cert.dockerfile
6+
volumes:
7+
- certs:/certs
8+
9+
web:
10+
build:
11+
context: .
12+
dockerfile: vis.dockerfile
13+
volumes:
14+
- certs:/etc/nginx/ssl/certs
15+
ports:
16+
- 443:443
17+
depends_on:
18+
- cert-generator
19+
20+
volumes:
21+
certs:

pm2-running-services.png

-17.5 KB
Binary file not shown.

scripts/generate-certs.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
3+
# Set variables
4+
PRIMARY_DOMAIN="ccn-coverage-vis"
5+
CERT_DIR="/certs" # Use absolute path
6+
DAYS_VALID=365
7+
8+
# Add all domains that might be used to access your service
9+
DOMAINS=(
10+
"$PRIMARY_DOMAIN"
11+
"localhost"
12+
"127.0.0.1"
13+
)
14+
15+
# Create directory for certificates if it doesn't exist
16+
mkdir -p $CERT_DIR
17+
18+
echo "Generating self-signed certificates..."
19+
20+
# Generate private key
21+
openssl genrsa -out $CERT_DIR/private-key.pem 2048
22+
23+
# Create config file for SAN support
24+
cat > $CERT_DIR/openssl.cnf << EOF
25+
[req]
26+
distinguished_name = req_distinguished_name
27+
req_extensions = v3_req
28+
prompt = no
29+
30+
[req_distinguished_name]
31+
CN = $PRIMARY_DOMAIN
32+
33+
[v3_req]
34+
basicConstraints = CA:FALSE
35+
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
36+
subjectAltName = @alt_names
37+
38+
[alt_names]
39+
EOF
40+
41+
# Add all domains to the config file
42+
for i in "${!DOMAINS[@]}"; do
43+
echo "DNS.$((i+1)) = ${DOMAINS[$i]}" >> $CERT_DIR/openssl.cnf
44+
done
45+
46+
# Generate a CSR with the config
47+
openssl req -new -key $CERT_DIR/private-key.pem -out $CERT_DIR/csr.pem -config $CERT_DIR/openssl.cnf
48+
49+
# Generate the self-signed certificate
50+
openssl x509 -req -days $DAYS_VALID -in $CERT_DIR/csr.pem -signkey $CERT_DIR/private-key.pem -out $CERT_DIR/certificate.pem -extensions v3_req -extfile $CERT_DIR/openssl.cnf
51+
52+
# Create a full chain file
53+
cat $CERT_DIR/certificate.pem > $CERT_DIR/fullchain.pem
54+
55+
# Set proper permissions (readable by all)
56+
chmod 644 $CERT_DIR/private-key.pem
57+
chmod 644 $CERT_DIR/certificate.pem
58+
chmod 644 $CERT_DIR/fullchain.pem
59+
60+
# Try to generate PKCS12 file but don't fail if it doesn't work
61+
openssl pkcs12 -export -out $CERT_DIR/certificate.pfx -inkey $CERT_DIR/private-key.pem -in $CERT_DIR/certificate.pem -passout pass: || echo "PKCS12 export failed, but continuing"
62+
63+
# Verify file creation and permissions
64+
echo "Certificates generated successfully in $CERT_DIR directory!"
65+
echo "Files generated with permissions:"
66+
ls -la $CERT_DIR/
67+
68+
# Verify certificate content
69+
echo "Verifying certificate:"
70+
openssl x509 -in $CERT_DIR/certificate.pem -text -noout | head -n 15
71+
72+
# Verify private key
73+
echo "Verifying private key:"
74+
openssl rsa -in $CERT_DIR/private-key.pem -check -noout || echo "Private key verification failed"

vis.dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM node:22-slim AS build
2+
3+
WORKDIR /usr/src/app
4+
5+
COPY package*.json ./
6+
COPY tsconfig.json ./
7+
COPY scripts/setup.sh ./scripts/
8+
9+
RUN chmod +x ./scripts/setup.sh
10+
RUN ./scripts/setup.sh
11+
12+
RUN npm ci
13+
14+
COPY . .
15+
16+
RUN npm run build
17+
18+
RUN npm prune --production
19+
20+
FROM nginx:stable
21+
22+
COPY --from=build /usr/src/app/build /usr/share/nginx/html
23+
COPY configs/nginx.conf /etc/nginx/conf.d/default.conf
24+
25+
EXPOSE 443
26+
27+
CMD ["nginx", "-g", "daemon off;"]

0 commit comments

Comments
 (0)