-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Dockerfile
80 lines (52 loc) · 1.93 KB
/
Dockerfile
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
# syntax=docker/dockerfile:1
# check=skip=SecretsUsedInArgOrEnv
##############################
FROM sqitch/sqitch:v1.4.1.3 AS prepare
WORKDIR /srv/app
##############################
FROM prepare AS development
VOLUME /srv/app
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["sqitch", "--chdir", "src", "deploy", "&&", "sleep", "infinity"]
###########################
FROM prepare AS build
COPY ./src ./
###########################
FROM postgres:17.2 AS test-build
ENV POSTGRES_DB=maevsi
ENV POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password
WORKDIR /srv/app
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
sqitch=1.3.1-1 \
&& mkdir -p /run/secrets \
&& echo "postgres" > /run/secrets/postgres_password \
&& echo "grafana" > /run/secrets/postgres_role_grafana_username \
&& echo "placeholder" | tee \
/run/secrets/postgres_role_grafana_password \
/run/secrets/postgres_role_maevsi-postgraphile_password \
/run/secrets/postgres_role_maevsi-tusd_password \
/dev/null
COPY ./src ./
RUN export SQITCH_TARGET="$(cat SQITCH_TARGET.env)" \
&& docker-entrypoint.sh postgres & \
while ! pg_isready -h localhost -U postgres -p 5432; do sleep 1; done \
&& sqitch deploy -t db:pg://postgres:postgres@/maevsi \
&& pg_dump -s -h localhost -U postgres -p 5432 maevsi | sed -e '/^-- Dumped/d' > schema.sql \
&& sqitch revert -t db:pg://postgres:postgres@/maevsi
##############################
FROM test-build AS test
COPY ./test/schema/schema.definition.sql ./
RUN diff schema.definition.sql schema.sql
##############################
FROM prepare AS collect
COPY --from=test /srv/app/schema.sql /dev/null
COPY --from=build /srv/app ./
##############################
FROM collect AS production
# used in docker entrypoint
ENV ENV=production
COPY ./docker-entrypoint.sh /usr/local/bin/
COPY --from=collect /srv/app ./
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["sqitch", "deploy", "&&", "sleep", "infinity"]