Utoljára aktív 6 months ago

Revízió 1a1fcdc9b8054be4c02dc52d8ae6d411f2a9af42

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