Skip to content

Commit d3787d9

Browse files
feature : introduce a new property DOCKER_COMPOSE_HOST_VOLUME_CHECK to check if the host folder or file exists
1 parent 5186b7b commit d3787d9

13 files changed

+62
-9
lines changed

.env.example.local

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ GOOD_APP_HEALTH_CHECK_PATTERN=xxx
5353
DOCKER_COMPOSE_ENVIRONMENT={"XDEBUG_CONFIG":"idekey=IDE_DEBUG","PHP_IDE_CONFIG":"serverName=laravel-crud-boilerplate"}
5454
DOCKER_BUILD_ARGS={}
5555
DOCKER_COMPOSE_NGINX_SELECTIVE_VOLUMES=[]
56+
DOCKER_COMPOSE_HOST_VOLUME_CHECK=false
5657

5758
NGINX_CLIENT_MAX_BODY_SIZE=50M
5859

.env.example.real

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ DOCKER_BUILD_ARGS={}
5858
DOCKER_COMPOSE_REAL_SELECTIVE_VOLUMES=[]
5959
# This is added on docker-compose-${project_name}-nginx.yml
6060
DOCKER_COMPOSE_NGINX_SELECTIVE_VOLUMES=["./shared/nginx-error-logs:/var/log/nginx"]
61-
61+
# Check if the host folder or file exists
62+
DOCKER_COMPOSE_HOST_VOLUME_CHECK=false
6263

6364
NGINX_CLIENT_MAX_BODY_SIZE=50M
6465

.env.java.local

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ DOCKER_COMPOSE_ENVIRONMENT={"TZ":"Asia/Seoul"}
4848
# docker exec -it CONTAINER_NAME cat /var/log/env_build_args.log
4949
DOCKER_BUILD_ARGS={"DOCKER_BUILDKIT":"1","PROJECT_ROOT_IN_CONTAINER":"/var/www/server/spring-sample-h-auth","APP_ENV":"local"}
5050
DOCKER_COMPOSE_NGINX_SELECTIVE_VOLUMES=[]
51+
DOCKER_COMPOSE_HOST_VOLUME_CHECK=false
5152

5253
NGINX_CLIENT_MAX_BODY_SIZE=50M
5354

.env.java.real

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ DOCKER_COMPOSE_ENVIRONMENT={"TZ":"Asia/Seoul"}
5050
DOCKER_BUILD_ARGS={"DOCKER_BUILDKIT":"1","PROJECT_ROOT_IN_CONTAINER":"/var/www/server/spring-sample-h-auth","APP_ENV":"production"}
5151
DOCKER_COMPOSE_REAL_SELECTIVE_VOLUMES=["./samples/spring-sample-h-auth/logs:/var/www/files"]
5252
DOCKER_COMPOSE_NGINX_SELECTIVE_VOLUMES=["./shared/nginx-error-logs:/var/log/nginx"]
53+
DOCKER_COMPOSE_HOST_VOLUME_CHECK=false
5354

5455
NGINX_CLIENT_MAX_BODY_SIZE=50M
5556

.env.java.real.commercial.ssl.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ DOCKER_BUILD_ARGS={"DOCKER_BUILDKIT":"1","PROJECT_ROOT_IN_CONTAINER":"/var/www/s
5151
# 3) ''/var/web/project/spring-sample-h-auth' is here as well. The thing is you should locate 'application.properties', 'logback-spring.xml', 'yourdomain.com.jks' on the './src/main/resource' folder.
5252
DOCKER_COMPOSE_REAL_SELECTIVE_VOLUMES=["/var/web/files/spring-sample-h-auth:/var/www/files","/var/web/project/spring-sample-h-auth/src/main/resources:/var/www/server/spring-sample-h-auth/src/main/resources"]
5353
DOCKER_COMPOSE_NGINX_SELECTIVE_VOLUMES=["/var/web/files/nginx/spring-sample-h-auth/logs:/var/log/nginx"]
54-
54+
DOCKER_COMPOSE_HOST_VOLUME_CHECK=false
5555

5656
NGINX_CLIENT_MAX_BODY_SIZE=50M
5757

.env.node.local

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ GOOD_APP_HEALTH_CHECK_PATTERN=docs
4545
DOCKER_COMPOSE_ENVIRONMENT={"MONGODB_URL":"mongodb://host.docker.internal:27017/node-boilerplate","NODE_ENV":"development"}
4646
DOCKER_BUILD_ARGS={}
4747
DOCKER_COMPOSE_NGINX_SELECTIVE_VOLUMES=[]
48+
DOCKER_COMPOSE_HOST_VOLUME_CHECK=false
4849

4950
NGINX_CLIENT_MAX_BODY_SIZE=50M
5051

.env.php.local

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ DOCKER_COMPOSE_ENVIRONMENT={"XDEBUG_CONFIG":"idekey=IDE_DEBUG","PHP_IDE_CONFIG":
4949
# docker exec -it CONTAINER_NAME cat /var/log/env_build_args.log
5050
DOCKER_BUILD_ARGS={"SAMPLE":"YAHOO","SAMPLE2":"YAHOO2"}
5151
DOCKER_COMPOSE_NGINX_SELECTIVE_VOLUMES=[]
52-
52+
DOCKER_COMPOSE_HOST_VOLUME_CHECK=false
5353

5454
NGINX_CLIENT_MAX_BODY_SIZE=50M
5555

.env.php.real

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ DOCKER_BUILD_ARGS={"SAMPLE":"YAHOO","SAMPLE2":"YAHOO2","shared_volume_group_id":
5252
# For SSL, the host folder is recommended to be './.docker/ssl' to be synchronized with 'docker-compose-nginx-original.yml'
5353
DOCKER_COMPOSE_REAL_SELECTIVE_VOLUMES=["./shared/app-error-logs:/var/www/app/storage/logs","./.docker/ssl:/etc/apache2/ssl"]
5454
DOCKER_COMPOSE_NGINX_SELECTIVE_VOLUMES=["./shared/nginx-error-logs:/var/log/nginx"]
55+
DOCKER_COMPOSE_HOST_VOLUME_CHECK=false
5556

5657
NGINX_CLIENT_MAX_BODY_SIZE=50M
5758

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ graph TD;
145145
| yq | 4.35.1 | Manual | Use v4.35.1 instead of the latest version. The lastest version causes a parsing error |
146146
| consul (docker image) | 1.14.11 | Auto | An error occurred due to a payload format issue while the lastest version of it was communicating with gliderlabs/registrator. |
147147
| gliderlabs/registrator (docker image) | master | Auto | |
148-
| nginx (docker image) | latest | Auto | Considering changing it to a certain version, but until now no issues have been detected. |
148+
| nginx (docker image) | 1.25.4 | Auto | Considering changing it to a certain version, but until now no issues have been detected. |
149149
| docker | 24~27 | Manual | I think too old versions could cause problems, and the lastest version v27.x causes only a warning message. |
150150
| docker-compose | 2 | Manual | I think too old versions could cause problems, and the v2 is recommended. |
151151

@@ -327,7 +327,8 @@ APP_ENV=real
327327
328328
# The 'real' setting requires defining 'DOCKER_COMPOSE_REAL_SELECTIVE_VOLUMES'.
329329
DOCKER_COMPOSE_REAL_SELECTIVE_VOLUMES=["/my-host/files/:/in-container/files", "/my-host/java-spring-project/src/main/resources:/in-container/java-spring-project/src/main/resources"]
330-
330+
# Check if the host folder or file exists
331+
DOCKER_COMPOSE_HOST_VOLUME_CHECK=false
331332
# If APP_ENV is set to 'local', as specified in 'docker-compose-app-local-original.yml', synchronize your entire project as follows: "HOST_ROOT_LOCATION:PROJECT_LOCATION".
332333
# [IMPORTANT] If this is set to true, Nginx will be restarted, resulting in a short downtime.
333334
# This option should be used when upgrading the Runner. See the "Upgrade" section below.

documents/Deploy-React-Project-with-DBGR.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@
7676
DOCKER_COMPOSE_REAL_SELECTIVE_VOLUMES=["/var/projects/your-app/.docker/nginx/app.conf.ctmpl:/etc/nginx-template/app.conf.ctmpl","/var/projects/files/your-app/logs:/var/log/nginx"]
7777
# [IMPORTANT] Run mkdir -p /var/projects/files/nginx/logs on your host machine
7878
DOCKER_COMPOSE_NGINX_SELECTIVE_VOLUMES=["/var/projects/files/nginx/logs:/var/log/nginx"]
79-
79+
DOCKER_COMPOSE_HOST_VOLUME_CHECK=false
80+
8081
NGINX_CLIENT_MAX_BODY_SIZE=50M
8182
8283
USE_MY_OWN_APP_YML=false

use-app.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,31 @@ apply_docker_compose_environment_onto_app_yaml(){
7272

7373
}
7474

75+
check_docker_compose_real_host_volumes_directories() {
76+
77+
local volumes=$(echo "${docker_compose_real_selective_volumes[@]}" | tr -d '[]"')
78+
79+
for volume in ${volumes}
80+
do
81+
# Extract the local directory path before the colon (:)
82+
local_dir="${volume%%:*}"
83+
84+
# Check if the directory or file exists
85+
if [[ ! -f "$local_dir" && ! -d "$local_dir" ]]; then
86+
echo "[ERROR] The local path '$local_dir' specified in DOCKER_COMPOSE_REAL_SELECTIVE_VOLUMES does not exist. Exiting..."
87+
exit 1
88+
fi
89+
done
90+
}
91+
7592
apply_docker_compose_volumes_onto_app_real_yaml(){
7693

7794
check_yq_installed
7895

96+
if [[ ${docker_compose_host_volume_check} == 'true' ]]; then
97+
check_docker_compose_real_host_volumes_directories
98+
fi
99+
79100
echo "[NOTICE] DOCKER_COMPOSE_REAL_SELECTIVE_VOLUMES on .env is now being applied to docker-${orchestration_type}-${project_name}-real.yml."
80101

81102
if [[ ${orchestration_type} == 'stack' ]]; then

use-common.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ display_planned_transition() {
2222
echo " Current State (${current_state})"
2323
echo "─────────────────────────────"
2424
echo " |"
25-
echo " >> Transition planned <<"
25+
echo " >> Transition planned <<"
2626
echo " v"
2727
echo "─────────────────────────────"
2828
echo " Target State (${target_state})"
@@ -41,7 +41,7 @@ display_immediate_transition() {
4141
echo " Current State (${current_state})"
4242
echo "─────────────────────────────"
4343
echo " |"
44-
echo " >> Immediate Transition <<"
44+
echo " >> Immediate Transition <<"
4545
echo " v"
4646
echo "─────────────────────────────"
4747
echo " Target State (${target_state})"
@@ -135,6 +135,7 @@ cache_non_dependent_global_vars() {
135135
fi
136136

137137
docker_compose_nginx_selective_volumes=$(get_value_from_env "DOCKER_COMPOSE_NGINX_SELECTIVE_VOLUMES")
138+
docker_compose_host_volume_check=$(get_value_from_env "DOCKER_COMPOSE_HOST_VOLUME_CHECK")
138139

139140
docker_layer_corruption_recovery=$(get_value_from_env "DOCKER_LAYER_CORRUPTION_RECOVERY")
140141

use-nginx.sh

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,33 @@ apply_ports_onto_nginx_yaml(){
2626
done
2727

2828
}
29+
30+
check_docker_compose_nginx_host_volumes_directories() {
31+
32+
local volumes=$(echo "${docker_compose_nginx_selective_volumes[@]}" | tr -d '[]"')
33+
34+
for volume in ${volumes}
35+
do
36+
# Extract the local directory path before the colon (:)
37+
local_dir="${volume%%:*}"
38+
39+
# Check if the directory or file exists
40+
if [[ ! -f "$local_dir" && ! -d "$local_dir" ]]; then
41+
echo "[ERROR] The local path '$local_dir' specified in DOCKER_COMPOSE_NGINX_SELECTIVE_VOLUMES does not exist. Exiting..."
42+
exit 1
43+
fi
44+
done
45+
}
46+
47+
2948
apply_docker_compose_volumes_onto_app_nginx_yaml(){
3049

3150
check_yq_installed
3251

52+
if [[ ${docker_compose_host_volume_check} == 'true' ]]; then
53+
check_docker_compose_nginx_host_volumes_directories
54+
fi
55+
3356
echo "[NOTICE] DOCKER_COMPOSE_NGINX_SELECTIVE_VOLUMES on .env is now being applied to docker-compose-${project_name}-nginx.yml."
3457

3558
for volume in "${docker_compose_nginx_selective_volumes[@]}"
@@ -293,7 +316,7 @@ nginx_down(){
293316
nginx_up(){
294317

295318
echo "[NOTICE] Up NGINX Container."
296-
PROJECT_NAME=${project_name} docker-compose -f docker-compose-${project_name}-nginx.yml up -d || echo "[ERROR] Critical - ${project_name}-nginx UP failure"
319+
PROJECT_NAME=${project_name} docker-compose -f docker-compose-${project_name}-nginx.yml up -d || echo "[ERROR] Critical - ${project_name}-nginx UP failure."
297320

298321
}
299322

0 commit comments

Comments
 (0)