Остання активність 6 months ago

Версія c647a6f9c05f187695cf48bbccef1437e4dc4f7a

deploy_traefik.sh Неформатований
1#!/bin/bash
2DOCKER_BASE=/srv/docker
3
4mkdir -p ${DOCKER_BASE}/traefik/container.conf
5
6cat > ${DOCKER_BASE}/traefik/container.conf/docker-compose.yml <<EOF
7version: '3.7'
8
9services:
10 traefik:
11 image: traefik:1.7-alpine
12 networks:
13 - system_traefik
14 environment:
15 - LC_ALL=C.UTF-8
16 - TZ=Europe/Berlin
17 labels:
18 - traefik.enable=true
19 - traefik.backend=traefik
20 - traefik.port=8080
21 ports:
22 - "80:80"
23 - "443:443"
24 - "8080:8080"
25 restart: always
26 volumes:
27 - "./config/:/etc/traefik/"
28 - "/var/run/docker.sock:/var/run/docker.sock:ro"
29
30networks:
31 system_traefik:
32 external: true
33EOF
34ln -s container.conf/docker-compose.yml ${DOCKER_BASE}/traefik/
35
36cat > ${DOCKER_BASE}/traefik/container.conf/production.yml <<EOF
37version: '3.7'
38
39services:
40
41 traefik:
42 labels:
43 - traefik.frontend.rule=Host:traefik.test.org
44 - com.centurylinklabs.watchtower.enable=true
45EOF
46
47cat > ${DOCKER_BASE}/traefik/container.conf/traefik.service <<EOF
48[Unit]
49Description=Traefik Proxy Service
50After=network.target docker.service
51Requires=docker.service
52
53[Service]
54Type=oneshot
55RemainAfterExit=yes
56
57Environment="WORK_DIR=/srv/docker/traefik/"
58WorkingDirectory=/srv/docker/traefik/
59ExecStartPre=/usr/bin/bash -c "/usr/bin/docker network inspect system_traefik &>/dev/null || /usr/bin/docker network create --driver bridge system_traefik"
60ExecStartPre=-/usr/local/bin/docker-compose -f "\${WORK_DIR}/docker-compose.yml" -f "\${WORK_DIR}/container.conf/production.yml" down
61ExecStart=/usr/local/bin/docker-compose -f "\${WORK_DIR}/docker-compose.yml" -f "\${WORK_DIR}/container.conf/production.yml" up -d
62ExecStop=/usr/local/bin/docker-compose -f "\${WORK_DIR}/docker-compose.yml" -f "\${WORK_DIR}/container.conf/production.yml" down
63
64[Install]
65WantedBy=docker.service
66EOF
67ln -s ${DOCKER_BASE}/traefik/container.conf/traefik.service /etc/systemd/system/
68
69mkdir -p ${DOCKER_BASE}/traefik/config
70
71cat > ${DOCKER_BASE}/traefik/config/traefik.toml <<EOF
72logLevel = "DEBUG"
73defaultEntryPoints = ["http", "https"]
74
75# WEB interface of Traefik - it will show web page with overview of frontend and backend configurations
76[web]
77address = ":8080"
78 [web.auth.basic]
79 users = ["admin:$apr1$AAbCdQpX$ajolS9mMfKRG.lqcY/uXU/"]
80
81# Connection to docker host system (docker.sock)
82[docker]
83domain = "test.org"
84watch = true
85# This will hide all docker containers that don't have explicitly
86# set label to "enable"
87exposedbydefault = false
88
89# Force HTTPS
90[entryPoints]
91 [entryPoints.http]
92 address = ":80"
93 [entryPoints.http.redirect]
94 entryPoint = "https"
95 [entryPoints.https]
96 address = ":443"
97 [entryPoints.https.tls]
98
99# Let's encrypt configuration
100[acme]
101 email="ssladmin@test.org"
102 storage="/etc/traefik/acme.json"
103 entryPoint="https"
104 acmeLogging=true
105 onDemand=false
106 OnHostRule=true
107
108[acme.httpChallenge]
109 entryPoint = "http"
110EOF
111
112systemctl daemon-reload && systemctl enable traefik && systemctl start traefik
113