diff --git a/deploy/docker/Dockerfile b/deploy/docker/Dockerfile index 8d68d29f4..421fb8c3e 100644 --- a/deploy/docker/Dockerfile +++ b/deploy/docker/Dockerfile @@ -1,21 +1,32 @@ +FROM python:3.8-alpine AS build + +WORKDIR /app +RUN python3 -m venv /app/venv +RUN /app/venv/bin/pip --no-cache-dir install wheel + +RUN apk add --no-cache libffi libffi-dev py3-cffi build-base python3-dev automake m4 autoconf libtool gcc g++ musl-dev openssl-dev cargo postgresql-dev + +COPY requirements.txt /app +RUN /app/venv/bin/pip --no-cache-dir install -r /app/requirements.txt + +COPY docker/plugins /app/plugins +ARG plugins +RUN for plugin in $plugins $(find /app/plugins -name 'setup.py' -exec dirname {} \; | sort -u); \ + do /app/venv/bin/pip --no-cache-dir install $plugin; done + FROM python:3.8-alpine LABEL maintainer="info@cert.pl" RUN apk add --no-cache postgresql-client postgresql-dev libmagic -COPY requirements.txt docker/plugins/requirements-*.txt /tmp/ -RUN apk add --no-cache -t build libffi libffi-dev py3-cffi build-base python3-dev automake m4 autoconf libtool gcc g++ musl-dev openssl-dev cargo \ - && pip --no-cache-dir install -r /tmp/requirements.txt \ - && ls /tmp/requirements-*.txt | xargs -i,, pip --no-cache-dir install -r ,, \ - && apk del build - # Copy backend files +COPY --from=build /app/venv /app/venv COPY docker/ setup.py MANIFEST.in requirements.txt /app/ COPY mwdb /app/mwdb/ # Install mwdb-core package -RUN pip install /app +RUN /app/venv/bin/pip install /app # Create a /app/uploads directory # Give +r to everything in /app and +x for directories @@ -28,7 +39,6 @@ RUN mkdir -p /app/uploads/ && \ ENV PYTHONPATH=/app ENV FLASK_APP=/app/mwdb/app.py -# How many workers gunicorn should spawn by default WORKDIR /app CMD ["/app/start.sh"] diff --git a/deploy/docker/Dockerfile-web b/deploy/docker/Dockerfile-web index 5ac895aa2..ff9b0c5e9 100644 --- a/deploy/docker/Dockerfile-web +++ b/deploy/docker/Dockerfile-web @@ -1,20 +1,25 @@ -FROM node:14 AS build +FROM node:16-alpine AS build + +LABEL maintainer="info@cert.pl" COPY ./mwdb/web /app -COPY ./docker/plugins /plugins +COPY ./docker/plugins /app/plugins +ARG web_plugins RUN cd /app \ - && npm install --unsafe-perm . $(find /plugins -name 'package.json' -printf "%h\n" | sort -u) \ + && npm install --unsafe-perm . $web_plugins $(find /app/plugins -name 'package.json' -exec dirname {} \; | sort -u) \ && CI=true npm run build \ && npm cache clean --force FROM nginx:stable +LABEL maintainer="info@cert.pl" + ENV PROXY_BACKEND_URL http://mwdb.:8080 COPY docker/nginx.conf.template /etc/nginx/conf.d/default.conf.template COPY docker/start-web.sh /start-web.sh -COPY --from=build /app/build /usr/share/nginx/html +COPY --from=build /app/dist /usr/share/nginx/html # Give +r to everything in /usr/share/nginx/html and +x for directories RUN chmod u=rX,go= -R /usr/share/nginx/html diff --git a/deploy/docker/Dockerfile-web-dev b/deploy/docker/Dockerfile-web-dev index 96efb7b29..169fc7204 100644 --- a/deploy/docker/Dockerfile-web-dev +++ b/deploy/docker/Dockerfile-web-dev @@ -1,14 +1,17 @@ -FROM node:14 AS build +FROM node:16-alpine AS build + +LABEL maintainer="info@cert.pl" COPY ./mwdb/web /app -COPY ./docker/plugins /plugins +COPY ./docker/plugins /app/plugins +ARG web_plugins RUN cd /app \ - && npm install --unsafe-perm . $(find /plugins -name 'package.json' -printf "%h\n" | sort -u) \ + && npm install --unsafe-perm . $web_plugins $(find /app/plugins -name 'package.json' -exec dirname {} \; | sort -u) \ && CI=true npm run build \ && npm cache clean --force ENV PROXY_BACKEND_URL http://mwdb.:8080 WORKDIR /app -CMD ["npm", "run", "start"] +CMD ["npm", "run", "dev"] diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index 78c7a3f51..35c78975b 100644 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -57,6 +57,7 @@ services: volumes: - "./mwdb/web/public:/app/public" - "./mwdb/web/src:/app/src" + - "./docker/plugins:/app/plugins" restart: on-failure postgres: image: postgres diff --git a/docker/start.sh b/docker/start.sh index 311cca452..4dc6497a9 100755 --- a/docker/start.sh +++ b/docker/start.sh @@ -7,4 +7,4 @@ until psql "$MWDB_POSTGRES_URI" -c "\q" ; do done echo "Configuring mwdb-core instance" -mwdb-core configure --quiet basic && exec gunicorn +/app/venv/bin/mwdb-core configure --quiet basic && exec /app/venv/bin/gunicorn diff --git a/mwdb/web/config-overrides.js b/mwdb/web/config-overrides.js deleted file mode 100644 index 2d9ee0e5c..000000000 --- a/mwdb/web/config-overrides.js +++ /dev/null @@ -1,81 +0,0 @@ -const { override, babelInclude, removeModuleScopePlugin, addWebpackModuleRule } = require('customize-cra'); -const fs = require("fs"); -const path = require('path'); - -const mwdbPackageNamespace = "@mwdb-web"; -const pluginPackagePrefix = "plugin-"; -const pluginsIndexFile = path.join(require.resolve("@mwdb-web/commons"), '..', 'extensions', 'plugins.js'); - -function findInstalledPlugins() { - let modules = {}; - const modulesDir = path.join(__dirname, "node_modules", mwdbPackageNamespace); - if(!fs.existsSync(modulesDir)) - return modules; - for(const pluginName of fs.readdirSync(modulesDir)) { - if(!pluginName.startsWith(pluginPackagePrefix)) - continue; - let realPath = path.join(modulesDir, pluginName); - try { - realPath = path.resolve(modulesDir, fs.readlinkSync(realPath)); - } catch(e) { - if(e.errno != -22 /* EINVAL */) - throw e; - } - modules[mwdbPackageNamespace + "/" + pluginName] = realPath; - } - return modules; -} - -function getPluginPaths(plugins) { - return Object.values(plugins) -} - -function getPluginLoaders(plugins) { - const moduleNames = Object.keys(plugins) - return moduleNames.map((moduleName) => ({ - loader: 'imports-loader', - options: { - imports: [ - { - moduleName, - name: moduleName.split("/")[1].slice(pluginPackagePrefix.length) - } - ] - } - })).concat({ - loader: 'exports-loader', - options: { - exports: moduleNames.map((moduleName) => ({ - syntax: 'named', - name: moduleName.split("/")[1].slice(pluginPackagePrefix.length) - })) - } - }) -} - -const plugins = findInstalledPlugins(); - -for(const pluginName of Object.keys(plugins)) { - console.log("[plugins] Found plugin " + pluginName); -} - -module.exports = { - webpack: override( - removeModuleScopePlugin(), - babelInclude([path.join(__dirname, 'src')].concat(getPluginPaths(plugins))), - ( - /* If there are plugins: add loaders */ - Object.keys(plugins).length - ? addWebpackModuleRule( - { - test: pluginsIndexFile, - use: getPluginLoaders(plugins) - } - ) - : (_ => _) - ) - ), - optimization: { - minimize: process.env.NODE_ENV == 'development' - } -} \ No newline at end of file diff --git a/mwdb/web/public/index.html b/mwdb/web/index.html similarity index 76% rename from mwdb/web/public/index.html rename to mwdb/web/index.html index 101af6b0d..689ec5da7 100644 --- a/mwdb/web/public/index.html +++ b/mwdb/web/index.html @@ -4,8 +4,6 @@ - -