/
run.sh
executable file
·51 lines (41 loc) · 1.17 KB
/
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
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
set -euo pipefail
while getopts v: flag
do
case "${flag}" in
v)
echo "Executing command with php verison: $OPTARG" >&2
phpversion=${OPTARG};;
esac
done
if [ "$1" = "-v7" ] || [ "$1" = "-v8" ]; then
shift
fi
# Find current folder
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
read_env_var() {
VAR=$(grep $1 $2 | xargs)
IFS="=" read -ra VAR <<< "$VAR"
echo ${VAR[1]}
}
GITHUB_TOKEN=$(read_env_var GITHUB_TOKEN .env)
# Use a checksum of the dockerfile + dependencies as the image version
TAG_NAME="demvsystems/werte"
TAG_VERSION="$(cat "$DIR/Dockerfile-php-$phpversion" | shasum -t | cut -d ' ' -f 1)"
TAG="$TAG_NAME:$TAG_VERSION"
# Build a new image if we pass --build or the image is outdated
if [ "$1" = "--build" ] || [ "$(docker images -q "$TAG" 2> /dev/null)" == "" ]; then
docker build "--tag=$TAG" \
"$DIR" \
--file "$DIR/Dockerfile-php-$phpversion" \
--build-arg GITHUB_TOKEN="$GITHUB_TOKEN"
# Remove --build if present
if [ "$1" = "--build" ]; then
shift
fi
fi
# Pass arguments to new temporary container
docker run --rm -it \
-v "$DIR:/var/www/html" \
"$TAG" \
"$@"