-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdiploi-runonce.sh
92 lines (75 loc) · 2.38 KB
/
diploi-runonce.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
#!/bin/sh
progress() {
current_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
local action="$1"
echo "🟩 $current_date $action"
}
# Perform tasks at controller pod startup
progress "Runonce started";
# Set accepted ssh key(s)
mkdir -p /root/.ssh;
chmod 0700 /root/.ssh;
cat /etc/ssh/internal_ssh_host_rsa.pub > /root/.ssh/authorized_keys;
cd /app;
# Seems that this is first run in devel instance
# Intialize persistant storage
if [ ! "$(ls -A /app)" ]; then
echo "Empty /app, assuming development instance setup was intended";
# Make /app default folder
echo "cd /app;" >> /root/.bashrc
# Generate root ssh key
ssh-keygen -A;
if [ "$REPOSITORY_URL" = "https://github.com/diploi/astro-template-demo.git" ]; then
# Using quick launch cached initial files
progress "Using quick launch cache start";
find /app-quick-launch/ -mindepth 1 -maxdepth 1 -exec mv -t /app -- {} +
rmdir /app-quick-launch
progress "Using quick launch cache done";
else
progress "Pulling code";
git init --initial-branch=main
git config credential.helper '!diploi-credential-helper';
git remote add --fetch origin $REPOSITORY_URL;
if [ -z "$REPOSITORY_TAG" ]; then
git checkout -f $REPOSITORY_BRANCH;
else
git checkout -f -q $REPOSITORY_TAG;
git checkout -b main
git branch --set-upstream-to=origin/main main
fi
git remote set-url origin "$REPOSITORY_URL";
git config --unset credential.helper;
progress "Installing";
npm install;
fi
# Configure VSCode
mkdir -p /root/.local/share/code-server/User
cp /usr/local/etc/diploi-vscode-settings.json /root/.local/share/code-server/User/settings.json
# TODO: How to update these if env changes?
cat > /app/.vscode/settings.json << EOL
{
"sqltools.connections": [
{
"previewLimit": 50,
"server": "$POSTGRES_HOST",
"port": $POSTGRES_PORT,
"driver": "PostgreSQL",
"name": "PostgreSQL",
"database": "$POSTGRES_DB",
"username": "$POSTGRES_USER",
"password": "$POSTGRES_PASSWORD",
}
]
}
EOL
fi
# Update internal ca certificate
update-ca-certificates
# Make all special env variables available in ssh also (ssh will wipe out env by default)
env >> /etc/environment
# Now that everything is initialized, start all services
progress "Starting services";
supervisorctl start www
supervisorctl start code-server
progress "Runonce done";
exit 0;