Restructured Dockerfile so it can build DEVELOPMENT and PRODUCTION modes

Signed-off-by: James Ketrenos <james_git@ketrenos.com>
This commit is contained in:
James Ketr 2023-01-20 13:47:37 -08:00
parent fea610797d
commit 179d8e98f3
4 changed files with 104 additions and 69 deletions

View File

@ -6,18 +6,18 @@
!*.sh !*.sh
!*.md !*.md
!config !config
!client
client/node_modules
!frontend !frontend
frontend/bower_modules
!server !server
server/node_modules
!scanner !scanner
!src !src
!util !util
!ketrface !ketrface
!client
!scripts !scripts
!Dockerfile !Dockerfile
!entrypoint.sh !entrypoint.sh
node_modules node_modules
frontend/bower_modules
client/node_modules
server/node_modules

View File

@ -1,5 +1,8 @@
ARG DEVELOPMENT= ARG DEVELOPMENT=
#
# Base Ubuntu image with nodejs installed
#
FROM ubuntu:jammy AS base FROM ubuntu:jammy AS base
RUN apt-get update \ RUN apt-get update \
@ -17,6 +20,10 @@ RUN DEBIAN_FRONTEND=NONINTERACTIVE apt-get install -y \
# Install the latest npm and npx # Install the latest npm and npx
RUN npm install --global npm@latest RUN npm install --global npm@latest
#
# 'production' is used as a COPY source when building
# DEVELOPMENT mode (via website1 image)
#
FROM base AS production FROM base AS production
RUN DEBIAN_FRONTEND=NONINTERACTIVE apt-get install -y \ RUN DEBIAN_FRONTEND=NONINTERACTIVE apt-get install -y \
@ -28,8 +35,8 @@ RUN npm upgrade && npm install
COPY /.babelrc /*.html /*.js /website/ COPY /.babelrc /*.html /*.js /website/
COPY /src /website/src COPY /src /website/src
COPY /frontend /website/frontend COPY /frontend /website/frontend
RUN cat package.json
RUN npm run build RUN npm run build
RUN ls -altr /website
WORKDIR /website/client WORKDIR /website/client
COPY /client/*.json /website/client/ COPY /client/*.json /website/client/
@ -38,20 +45,12 @@ COPY /client/*.js /website/client/
COPY /client/public /website/client/public COPY /client/public /website/client/public
COPY /client/src /website/client/src COPY /client/src /website/client/src
RUN npm run build RUN npm run build
RUN ls -altr /website/client
RUN echo $DEVELOPMENT
FROM base AS runtime1
ONBUILD COPY --from=production /website/dist /website/dist
ONBUILD COPY --from=production /website/*.html /website/
ONBUILD COPY --from=production /website/client/*.html /website/client/
ONBUILD COPY --from=production /website/client/dist /website/client/dist
#
# 'runtime' is the bulk of the DeepFace infrastructure
#
FROM base AS runtime FROM base AS runtime
FROM runtime${DEVELOPMENT}
RUN DEBIAN_FRONTEND=NONINTERACTIVE apt-get install -y \ RUN DEBIAN_FRONTEND=NONINTERACTIVE apt-get install -y \
pip \ pip \
libgl1 \ libgl1 \
@ -82,33 +81,39 @@ COPY /server /website/server
WORKDIR /website/server WORKDIR /website/server
RUN npm install RUN npm install
COPY /config/default.json /website/config/default.json # Copy the Python face management scripts
COPY /ketrface /website/ketrface COPY /ketrface /website/ketrface
#
# 'website' is used if DEVELOPMENT is not set (PRODUCTION)
#
FROM runtime AS website
RUN "Building PRODUCTION"
COPY /server/production.location /etc/nginx/snippets/active.location
COPY --from=production /website/dist /website/dist
COPY --from=production /website/*.html /website/
COPY --from=production /website/client/build /website/client/build
#
# 'website1' is used if DEVELOPMENT=1
#
FROM runtime AS website1
RUN echo "Building DEVELOPMENT"
COPY /server/development.location /etc/nginx/snippets/active.location
#
# This is the final image stage pulling together 'runtime' and the
# appropriate website build (website or website1)
#
FROM website${DEVELOPMENT} AS final
COPY /config/default.json /website/config/default.json
# Switch to bash instead of sh # Switch to bash instead of sh
SHELL [ "/bin/bash", "-c" ] SHELL [ "/bin/bash", "-c" ]
RUN cp /website/server/nginx.conf /etc/nginx/sites-enabled/default RUN cp /website/server/nginx.conf /etc/nginx/sites-enabled/default
# If not DEVELOPMENT mode, copy production config, else development
RUN \
if [[ -z "${DEVELOPMENT}" ]]; then \
echo "Building PRODUCTION" ; \
cp /website/server/production.location \
/etc/nginx/snippets/active.location ; \
else \
echo "Building DEVELOPMENT" ; \
cp /website/server/development.location \
/etc/nginx/snippets/active.location ; \
fi
# If not DEVELOPMENT mode, then locally build project
RUN \
if [[ -z "${DEVELOPMENT}" ]]; then \
cd /website/client ; \
npm run build ; \
fi
COPY /scripts /opt/scripts COPY /scripts /opt/scripts
ENV PATH="${PATH}:/opt/scripts" ENV PATH="${PATH}:/opt/scripts"

View File

@ -1,20 +1,13 @@
{ {
"name": "photos.ketr", "name": "ketr-photos-frontend",
"version": "1.0.0", "version": "1.0.0",
"description": "Self hosting photo", "description": "ketr-photos frontend",
"main": "server/app.js",
"scripts": { "scripts": {
"start": "node ./server/app.js",
"start-devel": "concurrently \"npm:server\" \"npm:dev\"", "start-devel": "concurrently \"npm:server\" \"npm:dev\"",
"server": "node ./server/app.js",
"faces": "node ./server/face-recognizer.js",
"dev": "webpack-dev-server --mode development --host 0.0.0.0 --config webpack.dev.js", "dev": "webpack-dev-server --mode development --host 0.0.0.0 --config webpack.dev.js",
"build": "webpack --config webpack.prod.js", "build": "webpack --config webpack.prod.js",
"debug": "node --inspect --debug-brk ./server/app.js", "debug": "node --inspect --debug-brk ./server/app.js",
"commit-build": "./commit-build.sh", "watch": "webpack --config webpack.prod.js --watch"
"watch": "webpack --config webpack.prod.js --watch",
"update": "./update.sh",
"backend": "NODE_CONFIG_ENV='production' node server/app.js"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -22,39 +15,20 @@
}, },
"author": "James Ketrenos", "author": "James Ketrenos",
"license": "Apache-2.0", "license": "Apache-2.0",
"unused": {
"face-recognition": "^0.9.4"
},
"dependencies": { "dependencies": {
"bluebird": "^3.7.2", "bootstrap": "^5.2.3",
"body-parser": "^1.20.1",
"bootstrap": "^4.4.1",
"concurrently": "^5.1.0", "concurrently": "^5.1.0",
"config": "^3.3.8", "config": "^3.3.8",
"connect-sqlite3": "^0.9.13",
"cookie-parser": "^1.4.4",
"core-js": "^3.2.1",
"exif-reader": "github:paras20xx/exif-reader",
"express": "^4.18.2",
"express-session": "^1.17.0",
"file-loader": "^6.2.0", "file-loader": "^6.2.0",
"googleapis": "^110.0.0",
"handlebars": "^4.7.7",
"ldapauth-fork": "=4.2.0",
"ldapjs": "^1.0.2",
"moment": "^2.29.4", "moment": "^2.29.4",
"moment-holiday": "^1.5.1", "moment-holiday": "^1.5.1",
"morgan": "^1.9.1",
"mustache": "^3.2.1",
"node-fetch": "^2.6.7", "node-fetch": "^2.6.7",
"node-gzip": "^1.1.2", "node-gzip": "^1.1.2",
"nodemailer": "^6.8.0", "nodemailer": "^6.8.0",
"react-app-polyfill": "^3.0.0", "react-app-polyfill": "^3.0.0",
"react-bootstrap": "^1.0.0-beta.16", "react-bootstrap": "^1.6.6",
"react-date-range": "^1.0.0-beta", "react-date-range": "^1.0.0-beta",
"react-router-dom": "^5.0.1", "react-router-dom": "^5.0.1"
"sequelize": "^6.0",
"sharp": "^0.31.3"
}, },
"devDependencies": { "devDependencies": {
"@babel/cli": "^7.20.7", "@babel/cli": "^7.20.7",

56
server/package.json Normal file
View File

@ -0,0 +1,56 @@
{
"name": "ketr-photos-server",
"version": "1.0.0",
"description": "Self hosting photo",
"main": "server/app.js",
"scripts": {
"start": "node .app.js",
"start-devel": "concurrently \"npm:server\" \"npm:dev\"",
"server": "node ./app.js",
"debug": "node --inspect --debug-brk ./app.js",
"backend": "NODE_CONFIG_ENV='production' node app.js"
},
"repository": {
"type": "git",
"url": "git@nuc:jketreno/photos.ketr.git"
},
"author": "James Ketrenos",
"license": "Apache-2.0",
"dependencies": {
"bluebird": "^3.7.2",
"body-parser": "^1.20.1",
"bootstrap": "^4.4.1",
"concurrently": "^5.1.0",
"config": "^3.3.8",
"connect-sqlite3": "^0.9.13",
"cookie-parser": "^1.4.4",
"core-js": "^3.2.1",
"exif-reader": "github:paras20xx/exif-reader",
"express": "^4.18.2",
"express-session": "^1.17.0",
"file-loader": "^6.2.0",
"googleapis": "^110.0.0",
"handlebars": "^4.7.7",
"ldapauth-fork": "=4.2.0",
"ldapjs": "^1.0.2",
"moment": "^2.29.4",
"moment-holiday": "^1.5.1",
"morgan": "^1.9.1",
"mustache": "^3.2.1",
"node-fetch": "^2.6.7",
"node-gzip": "^1.1.2",
"nodemailer": "^6.8.0",
"react-app-polyfill": "^3.0.0",
"react-bootstrap": "^1.0.0-beta.16",
"react-date-range": "^1.0.0-beta",
"react-router-dom": "^5.0.1",
"sequelize": "^6.0",
"sharp": "^0.31.3"
},
"jshintConfig": {
"undef": true,
"unused": true,
"esversion": 6,
"node": true
}
}