Skip to content

Commit

Permalink
feat: allow setting all config in environment
Browse files Browse the repository at this point in the history
chor: update compose
doc: update readme
  • Loading branch information
mhzawadi committed Jan 24, 2024
1 parent 356ec85 commit b6fe191
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ RUN cd /tmp && \

WORKDIR /var/www/html

VOLUME /var/www/html/uploads
VOLUME /var/www/html/uploads /var/www/html/assets/core/css /var/www/html/application/views
EXPOSE 80
ENTRYPOINT ["/config/start.sh"]
CMD ["nginx", "-g", "daemon off;"]
Expand Down
45 changes: 43 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@

## How to use this Docker image

This image will export 3 directories, if you dont setup a volume for them Docker will.

- /var/www/html/uploads (Uploaded images)
- /var/www/html/assets/core/css (custom styles)
- /var/www/html/application/views (Customized templates)

### Mysql

Run a MySQL database, dedicated to invoiceplane
Expand All @@ -31,7 +37,12 @@ This does take some time, so dont try to get invoiceplane setup too quick
### InvoicePlane

```bash
docker run -ti -d -p 80:80 --name invoiceplane --link invoiceplane-mysql:mysql mhzawadi/invoiceplane
docker run -ti -d -p 80:80 --name invoiceplane \
--link invoiceplane-mysql:mysql \
--volume "/your/path/to/invoiceplane/uploads:/var/www/html/uploads" \
--volume "/your/path/to/invoiceplane/assets:/var/www/html/assets/core/css" \
--volume "/your/path/to/invoiceplane/views:/var/www/html/application/views" \
mhzawadi/invoiceplane
```

We are linking the two containers and expose the HTTP port, once MySQL is up and running setup of invoiceplane should be quick.
Expand Down Expand Up @@ -60,15 +71,45 @@ if you run docker swarm, you can add your config to docker swarm config and have

Mount your config to `/var/www/html/ipconfig.php`

Or you can pass all the config via environment variables, see below for some of the basics.
Once you have your instance setup, you will want to collect the `ENCRYPTION_KEY` & `ENCRYPTION_CIPHER`. As that is used to store passwords.

The below commands will collect the `ENCRYPTION_KEY` & `ENCRYPTION_CIPHER` and

```
ID=$(docker ps | grep 'mhzawadi/invoiceplane' | awk '{print $1}');
docker exec -it "$ID" /bin/cat ipconfig.php | grep ENCRYPTION_KEY;
docker exec -it "$ID" /bin/cat ipconfig.php | grep ENCRYPTION_CIPHER;
```

Update your docker-compose file with them, also add `SETUP_COMPLETED=true`.

the `environment` section should have some like the below

```
- TZ=utc
- MYSQL_HOST=mariadb_10_4
- MYSQL_USER=InvoicePlane
- MYSQL_PASSWORD=invoiceplane
- MYSQL_DB=InvoicePlane
- IP_URL=http://invoiceplane.docker.local
- DISABLE_SETUP=true
- SETUP_COMPLETED=true
- ENCRYPTION_CIPHER=base64:LgrA+4Df/kJvZIx+GBech8PRTYuO+lbIoF5CgJ59iJM=
- ENCRYPTION_CIPHER=AES-256
```

### Environment variables summary

- TZ: the timezone for PHP
- IP_URL: This is the host that you will access the site on
- REMOVE_INDEXPHP: To remove index.php from the URL
- the bundled nginx has the config to work with this set to `true`
- MYSQL_HOST: the MySQL server
- MYSQL_USER: the username for MySQL
- MYSQL_PASSWORD: the password for MySQL
- MYSQL_DB: the MySQL database
- MYSQL_PORT: the MySQL port, if not 3306
- IP_URL: This is the host that you will access the site on
- DISABLE_SETUP: Have you run setup?

## Docker hub tags
Expand Down
1 change: 0 additions & 1 deletion docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ services:
image: mhzawadi/invoiceplane:dev-code
volumes:
- invoiceplane_data:/var/www/html/uploads
- /Users/matt/git/code-InvoicePlane:/var/www/html
environment:
- TZ=utc
- MYSQL_HOST=mariadb_10_4
Expand Down
8 changes: 6 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ version: '3.5'
# docker stack deploy --compose-file stack-invoiceplane.yml invoiceplane

volumes:
invoiceplane_data:
invoiceplane_uploads:
invoiceplane_css:
invoiceplane_views:
mariadb_10_4:

services:
Expand All @@ -23,7 +25,9 @@ services:
invoiceplane:
image: mhzawadi/invoiceplane
volumes:
- invoiceplane_data:/var/www/html/uploads
- invoiceplane_uploads:/var/www/html/uploads
- invoiceplane_css:/var/www/html/assets/core/css
- invoiceplane_views:/var/www/html/application/views
environment:
- TZ=utc
- MYSQL_HOST=mariadb_10_4
Expand Down
39 changes: 30 additions & 9 deletions setup/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,41 @@ ln -s /dev/stdout /var/log/php81/error.log
ln -s /dev/stdout /var/log/nginx/access.log
ln -s /dev/stdout /var/log/nginx/error.log


if [ ! -f "/var/www/html/ipconfig.php" ]; then
sed \
-e "s/DB_HOSTNAME=/DB_HOSTNAME=${MYSQL_HOST}/" \
-e "s/DB_USERNAME=/DB_USERNAME=${MYSQL_USER}/" \
-e "s/DB_PASSWORD=/DB_PASSWORD=${MYSQL_PASSWORD}/" \
-e "s/DB_DATABASE=/DB_DATABASE=${MYSQL_DB}/" \
-e "s/DB_PORT=/DB_PORT=${MYSQL_PORT}/" \
-e "s!IP_URL=!IP_URL=${IP_URL}!" \
-e "s/DISABLE_SETUP=false/DISABLE_SETUP=${DISABLE_SETUP}/" \
/var/www/html/ipconfig.php.example > /var/www/html/ipconfig.php;

/var/www/html/ipconfig.php.example > /var/www/html/ipconfig.php

else

[ -n "$IP_URL" ] && sed -i 's/IP_URL=/IP_URL=${IP_URL}/' /var/www/html/ipconfig.php
[ -n "$ENABLE_DEBUG" ] && sed -i 's/ENABLE_DEBUG=/ENABLE_DEBUG=${ENABLE_DEBUG}/' /var/www/html/ipconfig.php
[ -n "$DISABLE_SETUP" ] && sed -i 's/DISABLE_SETUP=/DISABLE_SETUP=${DISABLE_SETUP}/' /var/www/html/ipconfig.php
[ -n "$REMOVE_INDEXPHP" ] && sed -i 's/REMOVE_INDEXPHP=/REMOVE_INDEXPHP=${REMOVE_INDEXPHP}/' /var/www/html/ipconfig.php

[ -n "$DB_HOSTNAME" ] && sed -i 's/DB_HOSTNAME=/DB_HOSTNAME=${MYSQL_HOST}/' /var/www/html/ipconfig.php
[ -n "$DB_USERNAME" ] && sed -i 's/DB_USERNAME=/DB_USERNAME=${DB_USERNAME}/' /var/www/html/ipconfig.php
[ -n "$DB_PASSWORD" ] && sed -i 's/DB_PASSWORD=/DB_PASSWORD=${DB_PASSWORD}/' /var/www/html/ipconfig.php
[ -n "$DB_DATABASE" ] && sed -i 's/DB_DATABASE=/DB_DATABASE=${DB_DATABASE}/' /var/www/html/ipconfig.php
[ -n "$DB_PORT" ] && sed -i 's/DB_PORT=/DB_PORT=${DB_PORT}/' /var/www/html/ipconfig.php

[ -n "$SESS_EXPIRATION" ] && sed -i 's/SESS_EXPIRATION=/SESS_EXPIRATION=${SESS_EXPIRATION}/' /var/www/html/ipconfig.php
[ -n "$SESS_MATCH_IP" ] && sed -i 's/SESS_MATCH_IP=/SESS_MATCH_IP=${SESS_MATCH_IP}/' /var/www/html/ipconfig.php
[ -n "$ENABLE_INVOICE_DELETION" ] && sed -i 's/ENABLE_INVOICE_DELETION=/ENABLE_INVOICE_DELETION=${ENABLE_INVOICE_DELETION}/' /var/www/html/ipconfig.php
[ -n "$DISABLE_READ_ONLY" ] && sed -i 's/DISABLE_READ_ONLY=/DISABLE_READ_ONLY=${DISABLE_READ_ONLY}/' /var/www/html/ipconfig.php

### CRITICAL
if [ -n "$SETUP_COMPLETED" ]; then
[ -n "$ENCRYPTION_KEY" ] && sed -i 's/ENCRYPTION_KEY=/ENCRYPTION_KEY=${ENCRYPTION_KEY}/' /var/www/html/ipconfig.php
[ -n "$ENCRYPTION_CIPHER" ] && sed -i 's/ENCRYPTION_CIPHER=/ENCRYPTION_CIPHER=${ENCRYPTION_CIPHER}/' /var/www/html/ipconfig.php
sed -i 's/SETUP_COMPLETED=/SETUP_COMPLETED=${SETUP_COMPLETED}/' /var/www/html/ipconfig.php
fi
fi

chown nobody:nginx /var/www/html/ipconfig.php;
chown -R nobody:nginx /var/www/html/uploads;
chown -R nobody:nginx /var/www/html/assets/core/css;
chown -R nobody:nginx /var/www/html/application/views;

php-fpm81

Expand Down

0 comments on commit b6fe191

Please sign in to comment.