-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy
executable file
·45 lines (35 loc) · 1.3 KB
/
deploy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env bash
# This script builds + deploys the website on my DigitalOcean VPS
# It assumes you've got SSH access, and a private key in ~/.ssh/do_dmoffat.com
echo "Deploying website..."
source .env
# Build and publish the nginx container
./build-publish-nginx
if [[ "$?" != "0" ]]; then
echo "Failed to build + publish the nginx container."
exit 1
fi
# Deploy it remotely
ssh -i ~/.ssh/do_dmoffat.com dmoffat.com -p 9999 /bin/bash << EOF
echo "Authenticating with the registry"
docker login -u danmofo@gmail.com -p $DIGITALOCEAN_API_KEY registry.digitalocean.com
if [[ "$?" != "0" ]]; then
echo "Failed to authenticate with container registry"
exit 1
fi
echo "Pulling the container..."
docker pull registry.digitalocean.com/dmoffat/dmoffat-nginx:latest
if [[ "$?" != "0" ]]; then
echo "Failed to pull container from container registry"
exit 1
fi
echo "Killing existing container..."
docker container kill dmoffat-nginx
docker container rm dmoffat-nginx
echo "Running new container..."
docker run -d -p 80:8080 -p 443:8443 --name dmoffat-nginx registry.digitalocean.com/dmoffat/dmoffat-nginx
if [[ "$?" != "0" ]]; then
echo "Failed to start new container - website is currently down."
exit 1
fi
EOF