danielmarschall / oidplus

OIDplus 2.0 - An OpenSource online Registration Authority for OIDs and other Object Types
https://www.oidplus.com
Apache License 2.0
10 stars 6 forks source link

Docker image #12

Open danielmarschall opened 1 year ago

danielmarschall commented 1 year ago

Help wanted: How to make a Docker image for OIDplus?

danielmarschall commented 1 year ago

Got some help from @Tushev ! Thank you!

https://github.com/tushev/oidplus-docker-compose

Comments from @Tushev:

It's ready for public yet, however, I believe it would be useful for you in the development process.

I tested this very setup first on Windows/Docker/WSL2 backend (the files were on Windows filesystem, say, D:\Docker\oidplus), and it's a bit slow (as expected). Then I moved into WSL2 distribution (the files were on Linux filesystem, say, in /opt/oidplus/), and it's blazing fast. (In Windows Explorer, type \wsl$ into address bar to access Linux WSL fs). In production (on pure baremetal Linux) Docker usually is even faster.

To start:

  1. (Optional, but better to have, if you're on Windows). Install WSL2:

https://learn.microsoft.com/en-us/windows/wsl/install https://www.omgubuntu.co.uk/how-to-install-wsl2-on-windows-10 https://learn.microsoft.com/en-us/windows/terminal/install is also useful here because it allows to access both Windows and Linux/WSL command line much easier.

  1. Install Docker https://docs.docker.com/desktop/install/windows-install/ https://docs.docker.com/engine/install/ubuntu/ On Windows, in Docker Desktop > Settings enable WSL2 engine and in Settings > Resources > WSL Integration enable the default installed distro.
  2. Unzip the attached file. It contains:

data/sql-initdb.d/ - here we should put the struct_empty.sql for MySQL docker/.env - please check this file and adjust to your needs docker/docker-compose.yml - this is the main docker-compose project file docker/Dockerfile-apache - this is the custom php:8.2-apache 'image' that adds PHP extensions that are missing in the base image. Please check it once you will have everything running and (maybe) remove unnecessary PHP extensions docker/conf - here are the config files, adjust as needed. Require docker-compose project restart. www - this is wwwroot dir where OIDplus should be More folders will appear in /data after start.

If you would be using Linux, adjust permissions as needed (at least to /docker/conf/mariadb.conf - if you encounter any errors). As said, better to put it inside Linux filesystem. On Windows drives, it would be slower ( https://docs.docker.com/desktop/windows/wsl/#best-practices ).

  1. Clone the repo, like: git clone https://github.com/danielmarschall/oidplus move oidplus www
  2. Put struct_empty.sql for MySQL into data/sql-initdb.d/ This is what needs to be solved: currently this file will be generated only when the website is up and running. However, with docker-compose, this means that the DB server will also be up and running. But the DB server checks that dir on the first start, and - if this dir contains any .sql files, the server initializes DBs from them.

So, I suppose, 'docker' variant should already include structempty.sql as file. DB prefixes are IMHO not needed here because each dockerized DB server contains data for just a single app (or use standard 'oidplus' prefix since there could be no conflicts).

  1. Go to docker/ and run

docker-compose up -d from there. On Windows, start Docker Desktop app beforehand.

  1. Go to http://localhost:8080/ For config.inc.php, use the following settings (if you did not change default credentials in docker/.env) : OIDplus::baseConfig()->setValue('MYSQL_HOST', 'localhost'); OIDplus::baseConfig()->setValue('MYSQL_SOCKET', '/var/run/mysqld/mysqld.sock'); OIDplus::baseConfig()->setValue('MYSQL_USERNAME', 'oidplus_user'); OIDplus::baseConfig()->setValue('MYSQL_PASSWORD', base64_decode('...............')); OIDplus::baseConfig()->setValue('MYSQL_DATABASE', 'oidplus_db'); OIDplus::baseConfig()->setValue('TABLENAMEPREFIX', 'oidplus'); If you would like to test host:port connection, use 'db' - because it's DB server internal docker's hostname (see docker/docker-compose.yml, line 46):

OIDplus::baseConfig()->setValue('MYSQL_HOST', 'db'); OIDplus::baseConfig()->setValue('MYSQL_PORT', '3306'); I hope you will find this useful. If you have any questions, don't hesitate to ask me.

Next step: Read and understand everything, then follow the instructions for a Docker distribution