diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e00e331 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.settings +.project +.idea +.DS_Store \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..17abcd4 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,60 @@ +FROM php:7.4.21-apache +ENV APP_VERSION=1.0.0 + +RUN apt-get update && \ + apt-get install -y less nano tini curl tar git zip unzip && \ + #echo "**** # To install networking tools for testing purpose ****" && \ + apt-get install -y iputils-ping dnsutils net-tools procps + #echo "**** cleanup ****" && \ + #apt-get autoremove -y && \ + #apt-get clean -y + +# curl -SL -o app.tar.gz "https://github.com/giandonatoinverso/PHP-Dynamic-Qr-code/archive/${APP_VERSION}.tar.gz" \ +RUN curl -SL -o app.tar.gz "https://github.com/giandonatoinverso/PHP-Dynamic-Qr-code/archive/refs/heads/master.tar.gz" \ + && mkdir -p /app \ + && tar xvf app.tar.gz -C /app --strip-components=1 \ + && cp -r /app/qrcode/** /var/www/html \ + && rm app.tar.gz + +RUN apt-get update +RUN apt-get install -y libzip-dev libjpeg62-turbo-dev libpng-dev libfreetype6-dev + +# install composer +RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" +RUN php composer-setup.php +RUN rm composer-setup.php +RUN mv composer.phar /usr/local/bin/composer + +# Install extensions +RUN docker-php-source extract +RUN docker-php-ext-install pdo_mysql zip exif pcntl gd +RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli +RUN docker-php-ext-install gettext && docker-php-ext-enable gettext +RUN docker-php-ext-install sockets && docker-php-ext-enable sockets + +RUN mv "/usr/local/etc/php/php.ini-production" "/usr/local/etc/php/php.ini" + +WORKDIR /var/www/html + +COPY ./config/docker-entrypoint.sh /bin/docker-entrypoint.sh +RUN chmod +x /bin/docker-entrypoint.sh +COPY ./config/vhost.conf /etc/apache2/sites-available/000-default.conf +RUN a2enmod rewrite + +ENV APP_USER appuser +ARG PUID=1000 +ARG PGID=1000 +RUN groupadd -g ${PGID} $APP_USER \ + && useradd -M -u ${PUID} -g ${PGID} $APP_USER \ + && chown -R $APP_USER:$APP_USER /var/run/apache2 \ + && chown -R $APP_USER:$APP_USER /var/log \ + && chown -R $APP_USER:$APP_USER /etc/apache2 \ + && chown -R $APP_USER:$APP_USER /var/lib/apache2 \ + && chown -R $APP_USER:$APP_USER /var/www +USER $APP_USER +CMD apache2ctl -D FOREGROUND + +EXPOSE 80 + +# needs to fix install process to create database and then below line can be commented out +#ENTRYPOINT ["/bin/docker-entrypoint.sh"] diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 0000000..ceb831a --- /dev/null +++ b/docker/README.md @@ -0,0 +1,27 @@ +### How to run this image +- currently this image must be build locally.(in future can be pulled from docker hub) +- create folder to mount inside docker container + - `mkdir -p ./data/mariadb ./data/app/config ./data/app/saved_qrcode` +- Run and build this image as host machine user + - `PUID="$(id -u)" PGID="$(id -g)" docker-compose up --build -d` +- Run and build this image as specific user + - `PUID="1000" PGID="1000" docker-compose up --build -d` +- Run app installation :8080/install + - Provide Database credentials +- Default login: :8080 + - user: superadmin + - password: superadmin + +### Roadmap +- Make install process run via docker-compose. + - Work is partially done. docker-entrypoint.sh is created.(currently disabled due to next steps are pending) + - qrcode/install/database.php should be adjusted to create database without form submission. +- Make it possible to set PUID and GUID, from environment variable in docker-compose.yml . +- Reduce image size by removing unnecessary dependencies. +- Automate Build image and push to docker hub. +- Audit security flaws and fix it if needed. + +### some debug commands +- `docker-compose logs` +- `PUID="$(id -u)" PGID="$(id -g)" docker-compose config` +- `ps -aef | grep apache2` \ No newline at end of file diff --git a/docker/config/docker-entrypoint.sh b/docker/config/docker-entrypoint.sh new file mode 100644 index 0000000..9346f63 --- /dev/null +++ b/docker/config/docker-entrypoint.sh @@ -0,0 +1,24 @@ +#!/bin/bash +set -o errexit -o nounset + +APP_PATH=/var/www/html + +echo "##### coping config file #####" +cp $APP_PATH/install/config/database.php $APP_PATH/config/config.php + +echo "##### setting database hostname #####" +sed -i "s/%HOSTNAME%/$DATABASE_HOST/" $APP_PATH/config/config.php + +echo "##### setting database username #####" +sed -i "s/%USERNAME%/$DATABASE_USER/" $APP_PATH/config/config.php + +echo "##### setting database password #####" +sed -i "s/%PASSWORD%/$DATABASE_PASSWORD/" $APP_PATH/config/config.php + +echo "##### setting database name #####" +sed -i "s/%DATABASE%/$DATABASE_NAME/" $APP_PATH/config/config.php + +echo "#### Deleting install folder #####" +rm -r $APP_PATH/install + +exec apache2-foreground \ No newline at end of file diff --git a/docker/config/info.php b/docker/config/info.php new file mode 100644 index 0000000..5a1884f --- /dev/null +++ b/docker/config/info.php @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docker/config/vhost.conf b/docker/config/vhost.conf new file mode 100644 index 0000000..1c9b57c --- /dev/null +++ b/docker/config/vhost.conf @@ -0,0 +1,11 @@ + + DocumentRoot /var/www/html/ + + AllowOverride all + Require all granted + + + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + + \ No newline at end of file diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000..ebfa217 --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,49 @@ +version: "3.9" + +services: + qrcode: + build: + context: . + args: + PUID: ${PUID} + PGID: ${PGID} + image: qrcode:1.0 + container_name: qrcode + restart: "unless-stopped" + networks: + - qrcode_network + ports: + - "8080:80" + user: "${PUID}:${PGID}" + #environment: + #ADMIN_USER: "superadmin" # not supported yet please see road map + #ADMIN_PASSWORD: "superadmin" # not supported yet please see road map + #DATABASE_HOST: "mariadb" # not supported yet please see road map + #DATABASE_NAME: "qrcode" # not supported yet please see road map + #DATABASE_USER: "qrcode" # not supported yet please see road map + #DATABASE_PASSWORD: "changeme" # not supported yet please see road map + volumes: + - ./data/app/config:/var/www/html/config + - ./data/app/saved_qrcode:/var/www/html/saved_qrcode + + mariadb: + image: mariadb:10.5 + container_name: mariadb + command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW + restart: "unless-stopped" + environment: + MARIADB_ROOT_PASSWORD: "changeme" + MARIADB_DATABASE: "qrcode" + MARIADB_USER: "qrcode" + MARIADB_PASSWORD: "changeme" + networks: + - qrcode_network + volumes: + - ./data/mariadb:/var/lib/mysql + ports: + - 3306:3306 + +networks: + qrcode_network: + driver: bridge + name: qrcode