Skip to content

Commit

Permalink
Build scripts refactoring (#33)
Browse files Browse the repository at this point in the history
* Build scripts refactoring

`.github/build-and-upload.sh` to use `build.sh`
Related to  #32

* Update build.sh

Following review comments
  • Loading branch information
zstadler authored Jan 12, 2023
1 parent 7b50d77 commit f06f2be
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
22 changes: 7 additions & 15 deletions .github/build-and-upload.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
#!/bin/bash

echo "Cloning graphhopper"
git clone https://github.com/graphhopper/graphhopper.git
echo "Building docker image"
docker build . -t israelhikingmap/graphhopper:latest
docker login --username $DOCKERHUB_USER --password $DOCKERHUB_TOKEN
echo "Publishing docker image"
docker push israelhikingmap/graphhopper:latest
echo "Buidling and pushing israelhikingmap/graphhopper:latest"
./build.sh --push

TAG=`cd graphhopper; git for-each-ref --sort=committerdate refs/tags | tail -n 1 | cut -d "/" -f3`
if docker manifest inspect israelhikingmap/graphhopper:$TAG >/dev/null; then
echo "No need to publish existing version: $TAG";
TAG=`cd graphhopper; git for-each-ref --sort=committerdate refs/tags | sed -n '$s/.*\///p'`
if docker manifest inspect "israelhikingmap/graphhopper:${TAG}" >/dev/null; then
echo "No need to push existing version: ${TAG}";
else
(cd graphhopper ; git checkout tags/$TAG)
echo "Building docker image for tag: $TAG"
docker build . -t israelhikingmap/graphhopper:$TAG
echo "Publishing docker image for tag: $TAG"
docker push israelhikingmap/graphhopper:$TAG
echo "Buidling and pushing israelhikingmap/graphhopper:${TAG}"
./build.sh --push "${TAG}"
fi
30 changes: 24 additions & 6 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,32 @@

usage() (
cat <<USAGE
Build a docker image
Build a docker image for GraphHopper and optionally push it to Docker Hub
Usage:
./build.sh [<tag> | --help]
./build.sh [[--push] <tag>]
./build.sh --help
Argument:
<tag> Build an image for the given graphhopper repository tag [default: master]
<tag> Build an image for the given graphhopper repository tag [default: master]
Option:
--help Print this message
--push Push the image to Docker Hub
--help Print this message
Docker Hub credentials are needed for pushing the image. If they are not provided using the
DOCKERHUB_USER and DOCKERHUB_TOKEN environment variables, then they will be asked interactively.
USAGE
)

if [ "$1" == "--push" ]; then
push="true"
docker login --username "${DOCKERHUB_USER}" --password "${DOCKERHUB_TOKEN}" || exit $?
shift
else
push="false"
fi

if [ $# -gt 1 ] || [ "$1" == "--help" ]; then
usage
exit
Expand All @@ -23,6 +36,9 @@ fi
if [ ! -d graphhopper ]; then
echo "Cloning graphhopper"
git clone https://github.com/graphhopper/graphhopper.git
else
echo "Pulling graphhopper"
(cd graphhopper; git checkout master; git pull)
fi

imagename="israelhikingmap/graphhopper:${1:-latest}"
Expand All @@ -32,8 +48,10 @@ if [ "$1" ]; then
fi

echo "Building docker image ${imagename}"
docker build . -t ${imagename}
docker build . -t "${imagename}"

if [ $# -eq 1 ]; then
if [ "${push}" == "false" ]; then
echo "Use \"docker push ${imagename}\" to publish the image on Docker Hub"
else
docker push "${imagename}"
fi

0 comments on commit f06f2be

Please sign in to comment.