diff options
author | 2021-02-05 19:18:05 +0100 | |
---|---|---|
committer | 2021-02-07 10:20:38 +0100 | |
commit | 8337e2632686cf8d0dcf39474019370f7d3dc752 (patch) | |
tree | 7adac5b63d03aff8d81ab1250fa54d3007e51b41 /docker/root/etc/cont-init.d/50-config | |
parent | Merge pull request #47 from cromefire/db-path (diff) | |
download | ferdium-server-8337e2632686cf8d0dcf39474019370f7d3dc752.tar.gz ferdium-server-8337e2632686cf8d0dcf39474019370f7d3dc752.tar.zst ferdium-server-8337e2632686cf8d0dcf39474019370f7d3dc752.zip |
Moved getferdi/server-docker into getferdi/server repository.
Add sample docker-compose file and update README.md files in root and docker directories.
Diffstat (limited to 'docker/root/etc/cont-init.d/50-config')
-rwxr-xr-x | docker/root/etc/cont-init.d/50-config | 184 |
1 files changed, 184 insertions, 0 deletions
diff --git a/docker/root/etc/cont-init.d/50-config b/docker/root/etc/cont-init.d/50-config new file mode 100755 index 0000000..1c0caed --- /dev/null +++ b/docker/root/etc/cont-init.d/50-config | |||
@@ -0,0 +1,184 @@ | |||
1 | #!/usr/bin/with-contenv bash | ||
2 | |||
3 | # Display variables for troubleshooting | ||
4 | echo " " | ||
5 | echo "-------------------------------------" | ||
6 | echo " " | ||
7 | echo -e "Variables set:\\n\ | ||
8 | NODE_ENV=${NODE_ENV}\\n\ | ||
9 | EXTERNAL_DOMAIN=${EXTERNAL_DOMAIN}\\n\ | ||
10 | DB_CONNECTION=${DB_CONNECTION}\\n\ | ||
11 | DB_HOST=${DB_HOST}\\n\ | ||
12 | DB_PORT=${DB_PORT}\\n\ | ||
13 | DB_USER=${DB_USER}\\n\ | ||
14 | DB_PASSWORD=${DB_PASSWORD}\\n\ | ||
15 | DB_DATABASE=${DB_DATABASE}\\n\ | ||
16 | DB_SSL=${DB_SSL}\\n\ | ||
17 | IS_CREATION_ENABLED=${IS_CREATION_ENABLED}\\n\ | ||
18 | IS_DASHBOARD_ENABLED=${IS_DASHBOARD_ENABLED}\\n\ | ||
19 | IS_REGISTRATION_ENABLED=${IS_REGISTRATION_ENABLED}\\n\ | ||
20 | CONNECT_WITH_FRANZ=${CONNECT_WITH_FRANZ}\\n\ | ||
21 | MAIL_CONNECTION=${MAIL_CONNECTION}\\n\ | ||
22 | SMTP_PORT=${SMTP_PORT}\\n\ | ||
23 | SMTP_HOST=${SMTP_HOST}\\n\ | ||
24 | MAIL_SSL=${MAIL_SSL}\\n\ | ||
25 | MAIL_USERNAME=${MAIL_USERNAME}\\n\ | ||
26 | MAIL_PASSWORD=${MAIL_PASSWORD}\\n\ | ||
27 | MAIL_SENDER=${MAIL_SENDER}\\n" | ||
28 | |||
29 | # Echo init finish for test runs | ||
30 | if [ -n "${TEST_RUN}" ]; then | ||
31 | echo " " | ||
32 | echo '**** [services.d] done ****' | ||
33 | fi | ||
34 | |||
35 | # install ferdi-server if necessary | ||
36 | [[ -f /ferdi/ferdi.tar.gz ]] && \ | ||
37 | echo "**** Installing Ferdi-server ****" && \ | ||
38 | tar xf \ | ||
39 | /ferdi/ferdi.tar.gz -C \ | ||
40 | /app --strip-components=1 && \ | ||
41 | rm -rf \ | ||
42 | /ferdi && \ | ||
43 | chown -R abc:abc /app | ||
44 | |||
45 | # set ferdi-server status | ||
46 | echo " " | ||
47 | echo "**** Checking Ferdi-server settings ****" | ||
48 | if [ -f /config/config.txt ]; then | ||
49 | [[ "${NODE_ENV}" ]] && sed -i "s/NODE_ENV=.*/NODE_ENV=${NODE_ENV}/g" /config/config.txt | ||
50 | [[ "${EXTERNAL_DOMAIN}" ]] && sed -i "s/EXTERNAL_DOMAIN=.*/EXTERNAL_DOMAIN=${EXTERNAL_DOMAIN}/g" /config/config.txt | ||
51 | [[ "${IS_CREATION_ENABLED}" ]] && sed -i "s/IS_CREATION_ENABLED=.*/IS_CREATION_ENABLED=${IS_CREATION_ENABLED}/g" /config/config.txt | ||
52 | [[ "${IS_DASHBOARD_ENABLED}" ]] && sed -i "s/IS_DASHBOARD_ENABLED=.*/IS_DASHBOARD_ENABLED=${IS_DASHBOARD_ENABLED}/g" /config/config.txt | ||
53 | [[ "${IS_REGISTRATION_ENABLED}" ]] && sed -i "s/IS_REGISTRATION_ENABLED=.*/IS_REGISTRATION_ENABLED=${IS_REGISTRATION_ENABLED}/g" /config/config.txt | ||
54 | [[ "${CONNECT_WITH_FRANZ}" ]] && sed -i "s/CONNECT_WITH_FRANZ=.*/CONNECT_WITH_FRANZ=${CONNECT_WITH_FRANZ}/g" /config/config.txt | ||
55 | [[ "${DB_CONNECTION}" ]] && sed -i "s/DB_CONNECTION=.*/DB_CONNECTION=${DB_CONNECTION}/g" /config/config.txt | ||
56 | [[ "${DB_HOST}" ]] && sed -i "s/DB_HOST=.*/DB_HOST=${DB_HOST}/g" /config/config.txt | ||
57 | [[ "${DB_PORT}" ]] && sed -i "s/DB_PORT=.*/DB_PORT=${DB_PORT}/g" /config/config.txt | ||
58 | [[ "${DB_DATABASE}" ]] && sed -i "s/DB_DATABASE=.*/DB_DATABASE=${DB_DATABASE}/g" /config/config.txt | ||
59 | [[ "${DB_USER}" ]] && sed -i "s/DB_USER=.*/DB_USER=${DB_USER}/g" /config/config.txt | ||
60 | [[ "${DB_PASSWORD}" ]] && sed -i "s/DB_PASSWORD=.*/DB_PASSWORD=${DB_PASSWORD}/g" /config/config.txt | ||
61 | [[ "${DB_SSL}" ]] && sed -i "s/DB_SSL=.*/DB_SSL=${DB_SSL}/g" /config/config.txt | ||
62 | [[ "${MAIL_CONNECTION}" ]] && sed -i "s/MAIL_CONNECTION=.*/MAIL_CONNECTION=${MAIL_CONNECTION}/g" /config/config.txt | ||
63 | [[ "${SMTP_HOST}" ]] && sed -i "s/SMTP_HOST=.*/SMTP_HOST=${SMTP_HOST}/g" /config/config.txt | ||
64 | [[ "${SMTP_PORT}" ]] && sed -i "s/SMTP_PORT=.*/SMTP_PORT=${SMTP_PORT}/g" /config/config.txt | ||
65 | [[ "${MAIL_SSL}" ]] && sed -i "s/MAIL_SSL=.*/MAIL_SSL=${MAIL_SSL}/g" /config/config.txt | ||
66 | [[ "${MAIL_USERNAME}" ]] && sed -i "s/MAIL_USERNAME=.*/MAIL_USERNAME=${MAIL_USERNAME}/g" /config/config.txt | ||
67 | [[ "${MAIL_PASSWORD}" ]] && sed -i "s/MAIL_PASSWORD=.*/MAIL_PASSWORD=${MAIL_PASSWORD}/g" /config/config.txt | ||
68 | [[ "${MMAIL_SENDER}" ]] && sed -i "s/MAIL_SENDER=.*/MAIL_SENDER=${MAIL_SENDER}/g" /config/config.txt | ||
69 | rm /config/.env | ||
70 | cp /config/config.txt /config/.env | ||
71 | elif [ ! -f /config/config.txt ]; then | ||
72 | echo " " | ||
73 | echo "**** Generating .env file ****" | ||
74 | cp /defaults/.env.example /config/.env | ||
75 | [[ "${NODE_ENV}" ]] && sed -i "s/NODE_ENV=.*/NODE_ENV=${NODE_ENV}/g" /config/.env | ||
76 | [[ "${EXTERNAL_DOMAIN}" ]] && sed -i "s/EXTERNAL_DOMAIN=.*/EXTERNAL_DOMAIN=${EXTERNAL_DOMAIN}/g" /config/.env | ||
77 | [[ "${IS_CREATION_ENABLED}" ]] && sed -i "s/IS_CREATION_ENABLED=.*/IS_CREATION_ENABLED=${IS_CREATION_ENABLED}/g" /config/.env | ||
78 | [[ "${IS_DASHBOARD_ENABLED}" ]] && sed -i "s/IS_DASHBOARD_ENABLED=.*/IS_DASHBOARD_ENABLED=${IS_DASHBOARD_ENABLED}/g" /config/.env | ||
79 | [[ "${IS_REGISTRATION_ENABLED}" ]] && sed -i "s/IS_REGISTRATION_ENABLED=.*/IS_REGISTRATION_ENABLED=${IS_REGISTRATION_ENABLED}/g" /config/.env | ||
80 | [[ "${CONNECT_WITH_FRANZ}" ]] && sed -i "s/CONNECT_WITH_FRANZ=.*/CONNECT_WITH_FRANZ=${CONNECT_WITH_FRANZ}/g" /config/.env | ||
81 | [[ "${DB_CONNECTION}" ]] && sed -i "s/DB_CONNECTION=.*/DB_CONNECTION=${DB_CONNECTION}/g" /config/.env | ||
82 | [[ "${DB_HOST}" ]] && sed -i "s/DB_HOST=.*/DB_HOST=${DB_HOST}/g" /config/.env | ||
83 | [[ "${DB_PORT}" ]] && sed -i "s/DB_PORT=.*/DB_PORT=${DB_PORT}/g" /config/.env | ||
84 | [[ "${DB_DATABASE}" ]] && sed -i "s/DB_DATABASE=.*/DB_DATABASE=${DB_DATABASE}/g" /config/.env | ||
85 | [[ "${DB_USER}" ]] && sed -i "s/DB_USER=.*/DB_USER=${DB_USER}/g" /config/.env | ||
86 | [[ "${DB_PASSWORD}" ]] && sed -i "s/DB_PASSWORD=.*/DB_PASSWORD=${DB_PASSWORD}/g" /config/.env | ||
87 | [[ "${DB_SSL}" ]] && sed -i "s/DB_SSL=.*/DB_SSL=${DB_SSL}/g" /config/.env | ||
88 | [[ "${MAIL_CONNECTION}" ]] && sed -i "s/MAIL_CONNECTION=.*/MAIL_CONNECTION=${MAIL_CONNECTION}/g" /config/.env | ||
89 | [[ "${SMTP_HOST}" ]] && sed -i "s/SMTP_HOST=.*/SMTP_HOST=${SMTP_HOST}/g" /config/.env | ||
90 | [[ "${SMTP_PORT}" ]] && sed -i "s/SMTP_PORT=.*/SMTP_PORT=${SMTP_PORT}/g" /config/.env | ||
91 | [[ "${MAIL_SSL}" ]] && sed -i "s/MAIL_SSL=.*/MAIL_SSL=${MAIL_SSL}/g" /config/.env | ||
92 | [[ "${MAIL_USERNAME}" ]] && sed -i "s/MAIL_USERNAME=.*/MAIL_USERNAME=${MAIL_USERNAME}/g" /config/.env | ||
93 | [[ "${MAIL_PASSWORD}" ]] && sed -i "s/MAIL_PASSWORD=.*/MAIL_PASSWORD=${MAIL_PASSWORD}/g" /config/.env | ||
94 | [[ "${MMAIL_SENDER}" ]] && sed -i "s/MAIL_SENDER=.*/MAIL_SENDER=${MAIL_SENDER}/g" /config/.env | ||
95 | cp /config/.env /config/config.txt | ||
96 | fi | ||
97 | |||
98 | # update .env | ||
99 | if [ -f /app/.env ]; then | ||
100 | rm /app/.env | ||
101 | ln -s /config/.env /app/.env | ||
102 | elif [ ! -f /app/.env ]; then | ||
103 | ln -s /config/.env /app/.env | ||
104 | fi | ||
105 | |||
106 | # install adonisjs cli | ||
107 | echo " " | ||
108 | echo "**** Installing AdonisJS and deps ****" | ||
109 | cd /app | ||
110 | echo " " | ||
111 | npm config set unsafe-perm true | ||
112 | npm i -g @adonisjs/cli | ||
113 | |||
114 | # install adonisjs dependencies | ||
115 | npm install | ||
116 | |||
117 | # make custom recipe dir | ||
118 | if [ ! -f /app/recipes/dev ]; then | ||
119 | mkdir -p /app/recipes/dev | ||
120 | fi | ||
121 | |||
122 | # setting the database helper | ||
123 | if [ "${DB_CONNECTION}" = "sqlite" ]; then | ||
124 | echo " " | ||
125 | echo "**** DB helper loaded ****" | ||
126 | else npm i ${DB_CONNECTION} | ||
127 | echo " " | ||
128 | echo "**** DB Helper loaded ****" | ||
129 | fi | ||
130 | |||
131 | # check for the database endpoint for 30 seconds | ||
132 | echo " " | ||
133 | echo "**** Checking DB endpoint ****" | ||
134 | source .env | ||
135 | END=$((SECONDS+30)) | ||
136 | while [ ${SECONDS} -lt ${END} ] && [ "${DB_HOST} ${DB_PORT}" ]; | ||
137 | do | ||
138 | /usr/bin/nc -z ${DB_HOST} ${DB_PORT} && \ | ||
139 | if [ ! -z "$(/usr/bin/nc -w1 ${DB_HOST} ${DB_PORT})" ]; | ||
140 | then | ||
141 | [ ! -z "${RUN}" ] && break | ||
142 | RUN="RAN" | ||
143 | # we sleep here again due to first run init on DB containers | ||
144 | [ ! -f /dbwait.lock ] && sleep 5 | ||
145 | else | ||
146 | sleep 1 | ||
147 | fi | ||
148 | sleep 1 | ||
149 | done | ||
150 | |||
151 | # source the .env file | ||
152 | source .env | ||
153 | |||
154 | # database migration | ||
155 | echo " " | ||
156 | echo "**** Run DB migration ****" | ||
157 | adonis migration:run --force | ||
158 | |||
159 | # Create APP key if needed | ||
160 | if [ ! -f "/config/FERDI_APP_KEY.txt" ]; | ||
161 | then | ||
162 | echo " " | ||
163 | echo "**** Generating Ferdi-server app key for first run ****" | ||
164 | adonis key:generate | ||
165 | source .env | ||
166 | echo $APP_KEY > /config/FERDI_APP_KEY.txt | ||
167 | echo "**** App Key set to $APP_KEY you can modify FERDI_APP_KEY.txt to update your key ****" | ||
168 | sed -i "s/APP_KEY=/APP_KEY=$APP_KEY/g" /config/config.txt | ||
169 | elif [ -f "/config/FERDI_APP_KEY.txt" ]; | ||
170 | then | ||
171 | echo " " | ||
172 | echo "**** App Key found ****" | ||
173 | APP_KEY=$(cat /config/FERDI_APP_KEY.txt) | ||
174 | sed -i "s/APP_KEY=.*/APP_KEY=$APP_KEY/g" /config/config.txt | ||
175 | echo "**** App Key set to $APP_KEY you can modify FERDI_APP_KEY.txt to update your key ****" | ||
176 | fi | ||
177 | |||
178 | # set permissions | ||
179 | chown -R abc:abc \ | ||
180 | /config \ | ||
181 | /app | ||
182 | |||
183 | # set lockfile to avoid DB waits for this specific container | ||
184 | touch /dbwait.lock | ||