-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdocker-make.sh
executable file
·80 lines (70 loc) · 2.61 KB
/
docker-make.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
#!/usr/bin/env bash
# Remove temporary custom Docker configuration file when shell script exits
trap "rm -f $dockercfg" EXIT
# Catch errors
set -e
set -o pipefail
# Switch to build directory (if available)
if [[ ! -z "${GITHUB_WORKSPACE}" ]]; then
cd "${GITHUB_WORKSPACE}"
# Otherwise switch to root
else
cd "${0%/*}"
fi
DOCKER_CONFIG_FILE="${HOME}/.docker/config.json"
## TODO: This should NOT be necessary, as we're already logging in from a previous step
# Login to Docker Hub
# if [[ ! -z "${DOCKER_USERNAME+x}" && ! -z "${DOCKER_PASSWORD+x}" ]]; then
# echo "Logging in to Docker Hub.."
# # docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" > /dev/null
# sudo docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
# echo ""
# fi
# Ensure that the Docker configuration file exists
if [[ ! -f "${DOCKER_CONFIG_FILE}" ]]; then
echo "ERROR: Docker configuration file missing from ${DOCKER_CONFIG_FILE}"
ls -lah ${HOME}
exit 1
else
echo "Docker configuration file exists at ${DOCKER_CONFIG_FILE}, continuing"
fi
# Create a temporary custom Docker configuration file with the credentials embedded,
# otherwise docker-make will refuse to work correctly, as it needs permissions to push
DOCKER_CUSTOM_CONFIG="${DOCKER_CONFIG_FILE}"
if grep -q credsStore "${DOCKER_CONFIG_FILE}"; then
echo "Customizing Docker credentials for docker-make"
DOCKER_CUSTOM_CONFIG=$(mktemp /tmp/dockercfg.XXXXX)
storetype=$(jq -r .credsStore < ${DOCKER_CONFIG_FILE})
(
echo '{'
echo ' "auths": {'
for registry in $(docker-credential-$storetype list | jq -r 'to_entries[] | .key'); do
if [ ! -z $FIRST ]; then
echo ' },'
fi
FIRST=true
credential=$(echo $registry | docker-credential-$storetype get | jq -jr '"\(.Username):\(.Secret)"' | base64)
echo ' "'$registry'": {'
echo ' "auth": "'$credential'"'
done
echo ' }'
echo ' }'
echo '}'
) > $DOCKER_CUSTOM_CONFIG
else
echo "Skipping Docker credentials customization for docker-make"
fi
# Pull the latest version of docker-make
docker pull didstopia/docker-make:latest
# Run docker-make with the custom Docker configuration file
docker run \
--rm \
-w /usr/src/app \
-v "${HOME}/.docker":/root/.docker \
-v ${DOCKER_CUSTOM_CONFIG}:/root/.docker/config.json \
-v /var/run/docker.sock:/var/run/docker.sock \
-v "$(pwd)":/usr/src/app didstopia/docker-make:latest \
docker-make -rm "$@"
# Disable error handling (useful when running with "source")
set +e
set +o pipefail