Update deployment to single node swarm

This commit is contained in:
schmelczerandras 2020-07-11 22:16:41 +02:00
parent 3502dcfcb0
commit 58e688b83e
7 changed files with 97 additions and 51 deletions

View file

@ -1,24 +1,76 @@
version: '3' version: '3.8'
services: services:
ingress: ingress:
init: true
image: nginx:alpine image: nginx:alpine
restart: unless-stopped depends_on:
- certbot
- frontend
deploy:
replicas: 2
resources:
limits:
cpus: '0.10'
memory: 32M
reservations:
cpus: '0.10'
memory: 32M
update_config:
parallelism: 1
failure_action: rollback
delay: 10s
monitor: 10s
restart_policy:
condition: on-failure
window: 30s
ports: ports:
- "80:80" - "80:80"
- "443:443" - "443:443"
command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'" command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
volumes: volumes:
- ./data/nginx:/etc/nginx/conf.d
- ./data/certbot/conf:/etc/letsencrypt - ./data/certbot/conf:/etc/letsencrypt
- ./data/certbot/www:/var/www/certbot - ./data/certbot/www:/var/www/certbot
frontend:
image: declared-frontend
restart: unless-stopped
certbot: certbot:
init: true
image: certbot/certbot image: certbot/certbot
restart: unless-stopped deploy:
replicas: 1
resources:
limits:
cpus: '0.05'
memory: 16M
reservations:
cpus: '0.05'
memory: 16M
restart_policy:
condition: on-failure
window: 30s
entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'" entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
volumes: volumes:
- ./data/certbot/conf:/etc/letsencrypt - ./data/certbot/conf:/etc/letsencrypt
- ./data/certbot/www:/var/www/certbot - ./data/certbot/www:/var/www/certbot
frontend:
init: true
image: schmelczera/declared-frontend
ports:
- "80"
deploy:
replicas: 2
resources:
limits:
cpus: '0.15'
memory: 128M
reservations:
cpus: '0.15'
memory: 128M
update_config:
parallelism: 1
failure_action: rollback
delay: 10s
monitor: 10s
restart_policy:
condition: on-failure
window: 30s

View file

@ -1,25 +0,0 @@
# How to configure ingress from digital ocean docker one-click app
## iptables (remote)
```sh
iptables -L ufw-user-input
iptables -D ufw-user-input 4
iptables -D ufw-user-input 4
iptables -I ufw-user-input -p tcp --dport 80 -j ACCEPT
iptables -I ufw-user-input -p tcp --dport 443 -j ACCEPT
```
> Disable Docker ports and enable HTTP(S) ports
## Other (remote)
```sh
apt update && apt upgrade -y
rm -rf /etc/update-motd.d/99-one-click
```
## Copy (local)
```sh
scp -r infrastructure root@164.90.220.12:/root/infra
```

View file

@ -2,26 +2,10 @@
# Source https://medium.com/@pentacent/nginx-and-lets-encrypt-with-docker-in-less-than-5-minutes-b4b8a60d3a71 # Source https://medium.com/@pentacent/nginx-and-lets-encrypt-with-docker-in-less-than-5-minutes-b4b8a60d3a71
DOCKER_HOST=ssh://root@decla.red
if ! [ -x "$(command -v docker-compose)" ]; then
echo 'Error: docker-compose is not installed.' >&2
exit 1
fi
domains=(decla.red) domains=(decla.red)
rsa_key_size=4096 rsa_key_size=4096
data_path="./data/certbot" data_path="./data/certbot"
email="schmelczerandras@gmail.com" # Adding a valid address is strongly recommended email="schmelczerandras@gmail.com" # Adding a valid address is strongly recommended
staging=0 # Set to 1 if you're testing your setup to avoid hitting request limits
if [ -d "$data_path" ]; then
read -p "Existing data found for $domains. Continue and replace existing certificate? (y/N) " decision
if [ "$decision" != "Y" ] && [ "$decision" != "y" ]; then
exit
fi
fi
if [ ! -e "$data_path/conf/options-ssl-nginx.conf" ] || [ ! -e "$data_path/conf/ssl-dhparams.pem" ]; then if [ ! -e "$data_path/conf/options-ssl-nginx.conf" ] || [ ! -e "$data_path/conf/ssl-dhparams.pem" ]; then
echo "### Downloading recommended TLS parameters ..." echo "### Downloading recommended TLS parameters ..."
@ -68,9 +52,6 @@ case "$email" in
*) email_arg="--email $email" ;; *) email_arg="--email $email" ;;
esac esac
# Enable staging mode if needed
if [ $staging != "0" ]; then staging_arg="--staging"; fi
docker-compose run --rm --entrypoint "\ docker-compose run --rm --entrypoint "\
certbot certonly --webroot -w /var/www/certbot \ certbot certonly --webroot -w /var/www/certbot \
$staging_arg \ $staging_arg \

View file

@ -0,0 +1,6 @@
#!/bin/bash
REMOTE_ADDRESS=$1
echo Initializing new machine, $REMOTE_ADDRESS
cat init-remote.sh | ssh $REMOTE_ADDRESS

29
infrastructure/init.sh Normal file
View file

@ -0,0 +1,29 @@
#!/bin/bash
echo Configuring iptables
echo Start state
iptables -L ufw-user-input
iptables -D ufw-user-input 4
iptables -D ufw-user-input 4
iptables -I ufw-user-input -p tcp --dport 22 -j ACCEPT
iptables -I ufw-user-input -p tcp --dport 80 -j ACCEPT
iptables -I ufw-user-input -p tcp --dport 443 -j ACCEPT
echo End state
iptables -L ufw-user-input
echo Updating system
apt update &&\
apt upgrade -y &&\
apt install zsh &&\
sh -c "$(CHSH=yes curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
echo Removing banner
rm -rf /etc/update-motd.d/99-one-click
docker swarm init --advertise-addr eth0
./init-letsencrypt.sh
docker-compose down

3
ingress/Dockerfile Normal file
View file

@ -0,0 +1,3 @@
FROM nginx:alpine
COPY app.conf /etc/nginx/conf.d/