|
2 | 2 | set -o errexit -o errtrace -o noclobber -o nounset -o pipefail |
3 | 3 | IFS=$'\n\t' |
4 | 4 |
|
5 | | -script_dir=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd) |
| 5 | +function find_script_dir { |
| 6 | + local script=${BASH_SOURCE[0]} |
| 7 | + local script_dir=$(cd $(dirname "${script}") && pwd) |
| 8 | + if [ -L $script ]; then |
| 9 | + # Symlink detected. |
| 10 | + script_dir=$(dirname $(readlink $script)); |
| 11 | + fi |
| 12 | + |
| 13 | + echo $script_dir |
| 14 | +} |
| 15 | + |
| 16 | +script_dir=$(find_script_dir) |
6 | 17 | script_path=$script_dir/$(basename "${BASH_SOURCE[0]}") |
7 | 18 |
|
8 | 19 | bold=$(tput bold) |
@@ -47,6 +58,18 @@ Commands: |
47 | 58 | sql:port |
48 | 59 | Display the exposed MariaDB SQL server port. |
49 | 60 |
|
| 61 | + traefik:start |
| 62 | + Start træfik reverse proxy. |
| 63 | +
|
| 64 | + traefik:stop |
| 65 | + Stop træfik reverse proxy |
| 66 | +
|
| 67 | + traefik:url |
| 68 | + URL for the administrative UI for træfik. |
| 69 | +
|
| 70 | + traefik:open |
| 71 | + Open the administrative UI for træfik. |
| 72 | +
|
50 | 73 | mailhog:url |
51 | 74 | URL for the mailhog web-interface. |
52 | 75 |
|
@@ -85,9 +108,6 @@ Configuration: |
85 | 108 | COMPOSE_DOMAIN |
86 | 109 | The domain to use when generating urls |
87 | 110 |
|
88 | | - COMPOSE_URL |
89 | | - The url to use when generating urls |
90 | | -
|
91 | 111 | REMOTE_HOST |
92 | 112 | Host used when pulling data from remove site |
93 | 113 |
|
@@ -152,19 +172,24 @@ if [ "$#" == "0" ]; then |
152 | 172 | exit 1 |
153 | 173 | fi |
154 | 174 |
|
| 175 | +# Check if traefik is running and print warning if not |
| 176 | +if [ ! "$(docker inspect -f '{{.State.Running}}' traefik 2>/dev/null)" == "true" ]; then |
| 177 | + (>&2 echo "${bold}Traefik reverse proxy has not been started. Hostname will not be resolved to containers and not all commands will work correctly.${normal}") |
| 178 | +fi |
| 179 | + |
155 | 180 | # Helper function to call `docker-compose` in the right context |
156 | 181 | docker_compose () { |
157 | 182 | # Note: Apparently, using --project-directory or --file options for `docker-compose` will break use of `$PWD` in |
158 | 183 | # docker-compose.yml. Therefore, we `cd` before running `docker-compose` command. |
159 | | - (cd "$docker_compose_dir" && docker-compose "$@") |
| 184 | + (cd "$docker_compose_dir" && COMPOSE_DOMAIN=${COMPOSE_DOMAIN} docker-compose "$@") |
160 | 185 | } |
161 | 186 |
|
162 | 187 | cmd="$1" |
163 | 188 | shift |
164 | 189 |
|
165 | 190 | case "$cmd" in |
166 | 191 | url) |
167 | | - echo ${COMPOSE_URL:-http://${COMPOSE_DOMAIN}:$(docker_compose port reverse-proxy 80 | cut -d: -f2)} |
| 192 | + echo http://${COMPOSE_DOMAIN} |
168 | 193 | ;; |
169 | 194 |
|
170 | 195 | open) |
|
238 | 263 | docker_compose port mariadb 3306 | cut -d: -f2 |
239 | 264 | ;; |
240 | 265 |
|
| 266 | + traefik:start) |
| 267 | + docker network inspect frontend >/dev/null 2>&1 || docker network create --driver=bridge --attachable --internal=false frontend |
| 268 | + $(cd ${script_dir}/../traefik/; docker-compose up -d) |
| 269 | + ;; |
| 270 | + |
| 271 | + traefik:stop) |
| 272 | + $(cd ${script_dir}/../traefik/; docker-compose down --volumes) |
| 273 | + ;; |
| 274 | + |
| 275 | + traefik:open) |
| 276 | + open $($script_path traefik:url) |
| 277 | + ;; |
| 278 | + |
| 279 | + traefik:url) |
| 280 | + label=$(docker inspect --format '{{ index .Config.Labels "traefik.http.routers.traefik.rule"}}' traefik) |
| 281 | + url=$(echo "${label}" | sed -n 's/.*\`\(.*\)\`.*/\1/p') |
| 282 | + echo http://${url}:8080; |
| 283 | + ;; |
| 284 | + |
241 | 285 | mailhog:url) |
242 | 286 | url=http://${COMPOSE_DOMAIN}:$(docker_compose port mailhog 8025 | cut -d: -f2) |
243 | | - echo $url;; |
| 287 | + echo $url |
| 288 | + ;; |
244 | 289 |
|
245 | 290 | mailhog:open) |
246 | 291 | open $(itkdev-docker-compose mailhog:url) |
|
0 commit comments