scripts fixes: better error handling and shellcheck compliance

This commit is contained in:
Herve Nicol 2018-03-21 22:20:32 +01:00
parent 2f9ecd0f01
commit de729abf41
3 changed files with 27 additions and 9 deletions

View file

@ -1,20 +1,27 @@
#!/bin/sh
echo_exit() {
echo "$*"
exit 1
}
# Copy resources needed in the image build phase
cp ../template/index.mustache ../data/*.* ../www/
# Build image
cd ../www
docker image build -t lucj/sophia.events .
cd ../www || echo_exit "Could not switch to www dir"
docker image build -t lucj/sophia.events . || echo_exit "Could not use docker"
# Run website
ID=$(docker run -d -p 80 lucj/sophia.events)
ID="$(docker run -d -p 80 lucj/sophia.events)"
# Copy generated index.html and past.html locally
docker cp $ID:/usr/share/nginx/html/index.html .
docker cp $ID:/usr/share/nginx/html/past.html .
docker cp "$ID":/usr/share/nginx/html/index.html . || echo_exit "docker cp failed"
docker cp "$ID":/usr/share/nginx/html/past.html . || echo_exit "docker cp failed"
# Remove files used for image build
rm index.mustache events.json clean_events.js package.json
# Get port
PORT=$(docker inspect --format '{{ (index (index .NetworkSettings.Ports "80/tcp") 0).HostPort }}' $ID)
PORT="$(docker inspect --format '{{ (index (index .NetworkSettings.Ports "80/tcp") 0).HostPort }}' "$ID")"
echo "=> web site available on http://localhost:$PORT"

View file

@ -1 +1,6 @@
#!/bin/sh
### Helper script to push docker image to registry
### Require lucj credentials
docker push lucj/sophia.events

View file

@ -1,12 +1,18 @@
#!/bin/sh
version=$1
echo_exit() {
echo "$*"
exit 1
}
# a sepcific version can be passed as parameter
version="$1"
if [ "$version" = "" ]; then
version="latest"
fi
# Pull new image
docker pull lucj/sophia.events:$version
docker pull lucj/sophia.events:"$version" || echo_exit "Could not pull lucj/sophia.events:$version"
# Update www service with the newly retrieved image
docker service update sophia_www --image=lucj/sophia.events:$version
docker service update sophia_www --image=lucj/sophia.events:"$version"