forked from elixir-ecto/ecto_sql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Earthfile
158 lines (126 loc) · 5.21 KB
/
Earthfile
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
all:
BUILD +test-all
BUILD +integration-test-all
test-all:
BUILD \
--build-arg ELIXIR_BASE=1.13.4-erlang-24.3.4.2-alpine-3.16.0 \
--build-arg ELIXIR_BASE=1.13.4-erlang-22.3.4.20-alpine-3.14.0 \
+test
test:
FROM +test-setup
RUN MIX_ENV=test mix deps.compile
COPY --dir bench integration_test lib test ./
RUN mix deps.get && mix deps.unlock --check-unused
RUN mix deps.compile
RUN mix compile #--warnings-as-errors
RUN mix test
integration-test-all:
ARG ELIXIR_BASE=1.13.4-erlang-24.3.4.2-alpine-3.16.0
BUILD \
--build-arg POSTGRES=11.11 \
--build-arg POSTGRES=9.6 \
--build-arg POSTGRES=9.5 \
+integration-test-postgres
BUILD \
--build-arg MYSQL=5.7 \
+integration-test-mysql
BUILD \
--build-arg MSSQL=2017 \
--build-arg MSSQL=2019 \
+integration-test-mssql
integration-test-base:
FROM +setup-base
RUN apk add --no-progress --update docker docker-compose
RUN mix local.rebar --force
RUN mix local.hex --force
COMMON_INTEGRATION_SETUP_AND_MIX:
COMMAND
COPY mix.exs mix.lock .formatter.exs .
COPY --dir bench integration_test lib test ./
RUN mix deps.get
RUN mix deps.compile
RUN mix compile #--warnings-as-errors
integration-test-postgres:
FROM +integration-test-base
ARG POSTGRES="11.11"
IF [ "$POSTGRES" = "9.5" ]
# for 9.5 we require a downgraded version of pg_dump;
# and in the 3.4 version, it is not included in postgresql-client but rather in postgresql
RUN echo 'http://dl-cdn.alpinelinux.org/alpine/v3.4/main' >> /etc/apk/repositories
RUN apk add postgresql=9.5.13-r0
ELSE
RUN apk add postgresql-client
END
DO +COMMON_INTEGRATION_SETUP_AND_MIX
# then run the tests
WITH DOCKER \
--pull "postgres:$POSTGRES"
RUN set -e; \
timeout=$(expr $(date +%s) + 30); \
docker run --name pg --network=host -d -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=postgres "postgres:$POSTGRES"; \
# wait for postgres to start
while ! pg_isready --host=127.0.0.1 --port=5432 --quiet; do \
test "$(date +%s)" -le "$timeout" || (echo "timed out waiting for postgres"; exit 1); \
echo "waiting for postgres"; \
sleep 1; \
done; \
# run tests
PG_URL=postgres:[email protected] ECTO_ADAPTER=pg mix test;
END
integration-test-mysql:
FROM +integration-test-base
RUN apk add mysql-client
DO +COMMON_INTEGRATION_SETUP_AND_MIX
ARG MYSQL="5.7"
WITH DOCKER \
--pull "mysql:$MYSQL"
RUN set -e; \
timeout=$(expr $(date +%s) + 30); \
docker run --name mysql --network=host -d -e MYSQL_ROOT_PASSWORD=root "mysql:$MYSQL" --sql_mode="ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ANSI_QUOTES"; \
# wait for mysql to start
while ! mysqladmin ping --host=127.0.0.1 --port=3306 --protocol=TCP --silent; do \
test "$(date +%s)" -le "$timeout" || (echo "timed out waiting for mysql"; exit 1); \
echo "waiting for mysql"; \
sleep 1; \
done; \
# run tests
MYSQL_URL=root:[email protected] ECTO_ADAPTER=myxql mix test;
END
integration-test-mssql:
FROM +integration-test-base
RUN apk add --no-cache curl gnupg --virtual .build-dependencies -- && \
curl -O https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8d28ddafb39b/msodbcsql17_17.5.2.1-1_amd64.apk && \
curl -O https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8d28ddafb39b/mssql-tools_17.5.2.1-1_amd64.apk && \
echo y | apk add --allow-untrusted msodbcsql17_17.5.2.1-1_amd64.apk mssql-tools_17.5.2.1-1_amd64.apk && \
apk del .build-dependencies && rm -f msodbcsql*.sig mssql-tools*.apk
ENV PATH="/opt/mssql-tools/bin:${PATH}"
DO +COMMON_INTEGRATION_SETUP_AND_MIX
ARG MSSQL="2017"
WITH DOCKER \
--pull "mcr.microsoft.com/mssql/server:$MSSQL-latest"
RUN set -e; \
timeout=$(expr $(date +%s) + 30); \
docker run -d -p 1433:1433 --name mssql -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=some!Password' "mcr.microsoft.com/mssql/server:$MSSQL-latest"; \
# wait for mssql to start
while ! sqlcmd -S tcp:127.0.0.1,1433 -U sa -P 'some!Password' -Q "SELECT 1" >/dev/null 2>&1; do \
test "$(date +%s)" -le "$timeout" || (echo "timed out waiting for mssql"; exit 1); \
echo "waiting for mssql"; \
sleep 1; \
done; \
# run tests
ECTO_ADAPTER=tds mix test;
END
setup-base:
ARG ELIXIR_BASE=1.13.4-erlang-24.3.4.2-alpine-3.16.0
FROM hexpm/elixir:$ELIXIR_BASE
RUN apk add --no-progress --update git build-base
ENV ELIXIR_ASSERT_TIMEOUT=10000
WORKDIR /src/ecto_sql
test-setup:
FROM +setup-base
COPY mix.exs .
COPY mix.lock .
COPY .formatter.exs .
RUN mix local.rebar --force
RUN mix local.hex --force
RUN mix deps.get