diff --git a/.env.example b/.env.example index 2672b9e..dd1bfb7 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,11 @@ +WIKI_BASE_URI=https://wiki.planet-casio.com WIKI_EN_SECRET_KEY= -WIKI_EN_UPGRADE_KEY= +# WIKI_EN_UPGRADE_KEY= WIKI_FR_SECRET_KEY= -WIKI_FR_UPGRADE_KEY= -WIKI_DB_PASSWORD= -DEBUG=0 \ No newline at end of file +# WIKI_FR_UPGRADE_KEY= +WIKI_DB_ROOT_PASSWORD= +WIKI_DB_WIKI_PASSWORD= +# WIKI_DEBUG=1 +HTTP_BIND=127.0.0.1:8000 +WIKI_HOSTNAME=wiki.planet-casio.com +TOOLS_HOSTNAME=tools.planet-casio.com \ No newline at end of file diff --git a/README.md b/README.md index 6d060f7..4244003 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,17 @@ Docker compose sources to start planete-casio's wiki and tools +## Volumes + +The wiki is the only statefull tool of this setup. All the data will be stored in volumes that will be in the `volumes` directory. + +* `mariadb-wiki` : This is the raw storage of the db. Don't delete this. Avoid copying this between mysql versions, use SQL dumps instead. +* `wiki-fr-images` and `wiki-en-images` : Upload storages of the wiki. You have to restore this if you restore the db. It also contains some image caches. +* `wiki-fr-cache` and `wiki-en-caches` : This is a cache used by the wiki to avoid recomputing all pages for all users. You can safely delete this volume. + ## Deployment -Firt install the last version of [docker](https://docs.docker.com/install/) and [docker-compose](https://docs.docker.com/compose/install/) on the server. - +First, install the last version of [docker](https://docs.docker.com/install/) and [docker-compose](https://docs.docker.com/compose/install/) on the server. ### Clone the repo @@ -32,9 +39,28 @@ The docker-compose configuration is stored into a `.env` file at the root of the ``` cp .env.example .env +# Then edit .env ``` -TODO configuration description +The following keys are required: + +* `WIKI_BASE_URI`: Wiki base uri with protocol, hostname and port. For instance `https://wiki.planet-casio.com` or `http://wiki.local:8080` +* `WIKI_EN_SECRET_KEY` and `WIKI_FR_SECRET_KEY`: [Secret key](https://www.mediawiki.org/wiki/Manual:$wgSecretKey) of the wiki. Should be a 64-character random string. +* `WIKI_DB_ROOT_PASSWORD`: Password of the `root` user on the database that can, for instance, create other users on the DB. +* `WIKI_DB_WIKI_PASSWORD`: Password of the `wiki` user on the database. This account is used by the application and can only edit the `wiki` database. +* `HTTP_BIND`: Port and address on which we will bind the http server + * This docker compose doesn't support https, so we will generally expose it only to localhost on a given port to have another local server http using it on the host. For instance on port `8000`: `127.0.0.1:8000`. + * If you want to test the server remotely without having another http server, you can expose it directly to the outside world by giving only a port number : `8000`. +* `WIKI_HOSTNAME`: Hostname(s) on which the wiki will be hosted. You can use multiple hostnames by splitting them with spaces. +* `TOOLS_HOSTNAME`: Hostname(s) on which the tools will be hosted. You can use multiple hostnames by splitting them with spaces. + +The following keys are optionnal: + +* `WIKI_EN_UPGRADE_KEY` and `WIKI_FR_UPGRADE_KEY`: [Upgrade password](https://www.mediawiki.org/wiki/Manual:$wgUpgradeKey) of the wiki. Should be a random non-guessable password. Should be left empty when upgrade is not in progress. +* `WIKI_DEBUG`: Enable the debug mode of the wiki if set to 1. To disable debug mode, leave it empty. When enabled it activates: + * The debug log in `(fr|en)/cache/debug.log` + * Show php and sql errors + * Show details and backtrace of exceptions ### Start the server for the first time @@ -61,6 +87,58 @@ mariadb-wiki_1 | 2020-01-02 23:16:21+00:00 [Note] [Entrypoint]: MySQL init p mariadb-wiki_1 | 2020-01-02 23:16:21 0 [Note] mysqld: ready for connections. ``` +Once the database started, the tools should work as expected. However you should get the following error on the wiki + +``` +MediaWiki internal error. +``` + +This is generally because the wiki database has not been filled with a structure. If you want to get more details, you can restart the `docker-compose` with `DEBUG=1` in the `.env` file. + +### Init the wiki + +To init the wiki you will need a mysql dump of the current wiki. We don't have one without personnal data, but if really needed this might be created and upload to this repo. + +First, dump the current database with somehting like this + +``` +# This should ask you the password of the use `wiki` and create the dump +mysqldump -h old-pc-sql.net.labate.me -u wiki -p wiki > dump-wiki.sql +# This might take some time.. +``` + +Second, restore it to the container. Note that the `wikì` database should already be created so you have to ̀`use` it. + +``` +# We will first copy the dump into the container +docker cp dump-wiki.sql tools-compose_mariadb-wiki_1:/ + +# Then start restore the file into the db +docker exec -it tools-compose_mariadb-wiki_1 bash -c 'mysql -u root -p wiki < /dump-wiki.sql' +# Give the WIKI_DB_ROOT_PASSWORD as password + +# If it worked, we can delete the file from the container +docker exec -it tools-compose_mariadb-wiki_1 rm /dump-wiki.sql +``` + +Third, we also need to restore images from the current server + +``` +# In my case I will use direct rsync, but we don't care about the method, we only need to copy them +# take /var/www/main/(fr|en)/images content and put it into ./volumes/wiki-(fr|en)-images +rsync -vr old-pc-wiki.net.labate.me:/var/www/main/fr/images/ ./volumes/wiki-fr-images/ +rsync -vr old-pc-wiki.net.labate.me:/var/www/main/en/images/ ./volumes/wiki-en-images/ +``` + +Once everything has been copied, restart the `docker-compose up` to fix permissions on images directories. + +We can also ask MediaWiki to purge caches for all pages + +``` +docker exec -it tools-compose_phpfpm-wiki_1 php /www/wiki/fr/maintenance/purgeList.php --purge --all +docker exec -it tools-compose_phpfpm-wiki_1 php /www/wiki/en/maintenance/purgeList.php --purge --all +``` + ### Start it for real If you want to start containers without beeing locked into the logs, start @@ -75,5 +153,8 @@ You can still go watch the logs by doing docker-compose logs -f ``` -### Debug mode -TODO \ No newline at end of file +## Troubleshoot + +TODO explain password set in mysql +TODO Debug mode + Phpmyadmin +TODO port exposition \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 6be24cc..e263025 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,11 +3,13 @@ services: nginx: image: nginx:latest ports: - - "8080:80" + - "${HTTP_BIND}:80" networks: - php-fpm + environment: + WIKI_HOSTNAME: "${WIKI_HOSTNAME}" + TOOLS_HOSTNAME: "${TOOLS_HOSTNAME}" volumes: - - ./nginx.conf:/etc/nginx/conf.d/default.conf - ./src/EactMaker:/www/EactMaker/ - ./src/SH4compatibilityTool:/www/SH4compatibilityTool/ - ./src/G1rFxiTools:/www/G1rFxiTools/ @@ -19,6 +21,12 @@ services: - ./src/pcgenerator:/www/pcgenerator/ - ./src/home:/www/home/ - ./src/wiki:/www/wiki/ + - ./volumes/wiki-fr-images:/www/wiki/fr/images/ + - ./volumes/wiki-en-images:/www/wiki/en/images/ + - ./volumes/wiki-fr-cache:/www/wiki/fr/cache/ + - ./volumes/wiki-en-cache:/www/wiki/en/cache/ + - ./nginx.conf.template:/opt/nginx.conf.template + command: /bin/bash -c "envsubst '$$WIKI_HOSTNAME,$$TOOLS_HOSTNAME' < /opt/nginx.conf.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'" phpfpm-main: build: @@ -49,6 +57,7 @@ services: PHP_EXT_MYSQL: 1 IMAGEMAGICK: 1 environment: + WIKI_BASE_URI: "${WIKI_BASE_URI}" WIKI_EN_SECRET_KEY: "${WIKI_EN_SECRET_KEY}" WIKI_EN_UPGRADE_KEY: "${WIKI_EN_UPGRADE_KEY}" WIKI_FR_SECRET_KEY: "${WIKI_FR_SECRET_KEY}" @@ -57,12 +66,16 @@ services: WIKI_DB_NAME: "wiki" WIKI_DB_USER: "wiki" WIKI_DB_PASSWORD: "${WIKI_DB_WIKI_PASSWORD}" - WIKI_DEBUG: "${DEBUG}" + WIKI_DEBUG: "${WIKI_DEBUG}" networks: - php-fpm - mariadb-wiki volumes: - ./src/wiki:/www/wiki/ + - ./volumes/wiki-fr-images:/www/wiki/fr/images/ + - ./volumes/wiki-en-images:/www/wiki/en/images/ + - ./volumes/wiki-fr-cache:/www/wiki/fr/cache/ + - ./volumes/wiki-en-cache:/www/wiki/en/cache/ mariadb-wiki: image: mariadb diff --git a/nginx.conf b/nginx.conf.template similarity index 95% rename from nginx.conf rename to nginx.conf.template index 6513d86..179bf79 100644 --- a/nginx.conf +++ b/nginx.conf.template @@ -2,7 +2,7 @@ server { listen 80 default_server; listen [::]:80 default_server; - server_name _; + server_name ${TOOLS_HOSTNAME}; index index.php index.html; root /www; @@ -34,7 +34,7 @@ server { listen 80; listen [::]:80; - server_name alabate-laptop; + server_name ${WIKI_HOSTNAME}; index index.php; root /www/wiki; @@ -43,7 +43,7 @@ server { client_body_timeout 60; # Redirect old path to newer ones - rewrite ^/tools/(.*)$ http://tools.planet-casio.com/$1; + rewrite ^/tools/(.*)$ https://tools.planet-casio.com/$1; # Priority to the fr part location = / { diff --git a/src/wiki b/src/wiki index 943350b..c7f8ace 160000 --- a/src/wiki +++ b/src/wiki @@ -1 +1 @@ -Subproject commit 943350b0f4e5927be9c23d5c9ebf8ed71ce60903 +Subproject commit c7f8ace3dd6ed4cbdc8aa81f3b371ccf2f195bce