forked from zopanix/docker_factorio_server
-
Notifications
You must be signed in to change notification settings - Fork 246
/
build_legacy.sh
executable file
·104 lines (87 loc) · 3.02 KB
/
build_legacy.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
set -eoux pipefail
if [[ -z ${1:-} && -n ${CI:-} ]]; then
echo 'Usage: ./build.sh VERSION_SHORT'
exit 1
elif [[ ${CI:-} == true || -n ${1:-} ]]; then
VERSION_SHORT="$1"
else
VERSION_SHORT=$(find . -maxdepth 1 -type d | sort | tail -1 | grep -o "[[0-9]].[[0-9]]*")
EXTRA_TAG=latest
fi
cd "$VERSION_SHORT" || exit 1
VERSION=$(grep -oP '[0-9]+\.[0-9]+\.[0-9]+' Dockerfile | head -1)
DOCKER_REPO=factoriotools/factorio
BRANCH=${GITHUB_REF#refs/*/}
if [[ -n ${GITHUB_BASE_REF:-} ]]; then
TAGS="-t $DOCKER_REPO:$GITHUB_BASE_REF"
else
if [[ -n ${CI:-} ]]; then
# we are either on master or on a tag build
if [[ ${BRANCH:-} == master || ${BRANCH:-} == "$VERSION" ]]; then
TAGS="-t $DOCKER_REPO:$VERSION -t $DOCKER_REPO:$VERSION_SHORT"
# we are on an incremental build of a tag
elif [[ $VERSION == "${BRANCH%-*}" ]]; then
TAGS="-t $DOCKER_REPO:$BRANCH -t $DOCKER_REPO:$VERSION -t $DOCKER_REPO:$VERSION_SHORT"
# we build a other branch than master and exclude dependabot branches from tags cause the / is not supported by docker
elif [[ -n ${BRANCH:-} && ! $BRANCH =~ "/" ]]; then
TAGS="-t $DOCKER_REPO:$BRANCH"
fi
else
# we are not in CI and tag version and version short
TAGS="-t $DOCKER_REPO:$VERSION -t $DOCKER_REPO:$VERSION_SHORT"
fi
if [[ -n ${EXTRA_TAG:-} ]]; then
IFS=","
for TAG in $EXTRA_TAG; do
TAGS+=" -t $DOCKER_REPO:$TAG"
done
fi
if [[ ${STABLE:-} == "$VERSION" ]]; then
TAGS+=" -t $DOCKER_REPO:stable"
fi
fi
# Travis gets rate limited by Docker HUB.
if [[ ${CI:-} == true && -n ${DOCKER_PASSWORD:-} && -n ${DOCKER_USERNAME:-} ]]; then
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
fi
# shellcheck disable=SC2068
eval docker build . ${TAGS[@]:-}
docker images
# remove -1 from incremental tag
# eg before: 0.18.24-1, after 0.18.24
if [[ ${BRANCH:-} ]]; then
BRANCH_VERSION=${BRANCH%-*}
fi
# only push when:
# or we build a tag and we don't build a PR
if [[ $VERSION == "${BRANCH_VERSION:-}" && ${GITHUB_BASE_REF:-} == "" ]] ||
# or we are not in CI
[[ -z ${CI:-} ]]; then
if [[ ${CI:-} == true ]]; then
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
fi
# push a tag on a branch other than master except dependabot branches cause docker does not support /
if [[ -n ${BRANCH:-} && $VERSION != "${BRANCH_VERSION:-}" && ${BRANCH:-} != "master" && ! ${BRANCH:-} =~ "/" ]]; then
docker push "$DOCKER_REPO:$BRANCH"
fi
# push an incremental tag
# eg 0.18.24-1
if [[ $VERSION == "${BRANCH_VERSION:-}" ]]; then
docker push "$DOCKER_REPO:$BRANCH"
fi
# only push on tags or when manually running the script
if [[ -n ${BRANCH_VERSION:-} || -z ${CI:-} ]]; then
docker push "$DOCKER_REPO:$VERSION"
docker push "$DOCKER_REPO:$VERSION_SHORT"
fi
if [[ -n ${EXTRA_TAG:-} ]]; then
IFS=","
for TAG in $EXTRA_TAG; do
docker push "$DOCKER_REPO:$TAG"
done
fi
if [[ ${STABLE:-} == "$VERSION" ]]; then
docker push "$DOCKER_REPO:stable"
fi
fi