This repository has been archived by the owner on Jul 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
77 lines (62 loc) · 2.24 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
#!/bin/bash
cd ~
checkExitCode() {
exitcode=$?
if [[ ${exitcode} -ne 0 ]]; then
echo "Previous command failed with exit code ${exitcode}, container will stop now!"
exit ${exitcode}
fi
}
#Check if this is the first time this container ran
if [[ ! -f .first_execution ]]; then
echo "This is the first time this container gets executed, so we will install the dependencies and main app..."
# Clear output directory if exists
echo "Cleaning output directory..."
rm -rf keys
rm -rf ${APP_NAME}
checkExitCode
# Fetch private key if exists
if [[ ! -z ${SSH_KEY} ]]; then
# Save base64 Key on a file
echo "SSH Key detected"
mkdir keys
echo "${SSH_KEY}" > keys/ssh_key.base64
checkExitCode
# Decode the base64 Key and save decoded on a file
echo "Decoding base64 SSH key..."
base64 -d -i keys/ssh_key.base64 > keys/ssh_key
checkExitCode
# Set proper permissions to the key
chmod 600 keys/ssh_key
fi
# Get GIT Branch option if exists
if [[ ! -z ${GIT_BRANCH} ]]; then
git_branch_options=(--branch ${GIT_BRANCH})
fi
# Clone APP repository using GIT
if [[ -z ${SSH_KEY} ]]; then
# Without SSH
echo "Cloning app through git..."
git clone --branch ${GIT_BRANCH} ${GIT_REPOSITORY} ${APP_NAME}
checkExitCode
else
# With SSH
echo "Cloning app through git+ssh..."
GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i keys/ssh_key" git clone ${GIT_REPOSITORY} ${APP_NAME}
checkExitCode
# Remove SSH keys after successful clone
rm -rf keys
checkExitCode
fi
# Install API python requirements through PIP
echo "Installing app dependencies through pip..."
pip install --user --upgrade -r ${APP_NAME}/requirements.txt
checkExitCode
# Create file so next time container runs, this won't get executed again
# (only if all the previous commands were executed successfully, otherwise the container should be stopped)
touch .first_execution
echo "All requirements installed! We are ready to run the app"
fi
#Start the app
echo "Starting the app now!"
python -u ${APP_NAME}