From 59651d3cb9f6082f29381f6882564fdb6c90d3a2 Mon Sep 17 00:00:00 2001 From: Paul Bienkowski Date: Mon, 27 Sep 2021 18:54:02 +0200 Subject: [PATCH] add production setup --- api/Dockerfile | 8 +++++++- api/config.json.example | 20 ++++++++++---------- frontend/Dockerfile-prod | 34 ++++++++++++++++++++++++++++++++++ frontend/apache/.htaccess | 6 ++++++ frontend/public/config.json | 11 +++++++++++ 5 files changed, 68 insertions(+), 11 deletions(-) create mode 100644 frontend/Dockerfile-prod create mode 100644 frontend/apache/.htaccess mode change 100755 => 100644 frontend/public/config.json diff --git a/api/Dockerfile b/api/Dockerfile index f10db7e..13305bd 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -17,6 +17,12 @@ RUN cd scripts && pip install -e . ADD views /opt/obs/api/views/ ADD src /opt/obs/api/src/ +#ADD .migrations.js . +#ADD migrations . + EXPOSE 3000 + ENV PORT=3000 -CMD ["npm", "start"] +ENV DATA_DIR=/data + +CMD ["npm", "run", "start"] \ No newline at end of file diff --git a/api/config.json.example b/api/config.json.example index d20310d..564da02 100644 --- a/api/config.json.example +++ b/api/config.json.example @@ -1,8 +1,8 @@ { - "cookieSecret": "CHANGEME!!!!!!!!!!!!!!!!!!!!!11", - "jwtSecret": "CHANGEME???????????????????////", - "baseUrl": "https://openbikesensor.example.com/", - "mainFrontendUrl": "https://openbikesensor.example.com/api/", + "cookieSecret": "!!!<<>>!!!", + "jwtSecret": "!!!<<>>!!!", + "baseUrl": "https://api.example.com/", + "mainFrontendUrl": "https://portal.example.com/", "mail": { "from": "Sender Name ", "smtp" : { @@ -10,24 +10,24 @@ "port": 465, "starttls": false, "username": "sender@example.com", - "password": "hunter2" + "password": "!!!<<>>!!!" } }, "mongodb": { - "url": "mongodb://user:pass@host/obs", + "url": "mongodb://mongo/obs", "debug": false }, - "redisUrl": "redis://localhost", + "redisUrl": "redis://redis", "oAuth2Clients": [ { - "clientId": "CHANGEME", - "validRedirectUris": ["https://site.example.com/redirect"], + "clientId": "!!!<<>>!!!", + "validRedirectUris": ["https://portal.example.com/redirect"], "refreshTokenExpirySeconds": 604800, "maxScope": "*", "title": "OBS Portal" }, { - "clientId": "CHANGEME", + "clientId": "!!!<<>>!!!", "validRedirectUris": ["__LOCAL__"], "maxScope": "track.upload", "refreshTokenExpirySeconds": 86400000, diff --git a/frontend/Dockerfile-prod b/frontend/Dockerfile-prod new file mode 100644 index 0000000..805ee9b --- /dev/null +++ b/frontend/Dockerfile-prod @@ -0,0 +1,34 @@ +############################################# +# Build the frontend AS builder +############################################# + +FROM node:14 as builder + +WORKDIR /opt/obs/frontend +ADD package.json package-lock.json /opt/obs/frontend/ +RUN echo update-notifier=false >> ~/.npmrc +RUN npm ci + +ADD tsconfig.json craco.config.js /opt/obs/frontend/ +ADD public/ /opt/obs/frontend/public/ +ADD src/ /opt/obs/frontend/src/ + +# [Optional] Add the URL prefix. It must also be set in the docker-compose.yml +# ENV PUBLIC_URL=/prefix + +RUN npm run build + +############################################# +# Serve the frontend +############################################# + +# Use apache +FROM httpd:2.4 +# Enable rewrite_module +RUN sed -i '/LoadModule rewrite_module/s/^#//g' /usr/local/apache2/conf/httpd.conf +# Allow .htaccess within /usr/local/apache2/htdocs +RUN sed -i '//,/<\/Directory>/ s/AllowOverride None/AllowOverride all/' /usr/local/apache2/conf/httpd.conf + +COPY --from=builder /opt/obs/frontend/build /usr/local/apache2/htdocs +COPY apache/.htaccess /usr/local/apache2/htdocs/ +RUN chmod -R a+rX /usr/local/apache2/htdocs diff --git a/frontend/apache/.htaccess b/frontend/apache/.htaccess new file mode 100644 index 0000000..ad1af50 --- /dev/null +++ b/frontend/apache/.htaccess @@ -0,0 +1,6 @@ +# @see: https://create-react-app.dev/docs/deployment/#serving-apps-with-client-side-routing + +Options -MultiViews +RewriteEngine On +RewriteCond %{REQUEST_FILENAME} !-f +RewriteRule ^ index.html [QSA,L] \ No newline at end of file diff --git a/frontend/public/config.json b/frontend/public/config.json old mode 100755 new mode 100644 index e69de29..222eb3b --- a/frontend/public/config.json +++ b/frontend/public/config.json @@ -0,0 +1,11 @@ +{ + "apiUrl": "https://api.example.com", + "auth": { + "server": "https://api.example.com", + "clientId": "!!!<<>>!!!", + "scope": "*", + "redirectUri": "https://portal.example.com/redirect" + }, + "imprintUrl": "https://portal.example.com/imprint", + "privacyPolicyUrl": "https://portal.example.com/privacy" +}