diff --git a/.otp.env b/.otp.env new file mode 100644 index 0000000000000000000000000000000000000000..dd0a7a7f197ee227a67fcc3c78d0fb7bdd2dc3fc --- /dev/null +++ b/.otp.env @@ -0,0 +1,7 @@ +# otp_config.php +DB_HOST=edugain-db +DB_DATABASE=otp +USER=otp +PASSWORD=xxx + +DB_CONFIG_LOCATION=/var/otp_server_config/otp_config.php diff --git a/Dockerfile b/Dockerfile index 30f474f0ee28d2734e21c90b18ca87e6bddd98bd..45364222b03dde738a695a8c730b683201ba51ec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,13 +2,17 @@ FROM php:8.1-apache WORKDIR /var/www/html RUN docker-php-ext-install mysqli +COPY --from=hairyhenderson/gomplate:v3.11.3 /gomplate /bin/gomplate COPY --from=docker.io/library/composer:latest /usr/bin/composer /usr/bin/composer COPY composer.json . RUN apt-get update -RUN apt-get install -y git +RUN apt-get install -y git vim RUN composer update COPY otp_server.php otp_server.php COPY config/ config COPY otp_server_config/ /var/otp_server_config EXPOSE 80 + +COPY templating.sh /templating.sh +RUN chmod a+x /templating.sh diff --git a/README.md b/README.md index 2d086512296fe772a7d41d230cef4148958ba491..b78c2bf62065cf9103791fdc26a1f153a7f8c173 100644 --- a/README.md +++ b/README.md @@ -40,12 +40,13 @@ If you run stuff within secure environment (as you should) you do not need https When you unpack the code from Git: - Run composer to pull the TOTP PHP package. -- Create a directory where you will place server config file and copy **otp_config-template.php** there +- Create a directory where you will place server config file and copy **otp_config.php.template** there using a name of your choice; this file contains access details to the OTP database and it must be read by the server, but should not be placed within the web-server directory, in case a problem with your PHP could lead to exposure. -- In the config directory, copy `config-template.php` to `config.php` and put in the location of the otp_server config file. +- In the config directory, copy `config.php.template` to `config.php` and put in the location of the otp_server config file. - Configure your httpd server to be able to execute otp_server.php + ### Using Docker We suggest that you use **--network host** Docker run option which will allow address @@ -54,12 +55,12 @@ resolution based on the host machine and standard port 80 for connections. - You need docker instaled on your host machine - If you do not want to use ` --network host ` option then decide which port will be mapped to your Docker image (say 8080) - Download the code from git -- In the ` config ` directory, copy ` config-template.php ` to ` config.php `; do not modify the settings -- In the ` otp_server_config ` directory copy ` otp_config-template.php ` to ` otp_confi.php ` and modify the settings as needed +- In the ` config ` directory, copy ` config.php.template. ` to ` config.php `; do not modify the settings +- In the ` otp_server_config ` directory copy ` otp_config.php.template ` to ` otp_config.php ` and modify the settings as needed - As root run ` docker build -t otp_server:latest . ` - As root run ` docker run -d --name otp_server --network host --rm otp_server:latest ` -### Running the dosker image at boot +### Running the docker image at boot For systems using systemctl we suggest to install the new service called ` otp-docker ` to do that create the ` otp-docker.service ` file in ` /usr/lib/systemd/system ` with the contents as below: @@ -87,6 +88,23 @@ systemctl start otp-docker systemctl enable otp-docker ``` +## Create and upload the image on the Container Registry + +- You need docker installed on your host machine +- Download the code from git +- As root run ` docker login gitlab.software.geant.org:5050 ` +- As root run ` docker build -t gitlab.software.geant.org:5050/edugain/ot/totp-server:<VERSION> . ` +- As root run ` docker push gitlab.software.geant.org:5050/edugain/ot/totp-server:<VERSION> ` + + +## Using Docker Compose + +- You need docker and docker compose installed on your host machine +- Modify the settings file ` .otp.env ` as needed +- Update the ` docker-compose.yml ` file as needed +- As root run ` docker compose up -d ` +- As root run ` docker exec otp_server /templating.sh ` + ## Testing diff --git a/config/config-template.php b/config/config-template.php deleted file mode 100644 index d563f976aeb944da4d0273237d8349635195f88a..0000000000000000000000000000000000000000 --- a/config/config-template.php +++ /dev/null @@ -1,7 +0,0 @@ -<?php -// location of otp_config.php -//current path corresponds to the settings in the Dockerfile -// therefore you you are using Docker intall do not change this - -define('DB_CONFIG_LOCATION', '/var/otp_server_config/otp_config.php'); - diff --git a/config/config.php.template b/config/config.php.template new file mode 100644 index 0000000000000000000000000000000000000000..003c1cebac2b5db2a61878cf2b2efbf9cec57b2f --- /dev/null +++ b/config/config.php.template @@ -0,0 +1,4 @@ +<?php +// location of otp_config.php + +define('DB_CONFIG_LOCATION', '{{ .Env.DB_CONFIG_LOCATION }}'); diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000000000000000000000000000000000000..f37566e605d384a878aff12cc8c1901bcad7b779 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +version: '3.9' +services: + otp_server: + image: "gitlab.software.geant.org:5050/edugain/ot/totp-server:1.0.0" + container_name: "edugain_otp_server" + hostname: "edugain_otp_server" + env_file: + - ".otp.env" + ports: + - "8080:80" + diff --git a/otp_server_config/otp_config-template.php b/otp_server_config/otp_config.php.template similarity index 67% rename from otp_server_config/otp_config-template.php rename to otp_server_config/otp_config.php.template index 99fe5aee0facfd30c5736075cd39f6c60cb9a96a..1bb89679333cb22332010ec584efa47048b383f8 100644 --- a/otp_server_config/otp_config-template.php +++ b/otp_server_config/otp_config.php.template @@ -7,8 +7,8 @@ * config of the technical site, however the database user must not be the same * access provileges need to be different */ -define('DB_HOST','edugain-db'); -define('DB_DATABASE','otp'); -define('USER', 'otp'); -define('PASSWORD', 'xxxx'); +define('DB_HOST','{{ .Env.DB_HOST }}'); +define('DB_DATABASE','{{ .Env.DB_DATABASE }}'); +define('USER', '{{ .Env.USER }}'); +define('PASSWORD', '{{ .Env.PASSWORD }}'); diff --git a/templating.sh b/templating.sh new file mode 100644 index 0000000000000000000000000000000000000000..a9d6f3c412b301ecfd2094212f9068d1b3ed605d --- /dev/null +++ b/templating.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +gomplate -f /var/www/html/config/config.php.template -o /var/www/html/config/config.php +rm /var/www/html/config/config.php.template + +gomplate -f /var/otp_server_config/otp_config.php.template -o /var/otp_server_config/otp_config.php +rm /var/otp_server_config/otp_config.php.template +