Skip to content

Commit

Permalink
Updated Dockerfile and build
Browse files Browse the repository at this point in the history
The Docker cluster was not working; not sure when that happened.

Made improvements and fixes to the build and serve scripts.  It's been a
while since there's been a `build` dir, so I guess this has been broken
for a while.
  • Loading branch information
stupid-genius committed Jun 2, 2024
1 parent 3a0f029 commit 2cc2717
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 40 deletions.
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
FROM node:gallium-alpine
WORKDIR /opt/webapptemplate
ENV NODE_ENV=production
COPY build/ .
RUN npm i
COPY dist/ serve.sh .
RUN npm ci
EXPOSE 3000
CMD ["npm", "start"]

CMD ["sh", "serve.sh"]
2 changes: 1 addition & 1 deletion app/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const servefavicon = require('serve-favicon');
const path = require('path');
const config = require('./config');

/* eslint-disable-next-line no-undef */
Logger(config);
const logger = new Logger(path.basename(__filename));

const app = express();
Expand Down
2 changes: 2 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ cp app/client/* dist/client/ 2> /dev/null || :
if [ -d "app/client/images" ] && [ -n "app/client/images/*" ]; then
cp -R app/client/images dist/client/
fi
jq '{name: .name, description: .description, version: .version, dependencies: .dependencies}' package.json > dist/package.json
cp package-lock.json .env dist/
echo Build complete
4 changes: 2 additions & 2 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
COPY cert.pem /etc/nginx/cert.pem
COPY key.pem /etc/nginx/key.pem
# COPY cert.pem /etc/nginx/cert.pem
# COPY key.pem /etc/nginx/key.pem
44 changes: 22 additions & 22 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,30 @@ http {
proxy_pass http://api:3000;
}
}
server {
server_name _;
listen 443 ssl;
# server {
# server_name _;
# listen 443 ssl;

ssl_certificate cert.pem;
ssl_certificate_key key.pem;
# ssl_certificate cert.pem;
# ssl_certificate_key key.pem;

ssl_protocols TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
ssl_session_timeout 10m;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
# add_header X-Frame-Options DENY;
# add_header X-Content-Type-Options nosniff;
# add_header X-XSS-Protection "1; mode=block";
# ssl_protocols TLSv1.2;
# ssl_prefer_server_ciphers on;
# ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
# ssl_session_timeout 10m;
# ssl_session_cache shared:SSL:10m;
# ssl_session_tickets off;
# ssl_stapling on;
# ssl_stapling_verify on;
# resolver 8.8.8.8 8.8.4.4 valid=300s;
# resolver_timeout 5s;
# # add_header X-Frame-Options DENY;
# # add_header X-Content-Type-Options nosniff;
# # add_header X-XSS-Protection "1; mode=block";

location / {
proxy_pass http://api:3000;
}
}
# location / {
# proxy_pass http://api:3000;
# }
# }
}

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@
"scripts": {
"build": "npm run clean; ./build.sh",
"clean": "rm -rf dist",
"cluster": "npm run build; docker compose up --build; docker compose down",
"container": "docker run --name webapp -p80:3000 --rm webapptemplate",
"docker": "docker build -t webapptemplate .",
"esbuild": "esbuild",
"image": "docker build -t webapptemplate .",
"nodemon": "npx nodemon dist/server/index.js",
"package": "mkdir -p package; cd dist; npm pack --pack-destination='../package/'",
"start": "NODE_ENV=development ./serve.sh",
Expand Down
33 changes: 23 additions & 10 deletions serve.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
#!/bin/bash
# auto-reloading development server
# setting SPAMODE will run in SPA mode
# setting NODE_ENV=production will run without dev tooling

set -e
set -a
. .env
set +a
APPPORT=3000

./node_modules/.bin/browser-sync start --port 9000 --proxy localhost:$APPPORT --no-open -f dist/client &
BSPID=$!
echo BrowserSync PID $BSPID
trap "kill $BSPID 2> /dev/null" INT HUP TERM QUIT ABRT EXIT
if [[ -z "$1" || "$1" -ne spa ]]; then
(fswatch -ol 1 app | xargs -n1 -I{} ./build.sh) &
npm run nodemon
if [ "$NODE_ENV" = "production" ]; then
echo "NODE_ENV is set to production"
if [ -n "$SPAMODE" ]; then
npx http-server -c-1 client/ -p $APPPORT
else
npx nodemon server/index.js
fi
else
echo Server in SPA mode
(fswatch -ol 1 app/client | xargs -n1 -I{} ./build.sh spa) &
npx http-server dist/client/ -p $APPPORT
./node_modules/.bin/browser-sync start --port 9000 --proxy localhost:$APPPORT --no-open -f dist/client &
BSPID=$!
echo BrowserSync PID $BSPID
trap "kill -0 $BSPID &> /dev/null && kill $BSPID && echo sending SIGTERM to $BSPID" INT HUP TERM QUIT ABRT EXIT
# if [[ -z "$1" || "$1" -ne spa ]]; then
if [ -n "$SPAMODE" ]; then
echo Server in SPA mode
(fswatch -ol 1 app/client | xargs -n1 -I{} ./build.sh spa) &
npx http-server -c-1 dist/client/ -p $APPPORT
else
(fswatch -ol 1 app | xargs -n1 -I{} ./build.sh) &
npm run nodemon
fi
fi

0 comments on commit 2cc2717

Please sign in to comment.