-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpublish.sh
executable file
·95 lines (78 loc) · 3.62 KB
/
publish.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
#!/bin/bash
set -e
export DOCKER_CLI_EXPERIMENTAL="enabled"
if [[ -z "$DOCKER_USERNAME" ]]; then
echo "Set the DOCKER_USERNAME environment variable."
exit 1
fi
if [[ -z "$DOCKER_PASSWORD" ]]; then
echo "Set the DOCKER_PASSWORD environment variable."
exit 1
fi
if [[ -z "$GHCR_TOKEN" ]]; then
echo "Set the GHCR_TOKEN environment variable."
exit 1
fi
if [[ -z "$GITHUB_REPOSITORY" ]]; then
echo "Set the GITHUB_REPOSITORY environment variable."
exit 1
fi
GITHUB_OWNER=$(echo "${GITHUB_REPOSITORY}" | cut -d'/' -f1)
python_versions=( "$@" )
if [ ${#python_versions[@]} -eq 0 ]; then
if [[ -n "$PYTHON_VERSION" ]]; then
python_versions=( "${PYTHON_VERSION}" )
else
mapfile -t python_versions < PYTHON_VERSIONS
fi
fi
if [[ -n "$DEBIAN_VERSION" ]]; then
debian_versions=( "${DEBIAN_VERSION}" )
else
mapfile -t debian_versions < DEBIAN_VERSIONS
fi
platforms="linux/amd64,linux/arm/v7,linux/arm64/v8"
# Login to Docker Hub
echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin "docker.io"
# Login to GitHub Container registry
echo "${GHCR_TOKEN}" | docker login -u "${GITHUB_OWNER}" --password-stdin "ghcr.io"
docker_base_repo="docker.io/${DOCKER_USERNAME}/python"
ghcr_base_repo="ghcr.io/${GITHUB_OWNER}/python"
for python_version in "${python_versions[@]}"; do
echo "${python_version}"
for debian_version in "${debian_versions[@]}"; do
echo " ${debian_version}"
pattern='^ARG PYTHON_VERSION="(.*)"'
full_python_version=`grep -E "${pattern}" "slim/${python_version}/${debian_version}/Dockerfile"`
[[ "$full_python_version" =~ $pattern ]]
full_python_version="${BASH_REMATCH[1]}"
echo $full_python_version
for variant in {slim,minimal,busybox}; do
matching_python_version=`grep -E "${pattern}" "${variant}/${python_version}/${debian_version}/Dockerfile"`
[[ "$matching_python_version" =~ $pattern ]]
matching_python_version="${BASH_REMATCH[1]}"
if [ "$matching_python_version" == "$full_python_version" ]; then
echo "Building for python version ${full_python_version}-${variant}-${debian_version}..."
created_date=`date --utc --rfc-3339=seconds`
echo "${variant}/${python_version}/${debian_version}/"
docker buildx build \
--platform "${platforms}" \
--label "org.opencontainers.image.title=python" \
--label "org.opencontainers.image.description=python in Docker" \
--label "org.opencontainers.image.source=https://github.com/${GITHUB_REPOSITORY}" \
--label "org.opencontainers.image.revision=${GITHUB_SHA}" \
--label "org.opencontainers.image.created=${created_Date}" \
--label "org.opencontainers.image.version=${full_python_version}" \
--tag "${docker_base_repo}:${python_version}-${variant}-${debian_version}" \
--tag "${docker_base_repo}:${full_python_version}-${variant}-${debian_version}" \
--tag "${ghcr_base_repo}:${python_version}-${variant}-${debian_version}" \
--tag "${ghcr_base_repo}:${full_python_version}-${variant}-${debian_version}" \
--push \
--file "${variant}/${python_version}/${debian_version}/Dockerfile" \
"${variant}/${python_version}/${debian_version}/"
else
echo "${matching_python_version} does not match slim for variant ${variant}."
fi
done
done
done