major: flatten the project

This commit is contained in:
Jean-Baptiste Pasquier
2020-11-26 23:21:55 +01:00
parent ebe46c6b6f
commit dee070596a
66 changed files with 11228 additions and 9483 deletions

21
internal/assets.js Normal file
View File

@ -0,0 +1,21 @@
const HTMLAsset = require('parcel-bundler/lib/assets/HTMLAsset')
function shouldIgnore (file) {
// Ignore img(src="${...}") on pug & keep the components folder pristine
return /\${.+}/.test(file) || /components/.test(file);
}
class SkipStartinbloxWidgetAsset extends HTMLAsset {
addDependency (name, opts) {
if (!shouldIgnore(opts.resolved)) {
return super.addDependency(name, opts)
}
}
processSingleDependency (p, opts) {
if (shouldIgnore(p)) return p
else return super.processSingleDependency(p, opts)
}
}
module.exports = SkipStartinbloxWidgetAsset

View File

@ -0,0 +1,26 @@
FROM python:3.6
LABEL maintainer="Plup <plup@plup.io>"
# get server address
ARG serve
# fix bug in manager install
ENV PATH="/root/.local/bin:${PATH}"
# install a LDP server with required functions
WORKDIR /app
RUN pip install git+https://git.startinblox.com/djangoldp-packages/server-manager.git
RUN sib startproject sibserver
COPY docker/packages.yml /app/sibserver/
RUN sed -i 's#SERVER#'"${serve:-http://localhost:8000}"'#' /app/sibserver/packages.yml
RUN cd /app/sibserver && sib install server
# fix invalid HTTP_HOST
RUN sed -i 's/ALLOWED_HOSTS\s=\s\[\]/ALLOWED_HOSTS=\["\*"\]/' /app/sibserver/server/settings.py
# run the dev server
EXPOSE 8000
ENTRYPOINT ["python", "/app/sibserver/manage.py"]
CMD ["runserver", "0.0.0.0:8000"]
# vim: ft=dockerfile:

View File

@ -0,0 +1,15 @@
---
version: '3'
services:
front:
environment:
- SERVER=http://127.0.0.1
ports:
- 80:80
server:
build:
args:
serve: http://127.0.0.1

View File

@ -0,0 +1,39 @@
---
version: '3'
services:
front:
build:
context: ../
dockerfile: docker/front.docker
environment:
- SERVER=http://server.org:8000
networks:
- web
server:
build:
context: ../
dockerfile: docker/djangoldp.docker
args:
serve: http://server.org:8000
networks:
web:
aliases:
- server.org
db:
e2e:
image: cypress/included:4.3.0
environment:
- CYPRESS_baseUrl=https://front
volumes:
- ../cypress:/cypress
- ../cypress.json:/cypress.json
networks:
- web
networks:
web:
db:

View File

@ -0,0 +1,37 @@
FROM node:12 AS builder
LABEL maintainer="Plup <plup@plup.io>"
# install dependencies
WORKDIR /build
ADD package.json package-lock.json ./
ADD src/ src/
RUN npm install --only=production
# build the app
ADD docker/config.json .
RUN npm run build
# change index to template
RUN mv /build/dist/index.html /build/dist/index.tpl
# generate a self signed certificate
RUN openssl req -x509 -newkey rsa:4096 -keyout /tmp/key.pem -out /tmp/cert.pem -days 365 -nodes -subj '/CN=localhost'
# serve
FROM nginx:latest
COPY --from=builder /build/dist /var/www
COPY --from=builder /tmp/*.pem /etc/nginx/
WORKDIR /var/www
# get specific config
COPY docker/nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 443
# get server address
ENV SERVER http://localhost:8000
# replace addresses at runtime
CMD /bin/bash -c "envsubst '\$SERVER' < index.tpl > index.html && \
exec nginx -g 'daemon off;'"
# vim: ft=dockerfile:

View File

@ -0,0 +1,9 @@
server {
listen 443 ssl default_server;
root /var/www/;
ssl_certificate /etc/nginx/cert.pem;
ssl_certificate_key /etc/nginx/key.pem;
try_files $uri $uri/ index.html =404;
}

View File

@ -0,0 +1,27 @@
ldppackages:
djangoldp_dashboard: djangoldp_dashboard
djangoldp_account: djangoldp_account
djangoldp_circle: djangoldp_circle
djangoldp_notification: djangoldp_notification
djangoldp_profile: djangoldp_profile
djangoldp_project: djangoldp_project
oidc_provider: 'git+https://github.com/jblemee/django-oidc-provider.git@develop'
server:
site_url: SERVER
allowed_hosts:
- '*'
db_host: database
db_name: postgres
db_user: postgres
db_pass: postgres
smtp_host:
smtp_user:
smtp_pass:
admin_email: test@startinblox.com
admin_name: admin
admin_pass: admin
xmpp_url: https://jabber.happy-dev.fr
jabber_host: 'none'
default_client: SERVER
registration_open: True

77
internal/parcel.js Normal file
View File

@ -0,0 +1,77 @@
'use strict';
const fs = require('fs');
const fse = require('fs-extra');
const Bundler = require('parcel-bundler');
const options = {
outDir: './dist',
outFile: 'index.html',
publicUrl: '/',
watch: process.env.NODE_ENV !== 'production',
cache: true,
cacheDir: '.cache',
contentHash: false,
minify: process.env.NODE_ENV === 'production',
scopeHoist: false,
target: 'browser',
bundleNodeModules: false,
https: true,
logLevel: 3,
hmr: true,
hmrPort: 1235,
sourceMaps: true,
hmrHostname: '',
detailedReport: false,
autoInstall: true
};
(async function() {
if(!fs.existsSync("config.json")) throw "[Error] (Mandatory) Missing config.json file";
let config = JSON.parse(fs.readFileSync('config.json'));
if(!config.clientName) throw "[Error] (Mandatory) Missing clientName on config.json";
if(!config.clientLogo) throw "[Error] (Mandatory) Missing clientLogo on config.json";
let manifest = {
"lang": "fr",
"dir": "ltr",
"name": config.clientName,
"description": `Hubl of ${config.clientName}`,
"short_name": config.clientName,
"icons": [{
"src": config.clientLogo,
"purpose": "any"
}, {
"src": "/images/hubl-icon-192.png",
"sizes": "192x192",
"type": "image/png"
}, {
"src": "/images/hubl-icon-512.png",
"sizes": "512x512",
"type": "image/png"
}],
"start_url": ".",
"display": "standalone",
"orientation": "portrait",
"background_color": "#fff",
'theme_color': "white"
}
await fse.writeJSON('./src/manifest.webmanifest', manifest)
console.log(`Created manifest for ${config.clientName}`);
await fse.copy("./src/locales", "./dist/locales")
console.log(`Copied locales to dist folder`);
await fse.copy("./src/components", "./dist/components")
console.log(`Copied components to dist folder`);
const bundler = new Bundler('./src/index.pug', options);
bundler.addAssetType('html', require.resolve('./assets.js'));
if(process.env.NODE_ENV !== 'production') {
await bundler.serve();
} else {
await bundler.bundle();
}
})();