Skip to content

Commit f2cc4b6

Browse files
Allow user to change config and scripts folder
1 parent 687a6a8 commit f2cc4b6

File tree

7 files changed

+37
-28
lines changed

7 files changed

+37
-28
lines changed

Diff for: docs/config_flags.md

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ The following flags are a list of all the currently supported options that can b
2121
| Name | Description |
2222
|-------------------------|----------------------------------------------------------------------------------------------------------------|
2323
| WEBROOT | Change the default webroot directory from `/var/www/html` to your own setting |
24+
| CONFIG_FOLDER | Change the default config directory from `/var/www/html/conf` to your own setting |
2425
| ERRORS | Set to 1 to display PHP Errors in the browser |
2526
| HIDE_NGINX_HEADERS | Disable by setting to 0, default behaviour is to hide nginx + php version in headers |
2627
| PHP_MEM_LIMIT | Set higher PHP memory limit, default is 128 Mb |
@@ -31,6 +32,7 @@ The following flags are a list of all the currently supported options that can b
3132
| REAL_IP_HEADER | set to 1 to enable real ip support in the logs |
3233
| REAL_IP_FROM | set to your CIDR block for real ip in logs |
3334
| RUN_SCRIPTS | Set to 1 to execute scripts |
35+
| SCRIPTS_FOLDER | Change the default script folder from `/var/www/html/scripts` to your won setting |
3436
| PGID | Set to GroupId you want to use for nginx (helps permissions when using local volume) |
3537
| PUID | Set to UserID you want to use for nginx (helps permissions when using local volume) |
3638
| REMOVE_FILES | Use REMOVE_FILES=0 to prevent the script from clearing out /var/www/html (useful for working with local files) |

Diff for: docs/nginx_configs.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## Custom Nginx Config files
22
Sometimes you need a custom config file for nginx to do rewrites or password protection, etc. For this reason we've included the ability to have custom nginx configs pulled directly from your git source. Please have a read of the [repo layout guidelines](repo_layout.md) for more information. Its pretty simple to enable this, all you need to do is include a folder in the root of your repository called ```conf/nginx/``` within this folder you need to include a file called ```nginx-site.conf``` which will contain your default nginx site config. If you wish to have a custom file for SSL you simply include a file called ```nginx-site-ssl.conf``` in the same directory. These files will then be swapped in after you code is cloned.
3+
In addition, you can configure __CONFIG_FOLDER__ with your custome path.
34

45
## REAL IP / X-Forwarded-For Headers
56
If you operate your container behind a load balancer, an ELB on AWS for example, you need to configure nginx to get the real IP and not the load balancer IP in the logs by using the X-Forwarded-For. We've provided some handy flags to let you do this. You need to set both of these to get this to work:

Diff for: docs/scripting_templating.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## Scripting
22
There is often an occasion where you need to run a script on code to do a transformation once code lands in the container. For this reason we have developed scripting support. By including a scripts folder in your git repository and passing the __RUN_SCRIPTS=1__ flag to your command line the container will execute your scripts. Please see the [repo layout guidelines](https://gitlab.com/ric_harvey/nginx-php-fpm/blob/master/docs/repo_layout.md) for more details on how to organise this.
3+
In addition, you can configure __SCRIPT_FOLDER__ with your custome path.
34

45
## Using environment variables / templating
56
To set the variables pass them in as environment variables on the docker command line.

Diff for: scripts/letsencrypt-setup

-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ else
1010
# change nginx for webroot and domain name
1111
sed -i "s/##DOMAIN##/${DOMAIN}/g" /etc/nginx/sites-enabled/default-ssl.conf
1212
sed -i "s#root /var/www/html;#root ${WEBROOT};#g" /etc/nginx/sites-available/default-ssl.conf
13-
if [ ! -z "$WEBROOT" ]; then
14-
webroot=$WEBROOT
15-
sed -i "s#root /var/www/html;#root ${webroot};#g" /etc/nginx/sites-available/default-ssl.conf
16-
fi
1713

1814
supervisorctl restart nginx
1915

Diff for: scripts/pull

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ if [ -z "$GIT_NAME" ]; then
1111
fi
1212

1313
# Try auto install for composer
14-
if [ -f "/var/www/html/composer.lock" ]; then
15-
composer install --no-dev --working-dir=/var/www/html
14+
if [ -f "${WEBROOT}/composer.lock" ]; then
15+
composer install --no-dev --working-dir=${WEBROOT}
1616
fi
1717

18-
cd /var/www/html
18+
cd ${WEBROOT}
1919
git pull || exit 1
20-
chown -Rf nginx:nginx /var/www/html
20+
chown -Rf nginx:nginx ${WEBROOT}

Diff for: scripts/push

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if [ -z "$GIT_NAME" ]; then
1515
fi
1616

1717
ts=$(timestamp)
18-
cd /var/www/html
18+
cd ${WEBROOT}
1919
git add .
2020
git commit -a -m "push from container $ts"
2121
git push

Diff for: scripts/start.sh

+28-19
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fi
2121
if [ ! -z "$WEBROOT" ]; then
2222
sed -i "s#root /var/www/html;#root ${WEBROOT};#g" /etc/nginx/sites-available/default.conf
2323
else
24-
webroot=/var/www/html
24+
WEBROOT=/var/www/html
2525
fi
2626

2727
# Setup git variables
@@ -34,14 +34,14 @@ if [ ! -z "$GIT_NAME" ]; then
3434
fi
3535

3636
# Dont pull code down if the .git folder exists
37-
if [ ! -d "/var/www/html/.git" ]; then
37+
if [ ! -d "${WEBROOT}/.git" ]; then
3838
# Pull down code from git for our site!
3939
if [ ! -z "$GIT_REPO" ]; then
4040
# Remove the test index file if you are pulling in a git repo
4141
if [ ! -z ${REMOVE_FILES} ] && [ ${REMOVE_FILES} == 0 ]; then
4242
echo "skiping removal of files"
4343
else
44-
rm -Rf /var/www/html/*
44+
rm -Rf ${WEBROOT}/*
4545
fi
4646
GIT_COMMAND='git clone '
4747
if [ ! -z "$GIT_BRANCH" ]; then
@@ -57,30 +57,34 @@ if [ ! -d "/var/www/html/.git" ]; then
5757
GIT_COMMAND=${GIT_COMMAND}" https://${GIT_USERNAME}:${GIT_PERSONAL_TOKEN}@${GIT_REPO}"
5858
fi
5959
fi
60-
${GIT_COMMAND} /var/www/html || exit 1
60+
${GIT_COMMAND} ${WEBROOT} || exit 1
6161
if [ ! -z "$GIT_TAG" ]; then
6262
git checkout ${GIT_TAG} || exit 1
6363
fi
6464
if [ ! -z "$GIT_COMMIT" ]; then
6565
git checkout ${GIT_COMMIT} || exit 1
6666
fi
6767
if [ -z "$SKIP_CHOWN" ]; then
68-
chown -Rf nginx.nginx /var/www/html
68+
chown -Rf nginx.nginx ${WEBROOT}
6969
fi
7070
fi
7171
fi
7272

73+
if [ -z "$CONFIG_FOLDER" ]; then
74+
CONFIG_FOLDER=${WEBROOT}/conf
75+
fi
76+
7377
# Enable custom nginx config files if they exist
74-
if [ -f /var/www/html/conf/nginx/nginx.conf ]; then
75-
cp /var/www/html/conf/nginx/nginx.conf /etc/nginx/nginx.conf
78+
if [ -f ${CONFIG_FOLDER}/nginx.conf ]; then
79+
cp ${CONFIG_FOLDER}/nginx.conf /etc/nginx/nginx.conf
7680
fi
7781

78-
if [ -f /var/www/html/conf/nginx/nginx-site.conf ]; then
79-
cp /var/www/html/conf/nginx/nginx-site.conf /etc/nginx/sites-available/default.conf
82+
if [ -f ${CONFIG_FOLDER}/nginx-site.conf ]; then
83+
cp ${CONFIG_FOLDER}/nginx-site.conf /etc/nginx/sites-available/default.conf
8084
fi
8185

82-
if [ -f /var/www/html/conf/nginx/nginx-site-ssl.conf ]; then
83-
cp /var/www/html/conf/nginx/nginx-site-ssl.conf /etc/nginx/sites-available/default-ssl.conf
86+
if [ -f ${CONFIG_FOLDER}/nginx-site-ssl.conf ]; then
87+
cp ${CONFIG_FOLDER}/nginx-site-ssl.conf /etc/nginx/sites-available/default-ssl.conf
8488
fi
8589

8690

@@ -169,7 +173,7 @@ if [[ "$ENABLE_XDEBUG" == "1" ]] ; then
169173
fi
170174
fi
171175
fi
172-
else
176+
else
173177
if [ -f $XdebugFile ]; then
174178
echo "Disabling Xdebug"
175179
rm $XdebugFile
@@ -185,31 +189,36 @@ if [ ! -z "$PUID" ]; then
185189
adduser -D -S -h /var/cache/nginx -s /sbin/nologin -G nginx -u ${PUID} nginx
186190
else
187191
if [ -z "$SKIP_CHOWN" ]; then
188-
chown -Rf nginx.nginx /var/www/html
192+
chown -Rf nginx.nginx ${WEBROOT}
189193
fi
190194
fi
191195

192196
# Run custom scripts
193197
if [[ "$RUN_SCRIPTS" == "1" ]] ; then
194-
if [ -d "/var/www/html/scripts/" ]; then
198+
199+
if [ -z "$SCRIPTS_FOLDER" ]; then
200+
SCRIPTS_FOLDER=${WEBROOT}/scripts/
201+
fi
202+
203+
if [ -d "${SCRIPTS_FOLDER}" ]; then
195204
# make scripts executable incase they aren't
196-
chmod -Rf 750 /var/www/html/scripts/*; sync;
205+
chmod -Rf 750 ${SCRIPTS_FOLDER}/*; sync;
197206
# run scripts in number order
198-
for i in `ls /var/www/html/scripts/`; do /var/www/html/scripts/$i ; done
207+
for i in `ls ${SCRIPTS_FOLDER}/`; do ${SCRIPTS_FOLDER}/$i ; done
199208
else
200209
echo "Can't find script directory"
201210
fi
202211
fi
203212

204213
if [ -z "$SKIP_COMPOSER" ]; then
205214
# Try auto install for composer
206-
if [ -f "/var/www/html/composer.lock" ]; then
215+
if [ -f "${WEBROOT}/composer.lock" ]; then
207216
if [ "$APPLICATION_ENV" == "development" ]; then
208217
composer global require hirak/prestissimo
209-
composer install --working-dir=/var/www/html
218+
composer install --working-dir=${WEBROOT}
210219
else
211220
composer global require hirak/prestissimo
212-
composer install --no-dev --working-dir=/var/www/html
221+
composer install --no-dev --working-dir=${WEBROOT}
213222
fi
214223
fi
215224
fi

0 commit comments

Comments
 (0)