Skip to content

Commit ad6f36f

Browse files
committed
Allow Moodle app port to be configured
Before this change the moodle-app was always put onto port 8100, this makes it impossible to have multiple instances of moodle-docker running if they also have a copy of the app running. After this change while be default nothing should change you may now select the exposed port, or disable it altogether using MOODLE_DOCKER_APP_PORT Before this change MOODLE_DOCKER_APP_PORT was used internally to select the source port for the app, this is now done using MOODLE_DOCKER_APP_INTERNAL_PORT because that name fits better with the other environment variables that let the user set the port available on the host.
1 parent 83d6cc6 commit ad6f36f

File tree

7 files changed

+50
-17
lines changed

7 files changed

+50
-17
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ When you change them, use `bin/moodle-docker-compose down && bin/moodle-docker-c
229229
| `MOODLE_DOCKER_SELENIUM_VNC_PORT` | no | any integer value (or bind_ip:integer)| not set | If set, the selenium node will expose a vnc session on the port specified. Similar to MOODLE_DOCKER_WEB_PORT, you can optionally define the host IP to bind to. If you just set the port, VNC binds to 127.0.0.1 |
230230
| `MOODLE_DOCKER_APP_PATH` | no | path on your file system | not set | If set and the chrome browser is selected, it will start an instance of the Moodle app from your local codebase |
231231
| `MOODLE_DOCKER_APP_VERSION` | no | a valid [app docker image version](https://docs.moodle.org/dev/Moodle_App_Docker_images) | not set | If set will start an instance of the Moodle app if the chrome browser is selected |
232+
| `MOODLE_DOCKER_APP_PORT` | no | any integer value | 8100 | The app will be served on this port, 0 will mean the app is not available on the host machine |
232233
| `MOODLE_DOCKER_TIMEOUT_FACTOR` | no | any integer value | 1 | If set the timeouts in behat will be multiplied by the factor |
233234

234235
In addition to that, `MOODLE_DOCKER_RUNNING=1` env variable is defined and available

bin/moodle-docker-compose

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,23 @@ then
103103
export MOODLE_DOCKER_APP_NODE_VERSION="$appnodeversion"
104104
fi
105105

106-
# Guess mobile app port (only when using Docker app images)
107-
if [[ -z "$MOODLE_DOCKER_APP_PORT" ]] && [[ ! -z "$MOODLE_DOCKER_APP_VERSION" ]];
106+
107+
if [[ -z "$MOODLE_DOCKER_APP_INTERNAL_PORT" ]] && [[ ! -z "$MOODLE_DOCKER_APP_VERSION" ]];
108108
then
109+
# Guess mobile app port (only when using Docker app images)
109110
if [[ "$MOODLE_DOCKER_APP_RUNTIME" = "ionic5" ]];
110111
then
111-
export MOODLE_DOCKER_APP_PORT="80"
112+
export MOODLE_DOCKER_APP_INTERNAL_PORT="80"
112113
else
113-
export MOODLE_DOCKER_APP_PORT="443"
114+
export MOODLE_DOCKER_APP_INTERNAL_PORT="443"
114115
fi
115116
fi
116117

118+
if [[ -z "$MOODLE_DOCKER_APP_PORT" ]];
119+
then
120+
export MOODLE_DOCKER_APP_PORT="8100"
121+
fi
122+
117123
# Guess mobile app protocol
118124
if [[ -z "$MOODLE_DOCKER_APP_PROTOCOL" ]];
119125
then
@@ -146,10 +152,20 @@ then
146152
if [[ ! -z "$MOODLE_DOCKER_APP_PATH" ]];
147153
then
148154
dockercompose="${dockercompose} -f ${basedir}/moodle-app-dev.yml"
155+
156+
if [[ "$MOODLE_DOCKER_APP_PORT" != "0" ]];
157+
then
158+
dockercompose="${dockercompose} -f ${basedir}/moodle-app-dev-port.yml"
159+
fi
149160
elif [[ ! -z "$MOODLE_DOCKER_APP_VERSION" ]];
150161
then
151162
# Mobile app using a docker image
152163
dockercompose="${dockercompose} -f ${basedir}/moodle-app.yml"
164+
165+
if [[ "$MOODLE_DOCKER_APP_PORT" != "0" ]];
166+
then
167+
dockercompose="${dockercompose} -f ${basedir}/moodle-app-port.yml"
168+
fi
153169
fi
154170
fi
155171

bin/moodle-docker-compose.cmd

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,21 @@ IF "%MOODLE_DOCKER_APP_NODE_VERSION%"=="" (
7171
)
7272
)
7373

74-
REM Guess mobile app port (only when using Docker app images)
75-
IF "%MOODLE_DOCKER_APP_PORT%"=="" (
74+
IF "%MOODLE_DOCKER_APP_INTERNAL_PORT%"=="" (
7675
IF NOT "%MOODLE_DOCKER_APP_VERSION%"=="" (
76+
REM Guess mobile app port (only when using Docker app images)
7777
IF "%MOODLE_DOCKER_APP_RUNTIME%"=="ionic5" (
78-
SET MOODLE_DOCKER_APP_PORT=80
78+
SET MOODLE_DOCKER_APP_INTERNAL_PORT=80
7979
) ELSE (
80-
SET MOODLE_DOCKER_APP_PORT=443
80+
SET MOODLE_DOCKER_APP_INTERNAL_PORT=443
8181
)
8282
)
8383
)
8484

85+
IF "%MOODLE_DOCKER_APP_PORT%"=="" (
86+
SET MOODLE_DOCKER_APP_PORT=8100
87+
)
88+
8589
REM Guess mobile app protocol
8690
IF "%MOODLE_DOCKER_APP_PROTOCOL%"=="" (
8791
if "%MOODLE_DOCKER_APP_RUNTIME%"=="ionic5" (
@@ -109,9 +113,17 @@ IF "%MOODLE_DOCKER_BROWSER_TAG%"=="" (
109113

110114
IF "%MOODLE_DOCKER_BROWSER_NAME%"=="chrome" (
111115
IF NOT "%MOODLE_DOCKER_APP_PATH%"=="" (
112-
SET DOCKERCOMPOSE=%DOCKERCOMPOSE% -f "%BASEDIR%\moodle-app-dev.yml"
116+
IF NOT "%MOODLE_DOCKER_APP_PORT%"=="0" (
117+
SET DOCKERCOMPOSE=%DOCKERCOMPOSE% -f "%BASEDIR%\moodle-app-dev.yml" -f "%BASEDIR%\moodle-app-dev-port.yml"
118+
) ELSE (
119+
SET DOCKERCOMPOSE=%DOCKERCOMPOSE% -f "%BASEDIR%\moodle-app-dev.yml"
120+
)
113121
) ELSE IF NOT "%MOODLE_DOCKER_APP_VERSION%"=="" (
114-
SET DOCKERCOMPOSE=%DOCKERCOMPOSE% -f "%BASEDIR%\moodle-app.yml"
122+
IF NOT "%MOODLE_DOCKER_APP_PORT%"=="0" (
123+
SET DOCKERCOMPOSE=%DOCKERCOMPOSE% -f "%BASEDIR%\moodle-app.yml" -f "%BASEDIR%\moodle-app-port.yml"
124+
) ELSE (
125+
SET DOCKERCOMPOSE=%DOCKERCOMPOSE% -f "%BASEDIR%\moodle-app.yml"
126+
)
115127
)
116128
)
117129

moodle-app-dev-port.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
services:
2+
moodleapp:
3+
ports:
4+
- "$MOODLE_DOCKER_APP_PORT:8100"
5+
- "35729:35729"
6+
- "53703:53703"

moodle-app-dev.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,3 @@ services:
1313
- 8100
1414
- 35729
1515
- 53703
16-
ports:
17-
- "8100:8100"
18-
- "35729:35729"
19-
- "53703:53703"

moodle-app-port.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
services:
2+
moodleapp:
3+
ports:
4+
- "$MOODLE_DOCKER_APP_PORT:$MOODLE_DOCKER_APP_INTERNAL_PORT"

moodle-app.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ services:
22
webserver:
33
environment:
44
MOODLE_DOCKER_APP: "true"
5-
MOODLE_DOCKER_APP_PORT: ${MOODLE_DOCKER_APP_PORT}
5+
MOODLE_DOCKER_APP_PORT: ${MOODLE_DOCKER_APP_INTERNAL_PORT}
66
MOODLE_DOCKER_APP_PROTOCOL: ${MOODLE_DOCKER_APP_PROTOCOL}
77
moodleapp:
88
image: "moodlehq/moodleapp:${MOODLE_DOCKER_APP_VERSION}"
9-
ports:
10-
- "8100:$MOODLE_DOCKER_APP_PORT"

0 commit comments

Comments
 (0)