From 052e011b2841e06561d14cbe8f18e644fd7e434e Mon Sep 17 00:00:00 2001 From: Vishal Dodiya Date: Wed, 24 Jan 2018 14:28:17 +0530 Subject: [PATCH 1/5] update yml file --- docker-compose.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose.yml b/docker-compose.yml index 781e15a..cfe96a7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -46,6 +46,7 @@ services: restart: always environment: - VIRTUAL_HOST + - LETSENCRYPT_HOST=${VIRTUAL_HOST} volumes: - "./app/src:/var/www/html" - "./config/nginx/default.conf:/etc/nginx/conf.d/default.conf" From b0d2fcbaed4fa7a17af75fb8d410456d71b146bd Mon Sep 17 00:00:00 2001 From: Vishal Dodiya Date: Wed, 24 Jan 2018 14:59:40 +0530 Subject: [PATCH 2/5] add letsencrypt support in script --- scripts/ee4 | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/scripts/ee4 b/scripts/ee4 index a5bff85..097de6b 100755 --- a/scripts/ee4 +++ b/scripts/ee4 @@ -60,6 +60,7 @@ singleWordPress() { ### echo "Configuring network..." && sleep 1 runNginxProxy + runLetsEncrypt docker network create $SITE_NAME docker network connect $SITE_NAME nginx-proxy @@ -175,11 +176,23 @@ runNginxProxy() { -v /etc/nginx/certs:/etc/nginx/certs \ -v /etc/nginx/conf.d:/etc/nginx/conf.d \ -v /var/run/docker.sock:/tmp/docker.sock:ro \ + --network $SITE_NAME \ jwilder/nginx-proxy fi fi } +# run JrCs/docker-letsencrypt-nginx-proxy-companion container +runLetsEncrypt() { + if isNginxProxyRunning; then + docker run -d --name letsencrypt \ + -v /var/run/docker.sock:/var/run/docker.sock:ro \ + --volume-from nginx-proxy \ + --network $SITE_NAME \ + jrcs/letsencrypt-nginx-proxy-companion + fi +} + # fail_trap is executed if an error occurs. fail_trap() { result=$? From 7efa7db5ecc19afb6191e2908d813a2910e81c3a Mon Sep 17 00:00:00 2001 From: Vishal Dodiya Date: Thu, 25 Jan 2018 23:59:11 +0530 Subject: [PATCH 3/5] update ee4 script to support letsencrypt --- scripts/ee4 | 70 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 16 deletions(-) diff --git a/scripts/ee4 b/scripts/ee4 index 097de6b..54dfdb4 100755 --- a/scripts/ee4 +++ b/scripts/ee4 @@ -59,8 +59,7 @@ singleWordPress() { # Setup site networking ### echo "Configuring network..." && sleep 1 - runNginxProxy - runLetsEncrypt + runNginxProxyAndLetsEncrypt docker network create $SITE_NAME docker network connect $SITE_NAME nginx-proxy @@ -78,6 +77,43 @@ singleWordPress() { fi } +singleWordPressLetsEncrypt() { + echo "Installing WordPress site $SITE_NAME" + mkdir -p "$WEBROOT" > /dev/null 2>&1 + + ### + # Setup site configuration + ### + echo "Configuring project..." && sleep 1 + mkdir -p "$WEBROOT/$SITE_NAME" > /dev/null 2>&1 + cp "$EE_INSTALL_DIR/docker-compose.yml" "$WEBROOT/$SITE_NAME" + cp -r "$EE_INSTALL_DIR/config" "$WEBROOT/$SITE_NAME" + mv "$WEBROOT/$SITE_NAME/config/.env.example" "$WEBROOT/$SITE_NAME/.env" + sed -i.bak "s/\(VIRTUAL_HOST=\)\(site1.test\)/\1$SITE_NAME/" "$WEBROOT/$SITE_NAME/.env" + + ### + # Setup site networking + ### + echo "Configuring network..." && sleep 1 + runNginxProxyAndLetsEncrypt + docker network create $SITE_NAME + docker network connect $SITE_NAME nginx-proxy + docker network connect $SITE_NAME letsencrypt + + ### + # Start the containers + ### + pushd "$WEBROOT/$SITE_NAME" > /dev/null 2>&1 + docker-compose up -d + popd > /dev/null 2>&1 + + echo "$SITE_NAME created." + read -p "Would you like to add domain to /etc/host?(y/N) " -n 1 -r + if [[ $REPLY =~ ^[Yy]$ ]]; then + addHost "$SITE_NAME" + fi +} + multisiteSubdirectory() { echo "Installing WordPress Multisite with Subdirectory" } @@ -165,8 +201,8 @@ isNginxProxyRunning() { fi } -# run jwilder/nginx-proxy container -runNginxProxy() { +# run jwilder/nginx-proxy and JrCs/docker-letsencrypt-nginx-proxy-companion container +runNginxProxyAndLetsEncrypt() { if ! isNginxProxyRunning; then if ! portsFree; then echo "Please make sure ports 80 and 443 are free." @@ -176,20 +212,13 @@ runNginxProxy() { -v /etc/nginx/certs:/etc/nginx/certs \ -v /etc/nginx/conf.d:/etc/nginx/conf.d \ -v /var/run/docker.sock:/tmp/docker.sock:ro \ - --network $SITE_NAME \ jwilder/nginx-proxy - fi - fi -} -# run JrCs/docker-letsencrypt-nginx-proxy-companion container -runLetsEncrypt() { - if isNginxProxyRunning; then - docker run -d --name letsencrypt \ - -v /var/run/docker.sock:/var/run/docker.sock:ro \ - --volume-from nginx-proxy \ - --network $SITE_NAME \ - jrcs/letsencrypt-nginx-proxy-companion + docker run -d --name letsencrypt \ + -v /var/run/docker.sock:/var/run/docker.sock:ro \ + --volume-from nginx-proxy \ + jrcs/letsencrypt-nginx-proxy-companion + fi fi } @@ -235,6 +264,15 @@ while [[ $# -gt 0 ]]; do if [[ $# -ne 0 ]]; then case $1 in '--wp') + shift + if [[ $# -ne 0 ]]; then + case $1 in + '--le') + singleWordPressLetsEncrypt + exit 0 + ;; + esac + fi singleWordPress exit 0 ;; From 733ae50514b519be1574ae948b9db8748d502dc4 Mon Sep 17 00:00:00 2001 From: vishaldodiya Date: Sat, 27 Jan 2018 14:35:37 +0000 Subject: [PATCH 4/5] update nginx-proxy mounted volume --- scripts/ee4 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/ee4 b/scripts/ee4 index 54dfdb4..4411666 100755 --- a/scripts/ee4 +++ b/scripts/ee4 @@ -210,13 +210,15 @@ runNginxProxyAndLetsEncrypt() { docker run --name nginx-proxy --restart always -d -p 80:80 -p 443:443 \ -v /etc/nginx/htpasswd:/etc/nginx/htpasswd \ -v /etc/nginx/certs:/etc/nginx/certs \ + -v /etc/nginx/vhost.d \ + -v /usr/share/nginx/html \ -v /etc/nginx/conf.d:/etc/nginx/conf.d \ -v /var/run/docker.sock:/tmp/docker.sock:ro \ jwilder/nginx-proxy docker run -d --name letsencrypt \ -v /var/run/docker.sock:/var/run/docker.sock:ro \ - --volume-from nginx-proxy \ + --volumes-from nginx-proxy \ jrcs/letsencrypt-nginx-proxy-companion fi fi From 826b5bd45e49890d505476394f53f7af40c1d8fb Mon Sep 17 00:00:00 2001 From: Vishal Dodiya Date: Mon, 29 Jan 2018 20:09:35 +0530 Subject: [PATCH 5/5] Answer PR feedback --- config/.env.example | 1 + docker-compose.yml | 2 ++ scripts/ee4 | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/config/.env.example b/config/.env.example index e044e97..80b86e1 100644 --- a/config/.env.example +++ b/config/.env.example @@ -5,3 +5,4 @@ MYSQL_PASSWORD=password WORDPRESS_DB_HOST=db VIRTUAL_HOST=site1.test +VIRTUAL_HOST_EMAIL=example@site1.test diff --git a/docker-compose.yml b/docker-compose.yml index cfe96a7..63d9a13 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,6 +8,7 @@ services: environment: - VIRTUAL_HOST=mail.${VIRTUAL_HOST} - VIRTUAL_PORT=8025 + - LETSENCRYPT_HOST=mail.${VIRTUAL_HOST} networks: - site-network @@ -47,6 +48,7 @@ services: environment: - VIRTUAL_HOST - LETSENCRYPT_HOST=${VIRTUAL_HOST} + - LETSENCRYPT_EMAIL=${VIRTUAL_HOST_EMAIL} volumes: - "./app/src:/var/www/html" - "./config/nginx/default.conf:/etc/nginx/conf.d/default.conf" diff --git a/scripts/ee4 b/scripts/ee4 index 4411666..90bb457 100755 --- a/scripts/ee4 +++ b/scripts/ee4 @@ -131,6 +131,9 @@ deleteSingleWordPress() { sudo rm -rf "$WEBROOT/$SITE_NAME" docker network disconnect "$SITE_NAME" nginx-proxy + if isContainerConnected letsencrypt; then + docker network disconnect "$SITE_NAME" letsencrypt + fi docker network rm "$SITE_NAME" fi } @@ -201,6 +204,21 @@ isNginxProxyRunning() { fi } +# check if Container is connected to network +isContainerConnected() { + docker inspect -f '{{range $p, $conf := .NetworkSettings.Networks}} + {{if ne $p "bridge"}} + {{$p}} + {{end}} + {{end}}' $1 | grep $SITE_NAME > /dev/null 2>&1 + + if [[ $? == 0 ]]; then + return 0 + else + return 1 + fi +} + # run jwilder/nginx-proxy and JrCs/docker-letsencrypt-nginx-proxy-companion container runNginxProxyAndLetsEncrypt() { if ! isNginxProxyRunning; then