forked from OpenSourceLAN/gameservers-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.sh
35 lines (28 loc) · 1 KB
/
common.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
#!/bin/bash
BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
gettimestamp() {
date +%Y%m%d-%H%M%S
}
# Builds container with given name, and any dependencies
docker_build() {
local NAME=$1
local DOCKERFILE=$2
local OTHERARGS=$3
local CACHE=""
[[ -z $NAME ]] && echo "No name provided for docker build" && exit 1
[[ -z $DOCKERFILE ]] && DOCKERFILE="-f Dockerfile" || DOCKERFILE="-f ${DOCKERFILE}"
local PARENT="$(get_docker_parent $NAME)"
[[ -n $PARENT ]] && docker_build_if_needed $PARENT
[[ -n $NOCACHE ]] && CACHE="--no-cache"
(cd $BASE_DIR/$NAME && docker build $DOCKERFILE $CACHE $OTHERARGS -t $NAME -t $NAME:$(gettimestamp) . )
}
# Builds a container if it doesn't already have a latest
docker_build_if_needed() {
local NAME=$1
[[ "$(docker images --quiet $NAME:latest)" == "" ]] && docker_build $NAME
}
get_docker_parent() {
local CHILD=$1
[[ $CHILD == "base" ]] && exit 0
grep -i "^FROM" $BASE_DIR/$CHILD/Dockerfile | awk '{print $2}' | cut -d: -f1
}