| 1 | #!/bin/bash |
| 2 | DOCKER_BASE=/srv/docker |
| 3 | |
| 4 | mkdir -p ${DOCKER_BASE}/watchtower/container.conf |
| 5 | |
| 6 | cat > ${DOCKER_BASE}/watchtower/container.conf/docker-compose.yml <<EOF |
| 7 | version: '3.7' |
| 8 | |
| 9 | services: |
| 10 | watchtower: |
| 11 | image: ghcr.io/nicholas-fedor/watchtower |
| 12 | labels: |
| 13 | com.centurylinklabs.watchtower.enable: "true" |
| 14 | restart: on-failure |
| 15 | volumes: |
| 16 | - /var/run/docker.sock:/var/run/docker.sock |
| 17 | - /etc/localtime:/etc/localtime:ro |
| 18 | - /etc/timezone:/etc/timezone:ro |
| 19 | command: --interval 3600 --label-enable |
| 20 | EOF |
| 21 | ln -s container.conf/docker-compose.yml ${DOCKER_BASE}/watchtower/ |
| 22 | |
| 23 | cat > ${DOCKER_BASE}/watchtower/container.conf/production.yml <<EOF |
| 24 | version: '3.7' |
| 25 | EOF |
| 26 | |
| 27 | cat > ${DOCKER_BASE}/watchtower/container.conf/watchtower.service <<EOF |
| 28 | [Unit] |
| 29 | Description=Watchtower Service |
| 30 | After=network.target docker.service |
| 31 | Requires=docker.service |
| 32 | |
| 33 | [Service] |
| 34 | Type=oneshot |
| 35 | RemainAfterExit=yes |
| 36 | |
| 37 | Environment="WORK_DIR=/srv/docker/watchtower/" |
| 38 | WorkingDirectory=/srv/docker/watchtower/ |
| 39 | ExecStartPre=-/usr/local/bin/docker-compose -f "\${WORK_DIR}/docker-compose.yml" -f "\${WORK_DIR}/container.conf/production.yml" down |
| 40 | ExecStartPre=-/usr/local/bin/docker-compose -f "\${WORK_DIR}/docker-compose.yml" -f "\${WORK_DIR}/container.conf/production.yml" pull |
| 41 | ExecStart=/usr/local/bin/docker-compose -f "\${WORK_DIR}/docker-compose.yml" -f "\${WORK_DIR}/container.conf/production.yml" up -d |
| 42 | ExecStop=/usr/local/bin/docker-compose -f "\${WORK_DIR}/docker-compose.yml" -f "\${WORK_DIR}/container.conf/production.yml" down |
| 43 | |
| 44 | [Install] |
| 45 | WantedBy=docker.service |
| 46 | EOF |
| 47 | ln -s ${DOCKER_BASE}/watchtower/container.conf/watchtower.service /etc/systemd/system/ |
| 48 | |
| 49 | systemctl daemon-reload && systemctl enable watchtower && systemctl start watchtower |
| 50 |
waja / gist:98a2b64c5a8145218b9bc84a0c6cd661
Last active 3 months ago
Revision 70787e35ed2943e8575023e931adedf3588498a0
| 1 | #!/bin/bash |
| 2 | DOCKER_BASE=/srv/docker |
| 3 | WATCHTOWER_PATH=${DOCKER_BASE}/watchtower |
| 4 | DC_COMMAND="docker-compose -f docker-compose.yml" |
| 5 | |
| 6 | cd ${WATCHTOWER_PATH} || exit |
| 7 | [ -f container.conf/production.yml ] && DC_COMMAND="${DC_COMMAND} -f container.conf/production.yml" |
| 8 | [ "$(${DC_COMMAND} config | grep "WATCHTOWER_NOTIFICATIONS" | awk '{print $2}')" != "email" ] && exit |
| 9 | cp container.conf/production.yml container.conf/production.yml.old |
| 10 | |
| 11 | SMTP_HOST="$(${DC_COMMAND} config | grep "WATCHTOWER_NOTIFICATION_EMAIL_SERVER:" | awk '{print $2}')" |
| 12 | SMTP_FROM="$(${DC_COMMAND} config | grep "WATCHTOWER_NOTIFICATION_EMAIL_FROM:" | awk '{print $2}')" |
| 13 | SMTP_TO="$(${DC_COMMAND} config | grep "WATCHTOWER_NOTIFICATION_EMAIL_TO:" | awk '{print $2}')" |
| 14 | |
| 15 | [ ! -e ${WATCHTOWER_PATH}/.env ] && ln -s container.conf/.env ${WATCHTOWER_PATH}/.env |
| 16 | touch ${WATCHTOWER_PATH}/container.conf/.env |
| 17 | sed -iE '/^SMTP_/d' ${WATCHTOWER_PATH}/container.conf/.env |
| 18 | cat >> ${WATCHTOWER_PATH}/container.conf/.env <<EOF |
| 19 | SMTP_HOST=${SMTP_HOST} |
| 20 | SMTP_FROM=${SMTP_FROM} |
| 21 | SMTP_TO=${SMTP_TO} |
| 22 | EOF |
| 23 | |
| 24 | sed -i 's/WATCHTOWER_NOTIFICATIONS.*email/WATCHTOWER_NOTIFICATIONS=shoutrrr/' ${WATCHTOWER_PATH}/container.conf/production.yml |
| 25 | sed -i 's#WATCHTOWER_NOTIFICATION_EMAIL_FROM.*"#WATCHTOWER_NOTIFICATION_URL=smtp://:@\${SMTP_HOST}/?auth=None\&encryption=None\&fromaddress=\${SMTP_FROM}\&fromname=Watchtower\&starttls=No\&toaddresses=\${SMTP_TO}\&usehtml=No"#' ${WATCHTOWER_PATH}/container.conf/production.yml |
| 26 | sed -iE '/WATCHTOWER_NOTIFICATION_EMAIL_/d' ${WATCHTOWER_PATH}/container.conf/production.yml |
| 27 |
| 1 | #!/bin/bash |
| 2 | DOCKER_BASE=/srv/docker |
| 3 | |
| 4 | mkdir -p ${DOCKER_BASE}/watchtower/container.conf |
| 5 | |
| 6 | sed -i s/v2tec/containrrr/g ${DOCKER_BASE}/watchtower/container.conf/docker-compose.yml |
| 7 | |
| 8 | systemctl restart watchtower && docker image rm v2tec/watchtower |
| 9 |
| 1 | #!/bin/bash |
| 2 | DOCKER_BASE=/srv/docker |
| 3 | |
| 4 | mkdir -p ${DOCKER_BASE}/watchtower/container.conf |
| 5 | |
| 6 | sed -i "s/image: containrrr\/watchtower/image: ghcr.io\/nicholas-fedor\/watchtower/" ${DOCKER_BASE}/watchtower/container.conf/docker-compose.yml && cd ${DOCKER_BASE}/watchtower && systemctl restart watchtower && docker image rm containrrr/watchtower && docker-compose -f docker-compose.yml -f container.conf/production.yml logs -f |
| 7 |