From 84c82f6a5655e183dc8e7fced10978ee0643cad7 Mon Sep 17 00:00:00 2001 From: Esther Date: Mon, 15 Feb 2021 01:45:26 +0000 Subject: [PATCH] Attempt to add dockerfile --- .gitignore | 2 ++ app.js | 2 +- bin/www | 4 ++-- dockerfile | 9 ++++++--- pastel-codes.service | 22 ++++++++++++++++++++++ 5 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 pastel-codes.service diff --git a/.gitignore b/.gitignore index d57053d..35d1ec2 100644 --- a/.gitignore +++ b/.gitignore @@ -195,3 +195,5 @@ fabric.properties .idea/caches/build_file_checksums.ser notes + +.secrets \ No newline at end of file diff --git a/app.js b/app.js index d948084..3c422a3 100644 --- a/app.js +++ b/app.js @@ -13,7 +13,7 @@ var contactRouter = require('./routes/contact'); var app = express(); -app.set('trust proxy', 'loopback,uniquelocal'); +if (process.env.IS_DOCKER != 'true') app.set('trust proxy', 'loopback,uniquelocal'); app.disable('x-powered-by'); // view engine setup diff --git a/bin/www b/bin/www index 46dfc9e..2a4ae56 100755 --- a/bin/www +++ b/bin/www @@ -14,7 +14,6 @@ var http = require('http'); var port = normalizePort(process.env.PORT || '7000'); app.set('port', port); -console.log(port) /** * Create HTTP server. @@ -26,7 +25,8 @@ var server = http.createServer(app); * Listen on provided port, on all localhost. */ -server.listen(port, 'localhost'); +if (process.env.IS_DOCKER == 'true') server.listen(port, '0.0.0.0'); +else server.listen(port, '127.0.0.1'); server.on('error', onError); server.on('listening', onListening); diff --git a/dockerfile b/dockerfile index 5355582..8d16007 100644 --- a/dockerfile +++ b/dockerfile @@ -1,7 +1,10 @@ FROM node:15.8.0 -ENV PORT= -ENV NODE_ENV= +ARG port = + +ENV PORT=${port} +ENV IS_DOCKER=true +ENV NODE_ENV=production ENV GHOST_KEY= ENV HCAPTCHA_KEY= ENV SENDGRID_API_KEY= @@ -15,4 +18,4 @@ RUN npm install COPY . . CMD [ "npm", "start" ] -EXPOSE 7000/tcp +EXPOSE ${port}/tcp diff --git a/pastel-codes.service b/pastel-codes.service new file mode 100644 index 0000000..774010d --- /dev/null +++ b/pastel-codes.service @@ -0,0 +1,22 @@ +[Unit] +Description="pastel.codes web service" +Documentation=https://pastel.codes.com +After=network.target + +[Service] +Environment=PORT=7000 +Environment=NODE_ENV=production +Environment=GHOST_KEY=key +Environment=HCAPTCHA_KEY=key +Environment=SENDGRID_API_KEY=key +Environment=TO_MAIL_USER=user +Environment=REPLY_TO_MAIL=user +Environment=FROM_MAIL_USER=user +StandardOutput=syslog +SyslogIdentifier=pastel-codes +User=web +ExecStart=/home/web/pastel.codes/bin/www +Restart=always + +[Install] +WantedBy=multi-user.target