-
Notifications
You must be signed in to change notification settings - Fork 1
/
entrypoint.sh
executable file
·93 lines (86 loc) · 1.76 KB
/
entrypoint.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
#!/bin/sh
# Exit immediately if a pipeline returns a non-zero status.
set -e
# Add Prviate Key
add_ssh_key() {
mkdir -p ~/.ssh/
echo -e "$INPUT_SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
echo "SSH Key Installed"
}
# Start Up ssh-agent
start_up_ssh_agent() {
eval `ssh-agent`
ssh-add ~/.ssh/id_rsa
}
# Docker login
docker_login() {
if [ -n "$INPUT_USERNAME" ] && [ -n "$INPUT_PASSWORD" ]
then
if [ -n "$INPUT_REGISTRY" ]
then
echo "$INPUT_PASSWORD" | docker login "$INPUT_REGISTRY" -u "$INPUT_USERNAME" --password-stdin
else
echo "$INPUT_PASSWORD" | docker login -u "$INPUT_USERNAME" --password-stdin
fi
else
exit 1
fi
}
# Docker build
docker_build() {
docker build $OPTION $INPUT_PATH
if [ "$INPUT_PUSH" = true ]
then
if [ -n "$INPUT_REGISTRY" ]
then
if [ -n "$INPUT_TAGS" ]
then
echo $INPUT_TAGS | tr "," "\n" | while read TAG; do
docker push "$INPUT_REGISTRY/$INPUT_REPOSITORY:$TAG"
done
else
docker push "$INPUT_REGISTRY/$INPUT_REPOSITORY"
fi
else
if [ -n "$INPUT_TAGS" ]
then
echo $INPUT_TAGS | tr "," "\n" | while read TAG; do
docker push "$INPUT_REPOSITORY:$TAG"
done
else
docker push "$INPUT_REPOSITORY"
fi
fi
fi
}
# Option builder
opt_builder() {
if [ -n "$INPUT_TAGS" ]
then
for TAG in $(echo $INPUT_TAGS | tr "," "\n"); do
if [ -n "$INPUT_REGISTRY" ]
then
OPTION="$OPTION -t $INPUT_REGISTRY/$INPUT_REPOSITORY:$TAG"
else
OPTION="$OPTION -t $INPUT_REPOSITORY:$TAG"
fi
done
fi
if [ -n "$INPUT_DOCKERFILE" ]
then
OPTION="$OPTION -f $INPUT_DOCKERFILE"
fi
if [ "$INPUT_SSH" = true ]
then
OPTION="--ssh default $OPTION"
fi
}
if [ -n "$INPUT_SSH_PRIVATE_KEY" ]
then
add_ssh_key
start_up_ssh_agent
fi
docker_login
opt_builder
docker_build