-
Notifications
You must be signed in to change notification settings - Fork 5
/
deploy.sh
33 lines (23 loc) · 922 Bytes
/
deploy.sh
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
#!/bin/bash
version="${ENV:-latest}"
echo "Version: $version"
imageName=${INAME}
containerName=${CNAME:-$imageName}
dockerfile=${DOCKERFILE:-"Dockerfile"}
hostUser=${HOST_USER}
hostName=${HOST_NAME}
host="$hostUser@$hostName"
imageTag="$imageName:$version"
echo "Image tag: $imageTag"
echo "Building image..."
buildResult=$(docker build --pull -q -f "$dockerfile" -t "$imageTag" ".")
echo "Build result: $buildResult"
echo "Uploading to cloud..."
uploadToCloud=$(docker save $imageTag | ssh -C $host -- "docker load")
echo "Upload result: $uploadToCloud"
stopAndRemove=$(ssh -C $host -- "docker stop $containerName && docker rm $containerName")
echo "Stop and remove: $stopAndRemove"
runContainer=$(ssh -C $host -- "docker run --name $containerName --restart always --network nginx -d $imageTag")
echo "Run: $runContainer"
pruneImages=$(ssh -C $host -- "docker image prune -f")
echo "Prune Images: $pruneImages"