-
Notifications
You must be signed in to change notification settings - Fork 47
/
run-local.sh
executable file
·82 lines (63 loc) · 1.99 KB
/
run-local.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
#!/bin/bash
# Used for running the API and necessary services (dynamo, s3, elasticsearch) locally
# Determine the docker compose invocation.
if command -v docker-compose &> /dev/null; then
DOCKER_COMPOSE="docker-compose"
else
DOCKER_COMPOSE="docker compose"
fi
# shellcheck disable=SC1091
. ./setup-local-env.sh
if [[ -z "$CI" ]]; then
echo "Stopping postgres in case it's already running"
$DOCKER_COMPOSE -f web-api/src/persistence/postgres/docker-compose.yml down || true
echo "Starting postgres"
$DOCKER_COMPOSE -f web-api/src/persistence/postgres/docker-compose.yml up -d || { echo "Failed to start Postgres containers"; exit 1; }
echo "Stopping dynamodb in case it's already running"
pkill -f DynamoDBLocal
echo "starting dynamo"
./web-api/start-dynamo.sh &
DYNAMO_PID=$!
echo "Stopping elasticsearch in case it's already running"
pkill -f elasticsearch
echo "Starting elasticsearch"
./web-api/start-elasticsearch.sh &
ESEARCH_PID=$!
URL=http://localhost:9200/ ./wait-until.sh
echo "Stopping s3rver in case it's already running"
pkill -f s3rver
fi
npm run build:assets
echo "Seeding elasticsearch"
npm run seed:elasticsearch
echo "Starting s3rver"
rm -rf ./web-api/storage/s3/*
npm run start:s3rver &
S3RVER_PID=$!
URL=http://0.0.0.0:9001/ ./wait-until.sh
npm run seed:s3
if [ -n "${RESUME}" ]; then
echo "Resuming operation with previous s3 and dynamo data"
else
echo "Creating & seeding dynamodb tables"
npm run seed:db
exitCode=$?
if [ "${exitCode}" != 0 ]; then
echo "Failed to seed data!". 1>&2 && exit 1
fi
fi
npm run migration:postgres
npm run seed:postgres
echo "Seeding cognito-local users"
npx ts-node .cognito/seedCognitoLocal.ts --transpile-only
echo "Starting cognito-local"
CODE="385030" npx cognito-local &
COGNITO_PID=$!
npm run dev:api-local
if [[ -z "$CI" ]]; then
echo "Stopping dynamodb, elasticsearch, and s3rver"
pkill -P "$DYNAMO_PID"
pkill -P "$ESEARCH_PID"
pkill -P "$S3RVER_PID"
pkill -P "$COGNITO_PID"
fi