Skip to content

Commit 54fe51b

Browse files
chore: Make docker-compose production ready (#6415)
- Use images instead of build - Simplify docker-compose-dev.yml - Remove ElasticSearch container - Add logic for waiting for database - Remove unused file
1 parent 23d0b57 commit 54fe51b

File tree

6 files changed

+90
-102
lines changed

6 files changed

+90
-102
lines changed

Diff for: docker-compose-dev.yaml

-76
This file was deleted.

Diff for: docker-compose-dev.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: '3.5'
2+
3+
services:
4+
web:
5+
build: .
6+
7+
celery:
8+
build: .

Diff for: docker-compose.yml

+2-20
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
version: '3.5'
22

33
x-environment-vars: &environment-vars
4+
POSTGRES_HOST: postgres
45
DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}
5-
ELASTICSEARCH_HOST: elastic:9200
66
REDIS_URL: redis://redis:6379/0
77
ADMIN_EMAIL: "@{ADMIN_EMAIL}"
88
ADMIN_PASSWORD: "@{ADMIN_PASSWORD}"
99

1010
x-defaults: &defaults
11-
build: .
11+
image: eventyay/open-event-server
1212
restart: unless-stopped
1313
environment:
1414
<<: *environment-vars
1515
depends_on:
1616
- postgres
1717
- redis
18-
- elastic
19-
links:
20-
- postgres:postgres
21-
- redis:redis
22-
- elastic:elastic
2318
volumes:
2419
- ./static:/data/app/static
2520

@@ -44,18 +39,6 @@ services:
4439
volumes:
4540
- rd:/var/lib/redis/data
4641

47-
elastic:
48-
image: elasticsearch:5.6.12-alpine
49-
container_name: opev-elastic-search
50-
restart: unless-stopped
51-
environment:
52-
- discovery.type=single-node
53-
volumes:
54-
- es:/usr/share/elasticsearch/data
55-
ports:
56-
- 9200:9200
57-
- 9300:9300
58-
5942
web:
6043
<<: *defaults
6144
container_name: opev-web
@@ -73,4 +56,3 @@ services:
7356
volumes:
7457
pg:
7558
rd:
76-
es:

Diff for: postgres-initdb.d/create_db.sql

-6
This file was deleted.

Diff for: scripts/container_start.sh

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ echo "[LOG] Using redis: ${REDIS_URL}"
77

88
if [ "$DEPLOYMENT" == "api" ]
99
then
10+
echo "[LOG] Waiting for Database" && ./scripts/wait-for.sh ${POSTGRES_HOST}:5432 --timeout=60 -- echo "[LOG] Database Up"
1011
echo "[LOG] Preparing database"
1112
python manage.py prepare_kubernetes_db
1213
echo "[LOG] Running migrations"

Diff for: scripts/wait-for.sh

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/bin/sh
2+
3+
TIMEOUT=15
4+
QUIET=0
5+
6+
echoerr() {
7+
if [ "$QUIET" -ne 1 ]; then printf "%s\n" "$*" 1>&2; fi
8+
}
9+
10+
usage() {
11+
exitcode="$1"
12+
cat << USAGE >&2
13+
Usage:
14+
$cmdname host:port [-t timeout] [-- command args]
15+
-q | --quiet Do not output any status messages
16+
-t TIMEOUT | --timeout=timeout Timeout in seconds, zero for no timeout
17+
-- COMMAND ARGS Execute command with args after the test finishes
18+
USAGE
19+
exit "$exitcode"
20+
}
21+
22+
wait_for() {
23+
for i in `seq $TIMEOUT` ; do
24+
nc -z "$HOST" "$PORT" > /dev/null 2>&1
25+
26+
result=$?
27+
if [ $result -eq 0 ] ; then
28+
if [ $# -gt 0 ] ; then
29+
exec "$@"
30+
fi
31+
exit 0
32+
fi
33+
sleep 1
34+
done
35+
echo "Operation timed out" >&2
36+
exit 1
37+
}
38+
39+
while [ $# -gt 0 ]
40+
do
41+
case "$1" in
42+
*:* )
43+
HOST=$(printf "%s\n" "$1"| cut -d : -f 1)
44+
PORT=$(printf "%s\n" "$1"| cut -d : -f 2)
45+
shift 1
46+
;;
47+
-q | --quiet)
48+
QUIET=1
49+
shift 1
50+
;;
51+
-t)
52+
TIMEOUT="$2"
53+
if [ "$TIMEOUT" = "" ]; then break; fi
54+
shift 2
55+
;;
56+
--timeout=*)
57+
TIMEOUT="${1#*=}"
58+
shift 1
59+
;;
60+
--)
61+
shift
62+
break
63+
;;
64+
--help)
65+
usage 0
66+
;;
67+
*)
68+
echoerr "Unknown argument: $1"
69+
usage 1
70+
;;
71+
esac
72+
done
73+
74+
if [ "$HOST" = "" -o "$PORT" = "" ]; then
75+
echoerr "Error: you need to provide a host and port to test."
76+
usage 2
77+
fi
78+
79+
wait_for "$@"

0 commit comments

Comments
 (0)