-
Notifications
You must be signed in to change notification settings - Fork 9
/
docker_push.sh
executable file
·79 lines (62 loc) · 2.27 KB
/
docker_push.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
#!/bin/bash
set -e
# shellcheck disable=SC2153
docker_organization=$DOCKER_ORGANIZATION
if [ -z "$REGISTRY_URL" ]; then
if [ -z "$docker_organization" ]; then
echo "::error::No DOCKER_ORGANIZATION set. This is mandatory when using docker.io"
exit 1
fi
REGISTRY_URL="docker.io"
registry_url_prefix="$REGISTRY_URL/$docker_organization"
echo "Docker organization: $docker_organization"
else
registry_url_prefix="$REGISTRY_URL"
fi
echo "registry_url_prefix: $registry_url_prefix"
if [ "$#" -lt 4 ]; then
echo "::error::You need to provide a directory with a Dockerfile in it, Docker image name, base-dir and a tag."
exit 1
fi
builddir=$1
shift
imagename=$1
shift
# basedir=$1 // Is not used, so why bother to capture this in a variable.
shift
alltags=$*
IFS=' '
read -ra tags <<<"$alltags"
basetag=${tags[0]}
if [ -z "$REGISTRY_TOKEN" ]; then
echo "::error::No REGISTRY_TOKEN set. Please provide"
exit 1
fi
if [ -z "$REGISTRY_USERNAME" ]; then
echo "::error::No REGISTRY_USERNAME set. Please provide"
exit 1
fi
echo "Login to docker"
echo "--------------------------------------------------------------------------------------------"
echo "$REGISTRY_TOKEN" | docker login "$REGISTRY_URL" -u "$REGISTRY_USERNAME" --password-stdin
{
echo '## Images pushed'
echo ''
echo '| Image |'
echo '| ---- |'
echo "| $registry_url_prefix/$imagename:$basetag |"
} >> "$GITHUB_STEP_SUMMARY"
docker push "$registry_url_prefix"/"$imagename":"$basetag"
for tag in "${tags[@]:1}"; do
echo "| $registry_url_prefix/$imagename:$tag |" >> "$GITHUB_STEP_SUMMARY"
docker push "$registry_url_prefix"/"$imagename":"$tag"
done
echo '' >> "$GITHUB_STEP_SUMMARY"
echo "--------------------------------------------------------------------------------------------"
echo "Update readme"
echo "--------------------------------------------------------------------------------------------"
export DOCKER_REPOSITORY="$docker_organization"/"$imagename"
[ "$REGISTRY_URL" = "docker.io" ] && "${FOREST_DIR}"/update_readme.sh || echo "no docker.io so no update"
echo "============================================================================================"
echo "Finished pushing docker images: $builddir"
echo "============================================================================================"