From a2b26a978bf0682b1f86df6ba7bd264c5232bb3e Mon Sep 17 00:00:00 2001 From: Kris Lamoureux Date: Fri, 18 Nov 2022 04:11:08 -0500 Subject: [PATCH] testing --- dev/vars/webserver.yml | 2 +- roles/webserver/files/docker-compose.yml | 26 +++++++++++++++++++- update-hosts.sh | 31 ++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100755 update-hosts.sh diff --git a/dev/vars/webserver.yml b/dev/vars/webserver.yml index 67b1fc7..1b0490d 100644 --- a/dev/vars/webserver.yml +++ b/dev/vars/webserver.yml @@ -2,4 +2,4 @@ docker_users: - vagrant webserver_env: - TRAEFIK_DOMAIN: traefik.example.org + TRAEFIK_DOMAIN: traefik.local.freeitathens.org diff --git a/roles/webserver/files/docker-compose.yml b/roles/webserver/files/docker-compose.yml index d927b20..899a2c2 100644 --- a/roles/webserver/files/docker-compose.yml +++ b/roles/webserver/files/docker-compose.yml @@ -1,5 +1,8 @@ version: '3.5' +volumes: + wordpress: + networks: traefik: name: traefik @@ -7,10 +10,12 @@ networks: services: traefik: image: traefik:${TRAEFIK_VERSION:-latest} + restart: always command: - --api.dashboard=${TRAEFIK_DASHBOARD:-true} - - --api.debug=${TRAEFIK_DEBUG:-false} + - --api.debug=${TRAEFIK_DEBUG:-true} - --providers.docker=true + - --providers.docker.exposedbydefault=${TRAEFIK_EXPOSED_DEFAULT:-false} - --entrypoints.web.address=:80 - --entrypoints.web.http.redirections.entrypoint.to=websecure - --entrypoints.web.http.redirections.entrypoint.scheme=https @@ -28,5 +33,24 @@ services: traefik.http.routers.api.entrypoints: local traefik.http.routers.api.service: api@internal traefik.http.routers.api.tls: true + traefik.enable: true networks: - traefik + + wordpress: + image: wordpress:${WORDPRESS_VERSION:-latest} + restart: always + environment: + WORDPRESS_DB_HOST: asdf + WORDPRESS_DB_USER: asdf + WORDPRESS_DB_PASSWORD: ASDFASDF + WORDPRESS_DB_NAME: ASDFA + labels: + traefik.http.routers.wordpress.rule: Host(`${WORDPRESS_DOMAIN:-www.local.freeitathens.org}`) + traefik.http.routers.wordpress.entrypoints: websecure + traefik.http.routers.wordpress.tls.certresolver: letsencrypt + traefik.docker.network: traefik + traefik.enable: true + + volumes: + - wordpress:/var/www/html diff --git a/update-hosts.sh b/update-hosts.sh new file mode 100755 index 0000000..1bc33ba --- /dev/null +++ b/update-hosts.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +COMMENT="FRITA-infra" +DOMAIN="local.freeitathens.org" +HOST[0]="traefik.${DOMAIN}" +HOST[1]="www.${DOMAIN}" + +# Get Vagrantbox guest IP +VAGRANT_OUTPUT=$(vagrant ssh -c "hostname -I | cut -d' ' -f1" 2>/dev/null) + +# Remove ^M from the end +[ ${#VAGRANT_OUTPUT} -gt 1 ] && IP=${VAGRANT_OUTPUT::-1} + +echo "Purging project addresses from /etc/hosts" +sudo sed -i "s/# $COMMENT//g" /etc/hosts +for address in "${HOST[@]}"; do + sudo sed -i "/$address/d" /etc/hosts +done + +# Remove trailing newline +sudo sed -i '${/^$/d}' /etc/hosts + +if [ -n "$IP" ]; then + echo -e "Adding new addresses...\n" + echo -e "# $COMMENT" | sudo tee -a /etc/hosts + for address in "${HOST[@]}"; do + echo -e "$IP\t$address" | sudo tee -a /etc/hosts + done +else + echo "Cannot find address. Is the Vagrant box running?" +fi