-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
41 lines (31 loc) · 915 Bytes
/
run.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
34
35
36
37
38
39
40
41
#!/bin/bash
set -euo pipefail
export $(cat .env | grep "VERSION" | xargs)
IMAGENAME="joeleehen/pubscraper"
IMAGEVERSION=${IMAGEVERSION:-latest}
BUILD_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
FORCE_DOCKER=${FORCE_DOCKER:-0}
die() {
echo "$!" 1>&2
exit 1
}
realpath() {
echo "$(
cd "$(dirname "$1")"
pwd
)"
}
# should we run installed version or from docker image?
# check for installed version
DOCKER_RUN=""
# check for docker install
docker info >/dev/null || die "Docker is not installed. Exiting"
# check for image loaded
DOCKER_IMAGE=$(docker images -q "${IMAGENAME}:${IMAGEVERSION}")
# if not, build it
if [ -z "${DOCKER_IMAGE}" ]; then
docker build -t "${IMAGENAME}:${IMAGEVERSION}" "${BUILD_DIR}"
fi
DOCKER_RUN="docker run -t --rm --env-file ${BUILD_DIR}/.env -v $(pwd):/publication-scraper ${IMAGENAME}:${IMAGEVERSION} "
echo "${DOCKER_RUN} $@" 1>&2
${DOCKER_RUN} "$@"