|
1 | 1 | #!/usr/bin/env bash |
2 | 2 |
|
3 | | -function up() { |
4 | | - printf "xampp env up:\n" |
| 3 | +function main() { |
| 4 | + printf "xampp env:\n" |
5 | 5 | local network=local base=$(dirname $(readlink -f "$0"))/ |
6 | 6 |
|
| 7 | + local i rm run=YES |
| 8 | + for i in "$@" |
| 9 | + do |
| 10 | + case $i in |
| 11 | + --rm) |
| 12 | + run= |
| 13 | + rm=YES |
| 14 | + shift |
| 15 | + ;; |
| 16 | + |
| 17 | + --restart) |
| 18 | + run=YES |
| 19 | + rm=YES |
| 20 | + shift |
| 21 | + ;; |
| 22 | + |
| 23 | + *) |
| 24 | + ;; |
| 25 | + esac |
| 26 | + done |
| 27 | + |
| 28 | + [[ -n "$rm" ]] && { |
| 29 | + printf "removing ...\n" |
| 30 | + |
| 31 | + local images="dns proxy mail pma mysql" |
| 32 | + |
| 33 | + docker stop $images 2>/dev/null |
| 34 | + docker rm $images 2>/dev/null |
| 35 | + docker network rm "$network" 2>/dev/null |
| 36 | + } |
| 37 | + |
| 38 | + [[ -n "$run" ]] || { |
| 39 | + return 0 |
| 40 | + } |
| 41 | + |
7 | 42 | # chrome://flags/#allow-insecure-localhost |
8 | 43 |
|
9 | | - docker network inspect ${network} > /dev/null 2>&1 || docker network create ${network} > /dev/null 2>&1 |
| 44 | + docker network inspect "$network" > /dev/null 2>&1 || docker network create "$network" > /dev/null 2>&1 |
10 | 45 |
|
11 | | - docker start dns 2>/dev/null || docker run -d --hostname dns --name dns --network ${network} \ |
| 46 | + docker start dns 2>/dev/null || docker run -d --hostname dns --name dns --network "$network" \ |
| 47 | + --label "traefik.enable=true" \ |
| 48 | + --label "traefik.http.services.dns.loadbalancer.server.port=5380" \ |
| 49 | + --label "traefik.http.routers.dns.service=dns" \ |
| 50 | + --label "traefik.http.routers.dns.entrypoints=web" \ |
| 51 | + --label "traefik.http.routers.dns.rule=Host(\`dns.localhost\`)" \ |
| 52 | + --label "traefik.http.routers.dns.middlewares=redirect-https@docker" \ |
| 53 | + --label "traefik.http.routers.dns-secure.entrypoints=web-secure" \ |
| 54 | + --label "traefik.http.routers.dns-secure.rule=Host(\`dns.localhost\`)" \ |
| 55 | + --label "traefik.http.routers.dns-secure.tls=true" \ |
| 56 | + --env "MG_REGISTER_CONTAINER_NAMES=1" \ |
| 57 | + --env "MG_DOMAIN=.localhost" \ |
| 58 | + --env "MG_HOST_MACHINE_HOSTNAME=host.localhost" \ |
12 | 59 | --restart unless-stopped \ |
13 | 60 | -v /var/run/docker.sock:/var/run/docker.sock \ |
14 | 61 | -v /etc/resolv.conf:/etc/resolv.conf \ |
15 | 62 | xampp/dns |
16 | | - echo https://dns.localhost |
| 63 | + echo http://dns.localhost |
17 | 64 |
|
18 | | - docker start proxy 2>/dev/null || docker run -d --hostname proxy --name proxy --network ${network} \ |
| 65 | + docker start proxy 2>/dev/null || docker run -d --hostname .localhost --name proxy --network "$network" \ |
| 66 | + --label "traefik.enable=true" \ |
| 67 | + --label "traefik.http.middlewares.redirect-https.redirectscheme.scheme=https" \ |
| 68 | + --label "traefik.http.services.proxy.loadbalancer.server.port=8080" \ |
| 69 | + --label "traefik.http.routers.proxy.service=proxy" \ |
| 70 | + --label "traefik.http.routers.proxy.entrypoints=web" \ |
| 71 | + --label "traefik.http.routers.proxy.rule=Host(\`proxy.localhost\`)" \ |
| 72 | + --label "traefik.http.routers.proxy.middlewares=redirect-https@docker" \ |
| 73 | + --label "traefik.http.routers.proxy-secure.entrypoints=web-secure" \ |
| 74 | + --label "traefik.http.routers.proxy-secure.rule=Host(\`proxy.localhost\`)" \ |
| 75 | + --label "traefik.http.routers.proxy-secure.tls=true" \ |
19 | 76 | --restart unless-stopped \ |
20 | 77 | -v /var/run/docker.sock:/var/run/docker.sock \ |
21 | | - -p 80:80 -p 443:443 \ |
22 | | - xampp/proxy |
23 | | - echo https://proxy.localhost |
| 78 | + --expose 3000 \ |
| 79 | + -p 80:80 -p 443:443 -p 3000:3000 \ |
| 80 | + xampp/proxy \ |
| 81 | + --api=true \ |
| 82 | + --api.insecure=true \ |
| 83 | + --log.level=info \ |
| 84 | + --entrypoints.web-3000.address=:3000 \ |
| 85 | + --entrypoints.web.address=:80 \ |
| 86 | + --entrypoints.web-secure.address=:443 \ |
| 87 | + --providers.docker=true \ |
| 88 | + --providers.docker.network=local \ |
| 89 | + --providers.docker.exposedByDefault=false |
| 90 | + echo http://proxy.localhost |
24 | 91 |
|
25 | | - docker start mail 2>/dev/null || docker run -d --hostname mail --name mail --network ${network} \ |
| 92 | + docker start mail 2>/dev/null || docker run -d --hostname mail --name mail --network "$network" \ |
| 93 | + --label "traefik.enable=true" \ |
| 94 | + --label "traefik.http.services.mail.loadbalancer.server.port=8025" \ |
| 95 | + --label "traefik.http.routers.mail.service=mail" \ |
| 96 | + --label "traefik.http.routers.mail.entrypoints=web" \ |
| 97 | + --label "traefik.http.routers.mail.rule=Host(\`mail.localhost\`)" \ |
| 98 | + --label "traefik.http.routers.mail.middlewares=redirect-https@docker" \ |
| 99 | + --label "traefik.http.routers.mail-secure.entrypoints=web-secure" \ |
| 100 | + --label "traefik.http.routers.mail-secure.rule=Host(\`mail.localhost\`)" \ |
| 101 | + --label "traefik.http.routers.mail-secure.tls=true" \ |
26 | 102 | --restart unless-stopped \ |
27 | 103 | xampp/mail |
28 | | - echo https://mail.localhost |
| 104 | + echo http://mail.localhost |
29 | 105 |
|
30 | | - docker start pma 2>/dev/null || docker run -d --hostname pma --name pma --network ${network} \ |
| 106 | + docker start pma 2>/dev/null || docker run -d --hostname pma --name pma --network "$network" \ |
| 107 | + --label "traefik.enable=true" \ |
| 108 | + --label "traefik.http.routers.pma.entrypoints=web" \ |
| 109 | + --label "traefik.http.routers.pma.rule=Host(\`pma.localhost\`)" \ |
| 110 | + --label "traefik.http.routers.pma.middlewares=redirect-https@docker" \ |
| 111 | + --label "traefik.http.routers.pma-secure.entrypoints=web-secure" \ |
| 112 | + --label "traefik.http.routers.pma-secure.rule=Host(\`pma.localhost\`)" \ |
| 113 | + --label "traefik.http.routers.pma-secure.tls=true" \ |
| 114 | + --env "PMA_ARBITRARY=1" \ |
31 | 115 | --restart unless-stopped \ |
32 | 116 | xampp/pma |
33 | | - echo https://pma.localhost |
34 | | - |
35 | | - docker start mysql 2>/dev/null || . ${base}/xampp-mysql "mysql" |
36 | | -} |
37 | | - |
38 | | -function down() { |
39 | | - printf "xampp env down:\n" |
40 | | - |
41 | | - local images="dns proxy mail pma mysql" |
42 | | - local network=local |
| 117 | + echo http://pma.localhost |
43 | 118 |
|
44 | | - docker stop ${images} 2>/dev/null |
45 | | - docker rm ${images} 2>/dev/null |
46 | | - docker network rm ${network} 2>/dev/null |
| 119 | + docker start mysql 2>/dev/null || . "$base/xampp-mysql" mysql |
47 | 120 | } |
48 | 121 |
|
49 | | -if [[ ${1} == 'down' ]]; then |
50 | | - down |
51 | | -else |
52 | | - up |
53 | | -fi; |
| 122 | +main "$@" |
0 commit comments