Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Commit 21b779c

Browse files
Merge pull request #23 from nirpt/master
docker support added
2 parents 59cee36 + 618030e commit 21b779c

File tree

7 files changed

+176
-0
lines changed

7 files changed

+176
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.settings
2+
.project
3+
.idea
4+
.DS_Store

docker/Dockerfile

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
FROM php:7.4.21-apache
2+
ENV APP_VERSION=1.0.0
3+
4+
RUN apt-get update && \
5+
apt-get install -y less nano tini curl tar git zip unzip && \
6+
#echo "**** # To install networking tools for testing purpose ****" && \
7+
apt-get install -y iputils-ping dnsutils net-tools procps
8+
#echo "**** cleanup ****" && \
9+
#apt-get autoremove -y && \
10+
#apt-get clean -y
11+
12+
# curl -SL -o app.tar.gz "https://github.com/giandonatoinverso/PHP-Dynamic-Qr-code/archive/${APP_VERSION}.tar.gz" \
13+
RUN curl -SL -o app.tar.gz "https://github.com/giandonatoinverso/PHP-Dynamic-Qr-code/archive/refs/heads/master.tar.gz" \
14+
&& mkdir -p /app \
15+
&& tar xvf app.tar.gz -C /app --strip-components=1 \
16+
&& cp -r /app/qrcode/** /var/www/html \
17+
&& rm app.tar.gz
18+
19+
RUN apt-get update
20+
RUN apt-get install -y libzip-dev libjpeg62-turbo-dev libpng-dev libfreetype6-dev
21+
22+
# install composer
23+
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
24+
RUN php composer-setup.php
25+
RUN rm composer-setup.php
26+
RUN mv composer.phar /usr/local/bin/composer
27+
28+
# Install extensions
29+
RUN docker-php-source extract
30+
RUN docker-php-ext-install pdo_mysql zip exif pcntl gd
31+
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
32+
RUN docker-php-ext-install gettext && docker-php-ext-enable gettext
33+
RUN docker-php-ext-install sockets && docker-php-ext-enable sockets
34+
35+
RUN mv "/usr/local/etc/php/php.ini-production" "/usr/local/etc/php/php.ini"
36+
37+
WORKDIR /var/www/html
38+
39+
COPY ./config/docker-entrypoint.sh /bin/docker-entrypoint.sh
40+
RUN chmod +x /bin/docker-entrypoint.sh
41+
COPY ./config/vhost.conf /etc/apache2/sites-available/000-default.conf
42+
RUN a2enmod rewrite
43+
44+
ENV APP_USER appuser
45+
ARG PUID=1000
46+
ARG PGID=1000
47+
RUN groupadd -g ${PGID} $APP_USER \
48+
&& useradd -M -u ${PUID} -g ${PGID} $APP_USER \
49+
&& chown -R $APP_USER:$APP_USER /var/run/apache2 \
50+
&& chown -R $APP_USER:$APP_USER /var/log \
51+
&& chown -R $APP_USER:$APP_USER /etc/apache2 \
52+
&& chown -R $APP_USER:$APP_USER /var/lib/apache2 \
53+
&& chown -R $APP_USER:$APP_USER /var/www
54+
USER $APP_USER
55+
CMD apache2ctl -D FOREGROUND
56+
57+
EXPOSE 80
58+
59+
# needs to fix install process to create database and then below line can be commented out
60+
#ENTRYPOINT ["/bin/docker-entrypoint.sh"]

docker/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
### How to run this image
2+
- currently this image must be build locally.(in future can be pulled from docker hub)
3+
- create folder to mount inside docker container
4+
- `mkdir -p ./data/mariadb ./data/app/config ./data/app/saved_qrcode`
5+
- Run and build this image as host machine user
6+
- `PUID="$(id -u)" PGID="$(id -g)" docker-compose up --build -d`
7+
- Run and build this image as specific user
8+
- `PUID="1000" PGID="1000" docker-compose up --build -d`
9+
- Run app installation <IP>:8080/install
10+
- Provide Database credentials
11+
- Default login: <IP>:8080
12+
- user: superadmin
13+
- password: superadmin
14+
15+
### Roadmap
16+
- Make install process run via docker-compose.
17+
- Work is partially done. docker-entrypoint.sh is created.(currently disabled due to next steps are pending)
18+
- qrcode/install/database.php should be adjusted to create database without form submission.
19+
- Make it possible to set PUID and GUID, from environment variable in docker-compose.yml .
20+
- Reduce image size by removing unnecessary dependencies.
21+
- Automate Build image and push to docker hub.
22+
- Audit security flaws and fix it if needed.
23+
24+
### some debug commands
25+
- `docker-compose logs`
26+
- `PUID="$(id -u)" PGID="$(id -g)" docker-compose config`
27+
- `ps -aef | grep apache2`

docker/config/docker-entrypoint.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
set -o errexit -o nounset
3+
4+
APP_PATH=/var/www/html
5+
6+
echo "##### coping config file #####"
7+
cp $APP_PATH/install/config/database.php $APP_PATH/config/config.php
8+
9+
echo "##### setting database hostname #####"
10+
sed -i "s/%HOSTNAME%/$DATABASE_HOST/" $APP_PATH/config/config.php
11+
12+
echo "##### setting database username #####"
13+
sed -i "s/%USERNAME%/$DATABASE_USER/" $APP_PATH/config/config.php
14+
15+
echo "##### setting database password #####"
16+
sed -i "s/%PASSWORD%/$DATABASE_PASSWORD/" $APP_PATH/config/config.php
17+
18+
echo "##### setting database name #####"
19+
sed -i "s/%DATABASE%/$DATABASE_NAME/" $APP_PATH/config/config.php
20+
21+
echo "#### Deleting install folder #####"
22+
rm -r $APP_PATH/install
23+
24+
exec apache2-foreground

docker/config/info.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php phpinfo( ); ?>

docker/config/vhost.conf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<VirtualHost *:80>
2+
DocumentRoot /var/www/html/
3+
<Directory “/var/www/html/”>
4+
AllowOverride all
5+
Require all granted
6+
</Directory>
7+
8+
ErrorLog ${APACHE_LOG_DIR}/error.log
9+
CustomLog ${APACHE_LOG_DIR}/access.log combined
10+
11+
</VirtualHost>

docker/docker-compose.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
version: "3.9"
2+
3+
services:
4+
qrcode:
5+
build:
6+
context: .
7+
args:
8+
PUID: ${PUID}
9+
PGID: ${PGID}
10+
image: qrcode:1.0
11+
container_name: qrcode
12+
restart: "unless-stopped"
13+
networks:
14+
- qrcode_network
15+
ports:
16+
- "8080:80"
17+
user: "${PUID}:${PGID}"
18+
#environment:
19+
#ADMIN_USER: "superadmin" # not supported yet please see road map
20+
#ADMIN_PASSWORD: "superadmin" # not supported yet please see road map
21+
#DATABASE_HOST: "mariadb" # not supported yet please see road map
22+
#DATABASE_NAME: "qrcode" # not supported yet please see road map
23+
#DATABASE_USER: "qrcode" # not supported yet please see road map
24+
#DATABASE_PASSWORD: "changeme" # not supported yet please see road map
25+
volumes:
26+
- ./data/app/config:/var/www/html/config
27+
- ./data/app/saved_qrcode:/var/www/html/saved_qrcode
28+
29+
mariadb:
30+
image: mariadb:10.5
31+
container_name: mariadb
32+
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
33+
restart: "unless-stopped"
34+
environment:
35+
MARIADB_ROOT_PASSWORD: "changeme"
36+
MARIADB_DATABASE: "qrcode"
37+
MARIADB_USER: "qrcode"
38+
MARIADB_PASSWORD: "changeme"
39+
networks:
40+
- qrcode_network
41+
volumes:
42+
- ./data/mariadb:/var/lib/mysql
43+
ports:
44+
- 3306:3306
45+
46+
networks:
47+
qrcode_network:
48+
driver: bridge
49+
name: qrcode

0 commit comments

Comments
 (0)