Skip to content

Commit

Permalink
Add docker developement environment
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-anne authored Jun 20, 2024
1 parent 682d988 commit 809e759
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 5 deletions.
25 changes: 25 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# GLPI docker devcontainers

The docker devcontainers are meant to be used by VSCode or in a Github Codespaces environment.

## Services ports

By default, the following ports are exposed:
- `8080` for the GLPI web server,
- `8025` for the Mailpit web server,
- `8090` for the Adminer web server.

You can customize these ports by creating a `.devcontainer/docker-compose.override.yaml` file.

```yaml
services:
app:
ports: !override
- "9000:80"
mailpit:
ports: !override
- "9025:8025"
adminer:
ports: !override
- "9080:8080"
```
36 changes: 36 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/php-mariadb
{
"name": "GLPI docker devcontainer",
"dockerComposeFile": "docker-compose.yaml",
"service": "app",
"workspaceFolder": "/var/www/glpi",

"forwardPorts": [8080, 8090, 8025],
"portsAttributes": {
"8080": {
"label": "GLPI"
},
"8090": {
"label": "Adminer"
},
"8025": {
"label": "Mailpit"
}
},

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "composer build",

// automatically install these extensions when opening the dev container in vscode
"customizations": {
"vscode": {
"extensions": [
"bmewburn.vscode-intelephense-client",
"xdebug.php-debug",
"mblode.twig-language-2",
"dbaeumer.vscode-eslint"
]
}
}
}
51 changes: 51 additions & 0 deletions .devcontainer/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
services:
app:
container_name: "glpi-app"
build:
context: "../.docker/app"
restart: "unless-stopped"
volumes:
- "..:/var/www/glpi:rw"
ports:
- "8080:80"
depends_on:
- db
extra_hosts:
- "host.docker.internal:host-gateway"

db:
container_name: "glpi-db"
image: "mariadb:11.4"
restart: "unless-stopped"
volumes:
- "db:/var/lib/mysql"
- "./initdb.sql:/docker-entrypoint-initdb.d/initdb.sql"
environment:
MARIADB_ROOT_PASSWORD: "glpi"
MARIADB_DATABASE: "glpi"
MARIADB_USER: "glpi"
MARIADB_PASSWORD: "glpi"
expose:
- "3306"

mailpit:
container_name: "glpi-mailpit"
image: "axllent/mailpit"
restart: "unless-stopped"
expose:
- "1025"
ports:
- "8025:8025"

adminer:
container_name: "glpi-adminer"
image: "adminer:latest"
restart: "unless-stopped"
ports:
- "8090:8080"
environment:
- "ADMINER_DEFAULT_SERVER=db"
command: ["php", "-S", "0.0.0.0:8080", "-t", "/var/www/html"]

volumes:
db:
7 changes: 7 additions & 0 deletions .devcontainer/initdb.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This SQL queries contained in this file will be executed on every database container startup.

# Required for timezones usage.
# This may be executed before automatic `glpi` user creation, so we have to create it manually.
CREATE USER IF NOT EXISTS 'glpi'@'%' IDENTIFIED BY 'glpi';
SET PASSWORD FOR 'glpi'@'%' = PASSWORD('glpi');
GRANT SELECT ON `mysql`.`time_zone_name` TO 'glpi'@'%';
57 changes: 57 additions & 0 deletions .docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# GLPI docker development environment

The docker development environment can be easilly instanciated by running the command `docker compose up -d`
from the GLPI root directory.

## Custom configuration

You can customize the docker services by creating a `docker-compose.override.yaml` file in the GLPI root directory.

## HTTP server

By default, the HTTP port is published to on the `8080` port on the host machine.
You can change it in the `docker-compose.override.yaml` file.

```yaml
services:
app:
ports: !override
- "9000:80"
```
The default uid/gid used by the docker container is `1000`. If your host user uses different uid/gid, you may encounter
file permissions issues. To prevent this, you can customize them using the corresponding build args in
the `docker-compose.override.yaml` file.

```yaml
services:
app:
build:
args:
HOST_GROUP_ID: "${HOST_GROUP_ID:-1000}"
HOST_USER_ID: "${HOST_USER_ID:-1000}"
```

### Database server

By default, the database service is not provided. You can add it in the `docker-compose.override.yaml` file.

```yaml
services:
database:
container_name: "db"
image: "mariadb:11.0"
restart: "unless-stopped"
environment:
MYSQL_ROOT_PASSWORD: "R00tP4ssw0rd"
MYSQL_DATABASE: "glpi"
MYSQL_USER: "glpi"
MYSQL_PASSWORD: "P4ssw0rd"
ports:
- "3306:3306"
volumes:
- "db:/var/lib/mysql"
volumes:
db:
```
21 changes: 21 additions & 0 deletions .docker/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM ghcr.io/glpi-project/glpi-development-env:latest

USER root

# Workaround to make apache use same UID/GID as host user.
ARG HOST_GROUP_ID=1000
RUN groupmod --gid ${HOST_GROUP_ID} www-data
ARG HOST_USER_ID=1000
RUN usermod --uid ${HOST_USER_ID} www-data

# Allow login as www-data user and allow it to execute sudo
RUN usermod --shell /bin/bash www-data
RUN echo "www-data ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

# Make www-data user home persistent for cache purpose.
RUN mkdir --parents /home/www-data \
&& chown www-data:www-data /home/www-data \
&& usermod --home /home/www-data www-data
VOLUME /home/www-data

USER www-data
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ phpunit.xml
/inventory-vendors/*.json
/locales/*.mo
/inc/downstream.php
/docker-compose.override.yaml
/.devcontainer/docker-compose.override.yaml
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
services:
app:
container_name: "glpi"
build:
context: ".docker/app"
restart: "unless-stopped"
volumes:
- ".:/var/www/glpi:rw"
ports:
- "8080:80"
extra_hosts:
- "host.docker.internal:host-gateway"
1 change: 1 addition & 0 deletions tools/build_glpi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ find $WORKING_DIR -depth \( -iname ".*" ! -iname ".htaccess" \) -exec rm -rf {}
dev_nodes=(
"composer.json"
"composer.lock"
"docker-compose.yaml"
"ISSUE_TEMPLATE.md"
"locales/glpi.pot"
"node_modules"
Expand Down

0 comments on commit 809e759

Please sign in to comment.