-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush
47 lines (41 loc) · 1.89 KB
/
push
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
#!/bin/bash
# @see https://docs.docker.com/docker-hub/builds/advanced/#build-hook-examples
# Checks DOCKER_TAG.
# This code supports DOCKER_TAG 'latest' only in current specification.
check_docker_tag() {
# @see https://github.com/docker/hub-feedback/issues/1457#issuecomment-415030262
# @see https://stackoverflow.com/questions/34789149/bash-control-statement-double-forward-slash
# @see https://stackoverflow.com/questions/918886/how-do-i-split-a-string-on-a-delimiter-in-bash/5257398#5257398
docker_tags=(${DOCKER_TAG//,/ })
latest=false
# @see https://stackoverflow.com/questions/3685970/check-if-a-bash-array-contains-a-value/15394738#15394738
if [[ " ${docker_tags[@]} " =~ ' latest ' ]]; then
latest=true
# @see https://stackoverflow.com/questions/16860877/remove-an-element-from-a-bash-array/16861932#16861932
delete=(latest)
docker_tags=${docker_tags[@]/$delete}
fi
}
# Runs matrix push.
# @see https://blog.thesparktree.com/docker-hub-matrix-builds
run_matrix_push() {
while read software_version_line; do
wordpress_version=$(echo "${software_version_line}" | cut -d ',' -f 1)
php_image_tag=$(echo "${software_version_line}" | cut -d ',' -f 2)
image_tag="${DOCKER_REPO}:${wordpress_version}-php${php_image_tag}"
docker push "${image_tag}"
done < software-versions.txt
}
# Tags image which defined by first line of software-versions.txt as latest.
tag_and_push_latest() {
latest_software_version=$(cat software-versions.txt | head -n 1)
wordpress_version=$(echo "${latest_software_version}" | cut -d ',' -f 1)
php_image_tag=$(echo "${latest_software_version}" | cut -d ',' -f 2)
docker tag "${DOCKER_REPO}:${wordpress_version}-php${php_image_tag}" "${DOCKER_REPO}:latest"
docker push "${DOCKER_REPO}:latest"
}
check_docker_tag
run_matrix_push
if [ "$latest" = true ] ; then
tag_and_push_latest
fi