-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdocker-entrypoint.sh
executable file
·78 lines (61 loc) · 2.41 KB
/
docker-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
#!/bin/bash
set -e
#echo "---- Syncing time ----"
#timedatectl set-ntp on
#timedatectl
mv /app/minio /minio
cd /
sudo chmod +x /minio
sudo chmod +x /mc
echo "---- Starting Minio ----"
/minio server --address :9001 /data &> minio.log &
echo "---- Starting PostgreSQL ----"
service postgresql start
# Check if postgres user test is created
if ! sudo -u postgres psql -c "SELECT 1 FROM pg_roles WHERE rolname='test'" | grep -q 1; then
echo "---- Creating PostgreSQL user test ----"
sudo -i -u postgres psql -c "CREATE USER test with password 'test'"
sudo -i -u postgres psql -c "CREATE DATABASE cacophonytest WITH OWNER test;"
fi
sudo -i -u postgres psql cacophonytest -c "CREATE EXTENSION IF NOT EXISTS postgis"
sudo -i -u postgres psql cacophonytest -c "CREATE EXTENSION IF NOT EXISTS citext"
sudo -i -u postgres psql cacophonytest -c "CREATE EXTENSION IF NOT EXISTS ltree"
echo "---- Setting up Minio ----"
# Check minio has been setup by checking if myminio/cacophony exists
if ./mc ls myminio | grep -q cacophony; then
echo "---- Minio already setup ----"
else
echo "---- Setting up Minio ----"
./mc config host add myminio http://127.0.0.1:9001 $MINIO_ACCESS_KEY $MINIO_SECRET_KEY
./mc mb myminio/cacophony
./mc mb myminio/cacophony-archived
fi
cd /app/api
CONFIG=/app/api/config/app.js
if [ ! -f "$CONFIG" ]; then
cp /app/api/config/app_test_default.js $CONFIG
echo "---- Copying /app/api/config/app_test_default.js to $CONFIG ----"
fi
echo "---- install npm packages ----"
npm install --omit=optional --no-audit
mv ../bcrypt ./node_modules/
mv ../sharp ./node_modules/
# Sharp dependencies
if [ ! -d "./node_modules/detect-libc" ]; then
mv ../detect-libc ./node_modules/
fi
mv ../color ./node_modules/
cd ../types && npm install --no-audit
cd ../api
echo "---- Using config $CONFIG ----"
./node_modules/.bin/sequelize db:migrate --config $CONFIG --env "database"
sudo -i -u postgres psql cacophonytest -f /app/api/db-seed.sql
echo "alias psqltest='sudo -i -u postgres psql cacophonytest'" > ~/.bashrc
echo "---- Compiling JSON schemas ----"
cd ../types && npm run generate-schemas
cd ../api
echo "---- Compiling typescript and starting module ----"
./node_modules/.bin/tsc
#sleep 10000
chmod a+x ./node_modules/.bin/tsc-watch
./node_modules/.bin/tsc-watch --noClear --onSuccess "node --loader esm-module-alias/loader --no-warnings=ExperimentalWarnings --inspect=0.0.0.0:9229 ./Server.js --config=$CONFIG"