diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..382309e35fa84e894073c495ef2a83086dd5b310 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.vscode +node_modules +.env \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..8ff85a65353b1ec1ad4af0e91aea36781379bdc7 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,29 @@ +stages: + - build + +build_development: + stage: build + tags: + - build + only: + - development + script: + - export TAG=$CI_COMMIT_SHORT_SHA + - export RENDERTRON_BIND_PORT=3200 + - docker-compose build + - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY + - docker-compose push + #- 'curl -X POST -F token=$CI_JOB_TOKEN -F ref=master -F variables[TAG]=${TAG} https://forge.grandlyon.com/api/v4/projects/336/trigger/pipeline' + +build_release: + stage: build + tags: + - build + only: + - tags + script: + - export TAG=$(echo $CI_COMMIT_TAG | sed 's/v//g') + - export RENDERTRON_BIND_PORT=3200 + - docker-compose build + - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY + - docker-compose push diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..b7b0f26407c6c89d62652d7f437a97a1e07933eb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +FROM node:12-stretch + +# install Chrome +RUN apt-get update \ + && apt-get install -y wget gnupg \ + && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \ + && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \ + && apt-get update \ + && apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 \ + --no-install-recommends \ + && rm -rf /var/lib/apt/lists/* + + +RUN git clone https://github.com/GoogleChrome/rendertron.git + +WORKDIR /rendertron + +RUN npm install && npm run build + +#ADD make-config-from-env.js . +#ADD entrypoint.sh . + +ADD start.sh config.json.template config.py ./ +RUN mkdir /cache + +EXPOSE 3000 +VOLUME ["/cache"] + +CMD ["./start.sh"] + + diff --git a/README.md b/README.md index 12bcdd1954efa79a3571322e33cfb3f6eacaedcb..55346109db549982bd38fc59a4fce0121366b5b6 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,30 @@ -# rendertron +# Rendertron +## Installation + +Docker image for rendertron (https://github.com/GoogleChrome/rendertron) + +## Environment variables + +In order to run the code, some environment variables are needed. They are specified in the `template.env` file at the root of the project. + +For a local deployment: + +1. `cp template.env .env` +2. Edit .env according to the chosen configuration + +The values will be read from the file by default when running with docker. If you run the service outside of docker you can export those variables. + + +## Running the app with docker + +```bash +# build +docker-compose build + +# deploy +docker-compose up [-d] + +# build and deploy +docker-compose up --build [-d] +``` diff --git a/config.json b/config.json new file mode 100644 index 0000000000000000000000000000000000000000..e9773022aeea492292e9d03787f416dc9c5a182d --- /dev/null +++ b/config.json @@ -0,0 +1,21 @@ +{ + "timeout": 10000, + "port": 3000, + "host": "0.0.0.0", + "width": 1000, + "height": 1000, + "reqHeaders": {}, + "cache": "filesystem", + "cacheConfig": { + "cacheDurationMinutes": 86400, + "cacheMaxEntries": 1000, + "snapshotDir": "/cache" + }, + "renderOnly": [ + "https://data.grandlyon.com", + "https://preprod.data.grandlyon.com", + "https://portail-dev.grandlyon.neogeo.fr" + ], + "closeBrowserdefault": false, + "restrictedUrlPatterndefault": null +} diff --git a/config.json.template b/config.json.template new file mode 100644 index 0000000000000000000000000000000000000000..1b0a358a5f7b460e243475c10c860488f1ea5891 --- /dev/null +++ b/config.json.template @@ -0,0 +1,18 @@ +{ + "timeout": 10000, + "port": 3000, + "host": "0.0.0.0", + "width": 1000, + "height": 1000, + "reqHeaders": {}, + "cache": "filesystem", + "cacheConfig": { + "cacheDurationMinutes": 86400, + "cacheMaxEntries": 1000, + "snapshotDir": "/cache" + }, + "renderOnly": [ + ], + "closeBrowserdefault": false, + "restrictedUrlPatterndefault": null +} diff --git a/config.py b/config.py new file mode 100755 index 0000000000000000000000000000000000000000..4286114044a1e6eabaf4c0facd14b1efc85fc8e0 --- /dev/null +++ b/config.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 +import os +import json +import sys + +URL_ALLOWED = os.environ.get("URL_ALLOWED") + +if not URL_ALLOWED: + print("Missing value : environment variable URL_ALLOWED") + sys.exit(1) + +with open('config.json.template') as template: + config = json.load(template) + +config['renderOnly'] = URL_ALLOWED.split(',') + +with open('config.json', 'w') as output_file: + json.dump(config, output_file) + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000000000000000000000000000000000000..bd71111e8806d0d60508f3c63d9d6a3c0714a5b5 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,18 @@ +version: "3" + +services: + rendertron: + build: . + image: registry.forge.grandlyon.com/web-et-numerique/web-et-numerique-internet/data.grandlyon.com/web-portal/components/off-the-shelf-apps/rendertron:${TAG} + ports: + - ${RENDERTRON_BIND_PORT}:3000 + environment: + - URL_ALLOWED=${URL_ALLOWED} + restart: unless-stopped + volumes: + - rendertron_cache:/cache + +volumes: + rendertron_cache: + + diff --git a/start.sh b/start.sh new file mode 100755 index 0000000000000000000000000000000000000000..7bcb95a121a0661341a1f1ffc207727a757d5c64 --- /dev/null +++ b/start.sh @@ -0,0 +1,5 @@ +#!/bin/bash -e + +./config.py + +npm run start diff --git a/template.env b/template.env new file mode 100644 index 0000000000000000000000000000000000000000..1cfb44cd51862b30178ec069bb8b22ed933db790 --- /dev/null +++ b/template.env @@ -0,0 +1,3 @@ +TAG=<tag of the image to be used> +RENDERTRON_BIND_PORT=<proxy port> +URL_ALLOWED=<urls allowed to be rendered (comma separated value for multiple values)>