mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-07 05:31:24 +00:00
🚢 Simplified docker builds (#456)
* Simplify docker builds * Ignore docker and frontend scripts from PHP related checks * Update docker development setup
This commit is contained in:
committed by
GitHub
parent
3ed91545d1
commit
23f6b1877f
28
docker/development/Dockerfile
Normal file
28
docker/development/Dockerfile
Normal file
@@ -0,0 +1,28 @@
|
||||
FROM --platform=$BUILDPLATFORM node AS static_builder
|
||||
WORKDIR /var/www/html
|
||||
COPY . /var/www/html
|
||||
RUN yarn && yarn build
|
||||
|
||||
FROM serversideup/php:8-fpm-alpine AS base
|
||||
USER root
|
||||
RUN install-php-extensions exif
|
||||
RUN install-php-extensions pgsql
|
||||
RUN install-php-extensions sqlite3
|
||||
RUN install-php-extensions imagick
|
||||
RUN install-php-extensions mbstring
|
||||
RUN install-php-extensions gd
|
||||
RUN install-php-extensions xml
|
||||
RUN install-php-extensions zip
|
||||
RUN install-php-extensions redis
|
||||
RUN install-php-extensions bcmath
|
||||
RUN install-php-extensions intl
|
||||
RUN install-php-extensions curl
|
||||
|
||||
FROM base AS development
|
||||
ARG UID
|
||||
ARG GID
|
||||
|
||||
USER root
|
||||
RUN docker-php-serversideup-set-id www-data $UID:$GID
|
||||
USER www-data
|
||||
|
||||
166
docker/development/README.md
Normal file
166
docker/development/README.md
Normal file
@@ -0,0 +1,166 @@
|
||||
# InvoiceShelf Development Environment
|
||||
|
||||
This is dockerized development environment that allows developers to easily get started to develop InvoiceShelf.
|
||||
|
||||
This development environment is **NOT MEANT TO BE USED IN PRODUCTION** and is preconfigured with all the needed tools that InvoiceShelf requires for development purposes. It works on Windows, Linux and MacOS.
|
||||
|
||||
For production grade docker image, please refer to [InvoiceShelf/docker](https://github.com/InvoiceShelf/docker) and [InvoiceShelf on DockerHub](https://hub.docker.com/r/invoiceshelf/invoiceshelf).
|
||||
|
||||
## How to set up
|
||||
|
||||
### 1. Hosts configuration
|
||||
|
||||
We use `invoiceshelf.test` domain for local development within this environment and you need to adhere to it.
|
||||
|
||||
For that purpose you need to edit your OS hosts file or DNS server and add the following line to make the local domain name available on your system.
|
||||
|
||||
```
|
||||
127.0.0.1 invoiceshelf.test
|
||||
```
|
||||
|
||||
#### 1.1. Windows
|
||||
|
||||
The hosts file on Windows is located at `C:\Windows\system32\drivers\etc\hosts`.
|
||||
|
||||
You need to launch Notepad as administrator, open the file through **File > Open**, add the line from above and save the file.
|
||||
|
||||
#### 1.2. Linux/MacOS
|
||||
|
||||
The hosts file on Linux and Mac is located at `/etc/hosts`.
|
||||
|
||||
You need to open the file using your favorite editor as sudo/root, add the line from above and save the file.
|
||||
|
||||
### 2. FileSystem configuration (Linux)
|
||||
|
||||
If you are using **Linux**, you need to make sure that **USRID** and **GRPID** environment variables are set and matching your current session user ids. Those two variables are required to set up the filesystem permissions correctly on Linux.
|
||||
|
||||
You can run it one time, every time before starting as follows:
|
||||
|
||||
```
|
||||
export USRID=$(id -u) && export GRPID=$(id -g)
|
||||
```
|
||||
|
||||
or you can append this to your .zshrc/.bashrc by running this command in your terminal:
|
||||
|
||||
```
|
||||
grep -qxF 'export USRID=$(id -u) GRPID=$(id -g)' ~/.${SHELL##*/}rc || echo 'export USRID=$(id -u) GRPID=$(id -g)' >> ~/.${SHELL##*/}rc
|
||||
```
|
||||
this will append the `export` line to your rc file and run it on each terminal session.
|
||||
|
||||
### 3. Clone the project
|
||||
|
||||
Clone the InvoiceShelf project directly from InvoiceShelf git or your forked repository:
|
||||
|
||||
```bash
|
||||
git clone git@github.com:InvoiceShelf/InvoiceShelf.git
|
||||
```
|
||||
|
||||
## Development Workflow
|
||||
|
||||
We bundled separate docker-compose.yml file for each database: MySQL, PostgresSQL and SQLite, you can use any of those to spin up your development environment.
|
||||
|
||||
| Database | Compose File |
|
||||
|---------|---------------------------|
|
||||
| SQLite3 | docker-compose.sqlite.yml |
|
||||
| MariaDB | docker-compose.mysql.yml |
|
||||
| PostgresSQL | dpcler-compose.pgsql.yml |
|
||||
|
||||
### 1. Spinning Up
|
||||
|
||||
To **spin up** the environment, run docker compose as follows:
|
||||
|
||||
**Important**: If you are on **Linux** and didn't add the `export` line to your .zshrc/.bashrc file, you need to repeat `step 2` before spinning up, otherwise you will face permissions issues.
|
||||
|
||||
```
|
||||
docker compose -f .dev/docker-compose.mysql.yml up --build
|
||||
```
|
||||
|
||||
### 2. Spinning Down
|
||||
|
||||
To **spin down** the environment, run docker compose as follows:
|
||||
|
||||
```
|
||||
docker compose -f .dev/docker-compose.mysql.yml down
|
||||
```
|
||||
|
||||
### 3. Working with binaries
|
||||
|
||||
To correctly run `composer`, `npm`, `artisan`, `pint`, `pest` or other binaries within this project, you must ssh into the container as follows:
|
||||
|
||||
```
|
||||
docker exec -it invoiceshelf /bin/bash
|
||||
```
|
||||
|
||||
In the `/var/www/html` directory you can find the application root and run the commands from there.
|
||||
|
||||
## What is included
|
||||
|
||||
### 1. Web Server
|
||||
|
||||
This dockerized environment uses PHP-FPM and NGINX together to serve the website `invoiceshelf.test`
|
||||
|
||||
Both NGINX and PHP-FPM are configured with optimal settings for development. Please don't use this in production.
|
||||
|
||||
**URL**: http://invoiceshelf.test/
|
||||
|
||||
### 2. Databases
|
||||
|
||||
This dockerized environment comes with support for all three databases that InvoiceShelf suppots: MySQL, PostgreSQL and SQLite.
|
||||
|
||||
The setup parameters/credentials for each of the supported databases are as follows.
|
||||
|
||||
| | MySQL | PostgreSQL | SQLite |
|
||||
|---|---|---|---|
|
||||
| **DB_USER** | invoiceshelf | invoiceshelf | Not applicable |
|
||||
| **DB_PASS** | invoiceshelf | invoiceshelf | Not applicable |
|
||||
| **DB_NAME** | invoiceshelf | invoiceshelf | /var/www/html/database/database.sqlite |
|
||||
| **DB_HOST** | db-mysql | db-pgsql | Not applicable |
|
||||
| **DB_PORT** | 3036 | 5432 | Not applicable |
|
||||
|
||||
**Note:** The only required field for SQLite is **DB_NAME**.
|
||||
|
||||
### 3. Adminer
|
||||
|
||||
Adminer is UI tool for viewing the database contents and executing queries.
|
||||
|
||||
It supports MySQL, PostgreSQL, SQLite.
|
||||
|
||||
**URL**: http://invoiceshelf.test:8080
|
||||
|
||||
#### MySQL/PostgresSQL
|
||||
|
||||
To log into the MySQL or PostgresSQL, use the database information specified in the above section (2. Databases)
|
||||
|
||||
#### SQLite
|
||||
|
||||
To log into the SQLite, use the following credentials:
|
||||
|
||||
| KEY | VALUE |
|
||||
|--------------|---------------------------|
|
||||
| **USERNAME** | admin |
|
||||
| **PASSWORD** | admin |
|
||||
| **DATABASE** | /database/database.sqlite |
|
||||
|
||||
|
||||
### 4. Mailpit (fake mail)
|
||||
|
||||
To utilize Mailpit, use the following credentials:
|
||||
|
||||
| KEY | VALUE |
|
||||
|---------------------|-------------|
|
||||
| **MAIL DRIVER** | smtp |
|
||||
| **MAIL HOST** | mail |
|
||||
| **MAIL PORT** | 1025 |
|
||||
| **MAIL ENCRYPTION** | none |
|
||||
| **MAIL USER** | leave empty |
|
||||
| **MAIL PASS** | leave empty |
|
||||
| **FROM MAIL ADDR** | your choice |
|
||||
| **FROM MAIL NAME** | your choice |
|
||||
|
||||
|
||||
**URL**: http://invoiceshelf.test:8025
|
||||
|
||||
---
|
||||
|
||||
If you have any questions, feel free to open issue.
|
||||
|
||||
8
docker/development/adminer/Dockerfile
Normal file
8
docker/development/adminer/Dockerfile
Normal file
@@ -0,0 +1,8 @@
|
||||
FROM adminer:latest
|
||||
|
||||
USER root
|
||||
|
||||
USER adminer
|
||||
CMD [ "php", "-S", "[::]:8080", "-t", "/var/www/html" ]
|
||||
|
||||
EXPOSE 8080
|
||||
79
docker/development/docker-compose.mysql.yml
Normal file
79
docker/development/docker-compose.mysql.yml
Normal file
@@ -0,0 +1,79 @@
|
||||
services:
|
||||
php-fpm:
|
||||
container_name: invoiceshelf-dev-php
|
||||
build:
|
||||
context: ../../
|
||||
dockerfile: docker/development/Dockerfile
|
||||
args:
|
||||
- UID=${USRID:-1000}
|
||||
- GID=${GRPID:-1000}
|
||||
target: development
|
||||
volumes:
|
||||
- ../../:/var/www/html
|
||||
networks:
|
||||
- invoiceshelf-dev
|
||||
|
||||
nginx:
|
||||
container_name: invoiceshelf-dev-nginx
|
||||
build:
|
||||
context: ../../
|
||||
dockerfile: docker/development/nginx.Dockerfile
|
||||
environment:
|
||||
- "PHP_FPM_HOST=php-fpm:9000"
|
||||
ports:
|
||||
- '80:80'
|
||||
volumes:
|
||||
- ../../:/var/www/html
|
||||
networks:
|
||||
invoiceshelf-dev:
|
||||
aliases:
|
||||
- invoiceshelf.test
|
||||
|
||||
db:
|
||||
image: mariadb:10.9
|
||||
container_name: invoiceshelf-dev-mysql
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: invoiceshelf
|
||||
MYSQL_DATABASE: invoiceshelf
|
||||
MYSQL_USER: invoiceshelf
|
||||
MYSQL_PASSWORD: invoiceshelf
|
||||
ports:
|
||||
- "3306:3306"
|
||||
volumes:
|
||||
- invoiceshelf-dev-mysql:/var/lib/mysql
|
||||
networks:
|
||||
- invoiceshelf-dev
|
||||
|
||||
adminer:
|
||||
container_name: invoiceshelf-dev-adminer
|
||||
build:
|
||||
context: ../../
|
||||
dockerfile: docker/development/adminer/Dockerfile
|
||||
environment:
|
||||
ADMINER_PLUGINS: tables-filter
|
||||
ADMINER_DESIGN: konya
|
||||
ports:
|
||||
- '8080:8080'
|
||||
networks:
|
||||
- invoiceshelf-dev
|
||||
|
||||
mail:
|
||||
container_name: invoiceshelf-dev-mailpit
|
||||
image: axllent/mailpit:latest
|
||||
restart: always
|
||||
ports:
|
||||
- 1025:1025
|
||||
- 8025:8025
|
||||
networks:
|
||||
- invoiceshelf-dev
|
||||
|
||||
pdf:
|
||||
image: gotenberg/gotenberg:8
|
||||
networks:
|
||||
- invoiceshelf-dev
|
||||
|
||||
networks:
|
||||
invoiceshelf-dev:
|
||||
|
||||
volumes:
|
||||
invoiceshelf-dev-mysql:
|
||||
78
docker/development/docker-compose.pgsql.yml
Normal file
78
docker/development/docker-compose.pgsql.yml
Normal file
@@ -0,0 +1,78 @@
|
||||
services:
|
||||
php-fpm:
|
||||
container_name: invoiceshelf-dev-php
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: .dev/Dockerfile
|
||||
args:
|
||||
- UID=${USRID:-1000}
|
||||
- GID=${GRPID:-1000}
|
||||
target: development
|
||||
volumes:
|
||||
- ../../:/var/www/html
|
||||
networks:
|
||||
- invoiceshelf-dev
|
||||
|
||||
nginx:
|
||||
container_name: invoiceshelf-dev-nginx
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: .dev/nginx.Dockerfile
|
||||
environment:
|
||||
- "PHP_FPM_HOST=php-fpm:9000"
|
||||
ports:
|
||||
- '80:80'
|
||||
volumes:
|
||||
- ../../:/var/www/html
|
||||
networks:
|
||||
invoiceshelf-dev:
|
||||
aliases:
|
||||
- invoiceshelf.test
|
||||
|
||||
db:
|
||||
image: postgres:15
|
||||
container_name: invoiceshelf-dev-pgsql
|
||||
environment:
|
||||
- POSTGRES_PASSWORD=invoiceshelf
|
||||
- POSTGRES_USER=invoiceshelf
|
||||
- POSTGRES_DB=invoiceshelf
|
||||
ports:
|
||||
- 5432:5432
|
||||
volumes:
|
||||
- invoiceshelf-dev-pgsql:/var/lib/postgresql/data
|
||||
networks:
|
||||
- invoiceshelf-dev
|
||||
|
||||
adminer:
|
||||
container_name: invoiceshelf-dev-adminer
|
||||
build:
|
||||
context: ./adminer
|
||||
dockerfile: Dockerfile
|
||||
environment:
|
||||
ADMINER_PLUGINS: tables-filter
|
||||
ADMINER_DESIGN: konya
|
||||
ports:
|
||||
- '8080:8080'
|
||||
networks:
|
||||
- invoiceshelf-dev
|
||||
|
||||
mail:
|
||||
container_name: invoiceshelf-dev-mailpit
|
||||
image: axllent/mailpit:latest
|
||||
restart: always
|
||||
ports:
|
||||
- 1025:1025
|
||||
- 8025:8025
|
||||
networks:
|
||||
- invoiceshelf-dev
|
||||
|
||||
pdf:
|
||||
image: gotenberg/gotenberg:8
|
||||
networks:
|
||||
- invoiceshelf-dev
|
||||
|
||||
networks:
|
||||
invoiceshelf-dev:
|
||||
|
||||
volumes:
|
||||
invoiceshelf-dev-pgsql:
|
||||
62
docker/development/docker-compose.sqlite.yml
Normal file
62
docker/development/docker-compose.sqlite.yml
Normal file
@@ -0,0 +1,62 @@
|
||||
services:
|
||||
php-fpm:
|
||||
container_name: invoiceshelf-dev-php
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: .dev/Dockerfile
|
||||
args:
|
||||
- UID=${USRID:-1000}
|
||||
- GID=${GRPID:-1000}
|
||||
target: development
|
||||
volumes:
|
||||
- ../../:/var/www/html
|
||||
networks:
|
||||
- invoiceshelf-dev
|
||||
|
||||
nginx:
|
||||
container_name: invoiceshelf-dev-nginx
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: .dev/nginx.Dockerfile
|
||||
environment:
|
||||
- "PHP_FPM_HOST=php-fpm:9000"
|
||||
ports:
|
||||
- '80:80'
|
||||
volumes:
|
||||
- ../../:/var/www/html
|
||||
networks:
|
||||
invoiceshelf-dev:
|
||||
aliases:
|
||||
- invoiceshelf.test
|
||||
|
||||
adminer:
|
||||
container_name: invoiceshelf-dev-adminer
|
||||
build:
|
||||
context: ./adminer
|
||||
dockerfile: Dockerfile
|
||||
environment:
|
||||
ADMINER_PLUGINS: tables-filter
|
||||
ADMINER_DESIGN: konya
|
||||
volumes:
|
||||
- ../database:/database
|
||||
ports:
|
||||
- '8080:8080'
|
||||
networks:
|
||||
- invoiceshelf-dev
|
||||
|
||||
mail:
|
||||
container_name: invoiceshelf-dev-mailpit
|
||||
image: axllent/mailpit:latest
|
||||
ports:
|
||||
- '1025:1025'
|
||||
- '8025:8025'
|
||||
networks:
|
||||
- invoiceshelf-dev
|
||||
|
||||
pdf:
|
||||
image: gotenberg/gotenberg:8
|
||||
networks:
|
||||
- invoiceshelf-dev
|
||||
|
||||
networks:
|
||||
invoiceshelf-dev:
|
||||
56
docker/development/nginx.Dockerfile
Normal file
56
docker/development/nginx.Dockerfile
Normal file
@@ -0,0 +1,56 @@
|
||||
FROM --platform=$BUILDPLATFORM node AS static_builder
|
||||
WORKDIR /var/www/html
|
||||
COPY . /var/www/html
|
||||
RUN yarn && yarn build
|
||||
|
||||
FROM nginx AS production
|
||||
ENV PHP_FPM_HOST="php-fpm:9000"
|
||||
COPY --chown=www-data:www-data . /var/www/html
|
||||
COPY --from=static_builder --chown=www-data:www-data /var/www/html/public /var/www/html/public
|
||||
# Map the PHP-FPM host from the PHP_FPM_HOST environment variable to an nging variable
|
||||
RUN mkdir /etc/nginx/templates && cat <<EOF > /etc/nginx/templates/20-invoiceshelf.conf.template
|
||||
server {
|
||||
listen 80 default_server;
|
||||
listen [::]:80 default_server;
|
||||
|
||||
root /var/www/html/public;
|
||||
|
||||
# Set allowed "index" files
|
||||
index index.html index.htm index.php;
|
||||
|
||||
server_name _;
|
||||
|
||||
charset utf-8;
|
||||
|
||||
# Set max upload to 2048M
|
||||
client_max_body_size 2048M;
|
||||
|
||||
# Healthchecks: Set /healthcheck to be the healthcheck URL
|
||||
location /healthcheck {
|
||||
access_log off;
|
||||
|
||||
# set max 5 seconds for healthcheck
|
||||
fastcgi_read_timeout 5s;
|
||||
|
||||
include fastcgi_params;
|
||||
fastcgi_param SCRIPT_NAME /healthcheck;
|
||||
fastcgi_param SCRIPT_FILENAME /healthcheck;
|
||||
fastcgi_pass \${PHP_FPM_HOST};
|
||||
}
|
||||
|
||||
# Have NGINX try searching for PHP files as well
|
||||
location / {
|
||||
try_files \$uri \$uri/ /index.php?\$query_string;
|
||||
}
|
||||
|
||||
# Pass "*.php" files to PHP-FPM
|
||||
location ~ \.php\$ {
|
||||
fastcgi_pass \${PHP_FPM_HOST};
|
||||
fastcgi_index index.php;
|
||||
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
|
||||
include fastcgi_params;
|
||||
fastcgi_buffers 8 8k;
|
||||
fastcgi_buffer_size 8k;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
Reference in New Issue
Block a user