From 32a496599fa0ef639d0943bf57c98d0bfd2d389d Mon Sep 17 00:00:00 2001 From: nikurasu Date: Thu, 10 Nov 2022 15:49:01 +0100 Subject: [PATCH] FEATURE: Made Port dynamic with env variable --- .env.example | 1 + .gitignore | 3 ++- dev/docker/images/main/Dockerfile | 5 ++--- dev/docker/stacks/main/compose.yml | 6 ++++-- dev/shell/docker-prod.sh | 2 +- package.json | 1 + src/index.js | 4 +++- yarn.lock | 5 +++++ 8 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..c0c68b1 --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +PORT=3000 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 090a5b6..1e2ef7f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules src/dist -dev/docker/stacks/main/assets \ No newline at end of file +dev/docker/stacks/main/assets +.env \ No newline at end of file diff --git a/dev/docker/images/main/Dockerfile b/dev/docker/images/main/Dockerfile index 9a9e48d..8a887de 100644 --- a/dev/docker/images/main/Dockerfile +++ b/dev/docker/images/main/Dockerfile @@ -4,10 +4,9 @@ WORKDIR /app COPY src/ ./src COPY package.json ./ COPY yarn.lock ./ +COPY .env.example ./.env COPY assets /assets COPY dev/shell/entrypoint.sh /entrypoint.sh -RUN yarn -RUN yarn clean -RUN yarn build-prod +RUN yarn && yarn clean && yarn build-prod EXPOSE 3000 ENTRYPOINT ["/bin/sh", "/entrypoint.sh"] \ No newline at end of file diff --git a/dev/docker/stacks/main/compose.yml b/dev/docker/stacks/main/compose.yml index c0ba82f..9997809 100644 --- a/dev/docker/stacks/main/compose.yml +++ b/dev/docker/stacks/main/compose.yml @@ -1,9 +1,11 @@ version: '3' services: app: - image: nikurasukun/socialtree + image: git.oishi-ra.men/nikurasu/socialtree-js:latest container_name: socialtree + environment: + PORT: 3000 volumes: - ./assets:/app/assets/ ports: - - 80:3000 \ No newline at end of file + - 3000:3000 \ No newline at end of file diff --git a/dev/shell/docker-prod.sh b/dev/shell/docker-prod.sh index 26358d2..12f4a58 100755 --- a/dev/shell/docker-prod.sh +++ b/dev/shell/docker-prod.sh @@ -1 +1 @@ -docker build -t git.oishi-ra.men/nikurasu/socialtree-js -f dev/docker/images/main/Dockerfile --no-cache . \ No newline at end of file +docker build -t git.oishi-ra.men/nikurasu/socialtree-js:latest -f dev/docker/images/main/Dockerfile --no-cache . \ No newline at end of file diff --git a/package.json b/package.json index 005d742..1913923 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "build-prod": "sass --style=compressed src/public/themes:src/dist/style" }, "dependencies": { + "dotenv": "^16.0.3", "ejs": "^3.1.8", "express": "^4.18.2", "js-yaml": "^4.1.0" diff --git a/src/index.js b/src/index.js index 91325ef..55d4835 100644 --- a/src/index.js +++ b/src/index.js @@ -1,11 +1,13 @@ import express from 'express' import yaml from 'js-yaml' import fs from 'node:fs' +import * as dotenv from 'dotenv' console.log('🔧 Configuring socialtree...') +dotenv.config() const app = express() -const port = 3000 +const port = process.env.PORT const engine = 'ejs' app.set('view engine', engine) diff --git a/yarn.lock b/yarn.lock index 43f696b..4b1b842 100644 --- a/yarn.lock +++ b/yarn.lock @@ -211,6 +211,11 @@ destroy@1.2.0: resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.2.0.tgz#4803735509ad8be552934c67df614f94e66fa015" integrity sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg== +dotenv@^16.0.3: + version "16.0.3" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.0.3.tgz#115aec42bac5053db3c456db30cc243a5a836a07" + integrity sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ== + ee-first@1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"