Repository navigation
Expand file tree
/
Copy pathdocker-build.sh
More file actions
executable file
·58 lines (48 loc) · 1.53 KB
/
Copy pathdocker-build.sh
File metadata and controls
executable file
·58 lines (48 loc) · 1.53 KB
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
#!/usr/bin/env bash
set +x
set -euo pipefail
readonly SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
readonly IMAGE_REPOSITORY="${1:?Image repository is required}"
readonly IMAGE_TAG="${2:?Image tag is required}"
readonly DOCKER_HUB_USERNAME="${3:?Docker Hub username is required}"
readonly IMAGE="${IMAGE_REPOSITORY}:${IMAGE_TAG}"
readonly PLATFORMS="${PLATFORMS:-linux/amd64}"
DOCKER_HUB_TOKEN=""
IFS= read -r DOCKER_HUB_TOKEN || true
[[ -n "${DOCKER_HUB_TOKEN}" ]] || {
echo "Docker Hub token is required on stdin." >&2
exit 1
}
case "${DOCKER_HUB_USERNAME}" in *[!a-zA-Z0-9_-]*) exit 1 ;; esac
case "${DOCKER_HUB_TOKEN}" in *[!a-zA-Z0-9_.-]*) exit 1 ;; esac
export DOCKER_HUB_USERNAME DOCKER_HUB_TOKEN
umask 077
DOCKER_CONFIG="$(mktemp -d)"
export DOCKER_CONFIG
trap 'rm -rf -- "${DOCKER_CONFIG}"' EXIT
cat > "${DOCKER_CONFIG}/docker-credential-centermcp" <<'HELPER'
#!/usr/bin/env bash
set +x
set -euo pipefail
case "${1:-}" in
store) cat > /dev/null ;;
get)
printf '{"Username":"%s","Secret":"%s"}\n' \
"${DOCKER_HUB_USERNAME}" "${DOCKER_HUB_TOKEN}"
;;
erase) ;;
*) exit 1 ;;
esac
HELPER
chmod 700 "${DOCKER_CONFIG}/docker-credential-centermcp"
export PATH="${DOCKER_CONFIG}:${PATH}"
printf '%s\n' '{"credsStore":"centermcp"}' > "${DOCKER_CONFIG}/config.json"
printf '%s' "${DOCKER_HUB_TOKEN}" |
docker login --username "${DOCKER_HUB_USERNAME}" --password-stdin
docker buildx build \
--platform "${PLATFORMS}" \
--pull \
--tag "${IMAGE}" \
--push \
"${SCRIPT_DIR}"
echo "Published ${IMAGE}"