Skip to content

Commit 1f02ca9

Browse files
committed
Improved workflow (by @erseco)
1 parent 534f9b6 commit 1f02ca9

File tree

4 files changed

+146
-21
lines changed

4 files changed

+146
-21
lines changed

.env.dist

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# This file (.env.dist) is an example template for the environment variables required by the application.
2+
# The .env file is not versioned in the repository and should be created by duplicating this file.
3+
# To use it, copy this file as .env and define the appropriate values.
4+
# The environment variables defined in .env will be automatically loaded by Docker Compose.
5+
6+
APP_ENV=prod
7+
APP_DEBUG=0
8+
APP_SECRET=CHANGE_THIS_TO_A_SECRET
9+
APP_PORT=8080
10+
APP_ONLINE_MODE=1
11+
XDEBUG_MODE=off # You can enable it by changing to "debug"
12+
XDEBUG_CONFIG="client_host=host.docker.internal"
13+
14+
EXELEARNING_WEB_SOURCECODE_PATH=
15+
EXELEARNING_WEB_CONTAINER_TAG=latest
16+
17+
# Test user data
18+
19+
TEST_USER_USERNAME=user
20+
TEST_USER_PASSWORD=1234
21+

Makefile

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,32 +42,36 @@ endif
4242

4343
# Start Docker containers in interactive mode
4444
# This target builds and starts the Docker containers, allowing interaction with the terminal.
45-
up: check-docker
46-
docker compose up --build
45+
up: check-docker check-env
46+
docker compose up
4747

4848
# Start Docker containers in background mode (daemon)
4949
# This target builds and starts the Docker containers in the background.
50-
upd: check-docker
50+
upd: check-docker check-env
5151
docker compose up -d
5252

5353
# Stop and remove Docker containers
5454
# This target stops and removes all running Docker containers.
55-
down: check-docker
55+
down: check-docker check-env
5656
docker compose down
5757

5858
# Pull the latest images from the registry
5959
# This target pulls the latest Docker images from the registry.
60-
pull: check-docker
60+
pull: check-docker check-env
6161
docker compose -f docker-compose.yml pull
6262

6363
# Build or rebuild Docker containers
6464
# This target builds or rebuilds the Docker containers.
65-
build: check-docker
65+
build: check-docker check-env
66+
@if [ -z "$$(grep ^EXELEARNING_WEB_SOURCECODE_PATH .env | cut -d '=' -f2)" ]; then \
67+
echo "Error: EXELEARNING_WEB_SOURCECODE_PATH is not defined or empty in the .env file"; \
68+
exit 1; \
69+
fi
6670
docker compose build
6771

6872
# Open a shell inside the moodle container
6973
# This target opens an interactive shell session inside the running Moodle container.
70-
shell: check-docker
74+
shell: check-docker check-env
7175
docker compose exec moodle sh
7276

7377
# Clean up and stop Docker containers, removing volumes and orphan containers

README.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,106 @@ Go to the URL:
6464

6565
* A forbidden files list can be configurad here. Enter each forbidden file as a PHP regular expression (RE) on a new line.
6666

67+
68+
## Development using Makefile
69+
70+
To facilitate development, a `Makefile` is included to simplify Docker-based workflows.
71+
72+
### Requirements
73+
74+
- Docker
75+
- Docker Compose
76+
77+
### Available Commands
78+
79+
- **Pull the latest images**:
80+
To pull the latest Docker images from the registry, use:
81+
82+
```bash
83+
make pull
84+
```
85+
> **Note**: Docker need to be logged in ghcr.io *([more info...])(https://docs.github.com/es/packages/working-with-a-github-packages-registry/working-with-the-container-registry)*
86+
87+
- **Start the development environment**:
88+
To start the Docker containers in interactive mode, run:
89+
90+
```bash
91+
make up
92+
```
93+
94+
To start the containers in the background (daemon mode), run:
95+
96+
```bash
97+
make upd
98+
```
99+
100+
- **Build the Docker containers**:
101+
You can build the Docker containers using the following command. This will also check if the `EXELEARNING_WEB_SOURCECODE_PATH` is defined in the `.env` file:
102+
103+
```bash
104+
make build
105+
```
106+
107+
> **Note**: If `EXELEARNING_WEB_SOURCECODE_PATH` is not defined, the build will fail and display an error message.
108+
109+
- **Access a shell in the Moodle container**:
110+
To open a shell inside the running Moodle container, use:
111+
112+
```bash
113+
make shell
114+
```
115+
116+
- **Stop and remove containers**:
117+
To stop and remove the running Docker containers, run:
118+
119+
```bash
120+
make down
121+
```
122+
123+
- **Clean up the environment**:
124+
To stop and remove all Docker containers, volumes, and orphaned containers, run:
125+
126+
```bash
127+
make clean
128+
```
129+
130+
### Environment Variables
131+
132+
You can configure various settings using the `.env` file. If this file does not exist, it will be automatically generated by copying from `.env.dist`. Key variables to configure:
133+
134+
- `EXELEARNING_WEB_SOURCECODE_PATH`: Define the path to the eXeLearning source code if you want to work with a local version.
135+
- `APP_PORT`: Define the port on which the application will run.
136+
- `APP_SECRET`: Set a secret key for the application.
137+
138+
### Example Workflow
139+
140+
1. Ensure you have Docker running and properly configured.
141+
2. Define your environment variables in the `.env` file or copy from `.env.dist`.
142+
3. Pull the latest Docker images:
143+
144+
```bash
145+
make pull
146+
```
147+
148+
4. Start the environment:
149+
150+
```bash
151+
make up
152+
```
153+
154+
5. Build the environment if necessary:
155+
156+
```bash
157+
make build
158+
```
159+
160+
6. Once development is complete, stop and clean up the environment:
161+
162+
```bash
163+
make down
164+
make clean
165+
```
166+
67167
## About
68168

69169
Copyright 2023:

docker-compose.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ version: "3"
33
services:
44

55
exelearning-web:
6-
image: ghcr.io/exelearning/exelearning-web:latest
7-
# build: ${EXELEARNING_WEB_PATH:-} # If EXELEARNING_WEB_PATH is not defined, skip build
6+
image: ghcr.io/exelearning/exelearning-web:${EXELEARNING_WEB_CONTAINER_TAG}
7+
build: ${EXELEARNING_WEB_SOURCECODE_PATH:-} # If EXELEARNING_WEB__SOURCECODE_PATH is not defined, skip build
88
ports:
9-
- 8080:8080
9+
- ${APP_PORT}:8080
1010
restart: unless-stopped # Restart the container unless it is stopped manually
1111
volumes:
1212
- mnt-data:/mnt/data:rw # Mount the volume for persistent data
1313
environment:
14-
APP_ENV: prod
15-
APP_DEBUG: 0
16-
XDEBUG_MODE: off
17-
APP_SECRET: CHANGE_THIS_TO_A_SECRET
14+
APP_ENV: ${APP_ENV}
15+
APP_DEBUG: ${APP_DEBUG}
16+
XDEBUG_MODE: ${XDEBUG_MODE}
17+
APP_SECRET: ${APP_SECRET}
1818
PRE_CONFIGURE_COMMANDS:
1919
POST_CONFIGURE_COMMANDS: |
2020
echo "this is a test line 1"
2121
echo "this is a test line 2"
22-
php bin/console app:create-user [email protected] testpassword testuser --no-fail
22+
php bin/console app:create-user ${TEST_USER_EMAIL} ${TEST_USER_PASSWORD} ${TEST_USER_USERNAME} --no-fail
2323
2424
moodle:
2525
image: erseco/alpine-moodle
@@ -36,19 +36,19 @@ services:
3636
DB_PASS: moodle
3737
DB_PREFIX: mdl_
3838
DEBUG: true
39-
MOODLE_EMAIL: [email protected]
39+
MOODLE_EMAIL: ${TEST_USER_EMAIL}
4040
MOODLE_LANGUAGE: es
41-
MOODLE_SITENAME: New-Site
42-
MOODLE_USERNAME: testuser
43-
MOODLE_PASSWORD: testpassword
41+
MOODLE_SITENAME: Moodle-eXeLearning
42+
MOODLE_USERNAME: ${TEST_USER_USERNAME}
43+
MOODLE_PASSWORD: ${TEST_USER_PASSWORD}
4444
PRE_CONFIGURE_COMMANDS: |
4545
echo 'This is a pre-configure command'
4646
POST_CONFIGURE_COMMANDS: |
4747
echo 'This is a post-configure command'
4848
echo 'Forcing upgrade to re-install exe plugin...'
4949
php admin/cli/upgrade.php --non-interactive
50-
php admin/cli/cfg.php --component=exescorm --name=exeonlinebaseuri --set=http://localhost:8080
51-
php admin/cli/cfg.php --component=exescorm --name=hmackey1 --set=CHANGE_THIS_TO_A_SECRET
50+
php admin/cli/cfg.php --component=exescorm --name=exeonlinebaseuri --set=http://localhost:${APP_PORT}
51+
php admin/cli/cfg.php --component=exescorm --name=hmackey1 --set=${APP_SECRET}
5252
ports:
5353
- 80:8080
5454
volumes:

0 commit comments

Comments
 (0)