From d078e20aa3612a041b6204f9c1bfa933a52c9b56 Mon Sep 17 00:00:00 2001 From: nikurasu Date: Fri, 28 Oct 2022 14:39:35 +0200 Subject: [PATCH] First steps of dockerisation --- {config => assets/config}/config.yml | 0 {src/assets => assets}/img/profilepic.jpg | Bin dev/docker/images/main/Dockerfile | 13 +++++++++++++ dev/shell/entrypoint.sh | 8 ++++++++ package.json | 11 +++++++---- src/index.js | 4 ++-- yarn.lock | 21 ++++++++++++++++++++- 7 files changed, 50 insertions(+), 7 deletions(-) rename {config => assets/config}/config.yml (100%) rename {src/assets => assets}/img/profilepic.jpg (100%) create mode 100644 dev/docker/images/main/Dockerfile create mode 100644 dev/shell/entrypoint.sh diff --git a/config/config.yml b/assets/config/config.yml similarity index 100% rename from config/config.yml rename to assets/config/config.yml diff --git a/src/assets/img/profilepic.jpg b/assets/img/profilepic.jpg similarity index 100% rename from src/assets/img/profilepic.jpg rename to assets/img/profilepic.jpg diff --git a/dev/docker/images/main/Dockerfile b/dev/docker/images/main/Dockerfile new file mode 100644 index 0000000..9a9e48d --- /dev/null +++ b/dev/docker/images/main/Dockerfile @@ -0,0 +1,13 @@ +FROM node:lts-alpine +LABEL maintainer="nikurasu_tan publicmail@nikurasu.gay" +WORKDIR /app +COPY src/ ./src +COPY package.json ./ +COPY yarn.lock ./ +COPY assets /assets +COPY dev/shell/entrypoint.sh /entrypoint.sh +RUN yarn +RUN yarn clean +RUN yarn build-prod +EXPOSE 3000 +ENTRYPOINT ["/bin/sh", "/entrypoint.sh"] \ No newline at end of file diff --git a/dev/shell/entrypoint.sh b/dev/shell/entrypoint.sh new file mode 100644 index 0000000..430cf11 --- /dev/null +++ b/dev/shell/entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/sh +if [[ ! -d "/app/assets/config" ]] && [[ ! -d "/app/assets/img" ]]; then + echo "No config found, installing default files" + cp -R /assets/ /app/assets +fi + +echo "Starting node application" +yarn start \ No newline at end of file diff --git a/package.json b/package.json index adee496..c5f77b9 100644 --- a/package.json +++ b/package.json @@ -9,17 +9,20 @@ "scripts": { "start": "node src/index.js", "dev": "nodemon src/index.js & $npm_execpath run watch-css", + "clean": "rimraf src/dist", "watch-css": "run-when-changed --watch 'src/public/themes/*.scss' --watch 'src/public/util/*.scss' --exec '$npm_execpath run build'", - "build": "sass src/public/themes:src/dist/style & echo \"🎨 Rebuilded your css\"" + "build": "sass src/public/themes:src/dist/style & echo \"🎨 Rebuilded your css\"", + "build-prod": "sass --style=compressed src/public/themes:src/dist/style" }, "dependencies": { "ejs": "^3.1.8", "express": "^4.18.2", - "js-yaml": "^4.1.0", - "sass": "^1.55.0" + "js-yaml": "^4.1.0" }, "devDependencies": { "nodemon": "^2.0.20", - "run-when-changed": "^2.1.0" + "rimraf": "^3.0.2", + "run-when-changed": "^2.1.0", + "sass": "^1.55.0" } } diff --git a/src/index.js b/src/index.js index 441d37c..91325ef 100644 --- a/src/index.js +++ b/src/index.js @@ -11,10 +11,10 @@ const engine = 'ejs' app.set('view engine', engine) app.set('views', './src/views') app.use(express.static('src/dist')) -app.use(express.static('src/assets')) +app.use(express.static('assets')) app.get('/', (req, res) => { - let config = yaml.load(fs.readFileSync('config/config.yml'), 'utf8') + let config = yaml.load(fs.readFileSync('assets/config/config.yml'), 'utf8') res.render('index', { name: config.name, filenameProfilePic: config.profilePic ? config.profilePic : 'profilepic.jpg', diff --git a/yarn.lock b/yarn.lock index 4fe0ec9..43f696b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -362,6 +362,18 @@ glob-parent@~5.1.2: dependencies: is-glob "^4.0.1" +glob@^7.1.3: + version "7.2.3" + resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.3.tgz#b8df0fb802bbfa8e89bd1d938b4e16578ed44f2b" + integrity sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q== + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^3.1.1" + once "^1.3.0" + path-is-absolute "^1.0.0" + glob@~7.1.1: version "7.1.7" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.7.tgz#3b193e9233f01d42d0b3f78294bbeeb418f94a90" @@ -529,7 +541,7 @@ mime@1.6.0: resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1" integrity sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg== -minimatch@^3.0.4, minimatch@^3.1.2: +minimatch@^3.0.4, minimatch@^3.1.1, minimatch@^3.1.2: version "3.1.2" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b" integrity sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw== @@ -674,6 +686,13 @@ readdirp@~3.6.0: dependencies: picomatch "^2.2.1" +rimraf@^3.0.2: + version "3.0.2" + resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.2.tgz#f1a5402ba6220ad52cc1282bac1ae3aa49fd061a" + integrity sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA== + dependencies: + glob "^7.1.3" + run-when-changed@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/run-when-changed/-/run-when-changed-2.1.0.tgz#2e76d6ff6014d38786a3a11b98e9291c7e934953"