forked from phoenixframework/phoenix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Earthfile
112 lines (96 loc) · 4.01 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
all:
BUILD +all-test
BUILD +all-integration-test
BUILD +npm
all-test:
BUILD --build-arg ELIXIR=1.9.4 --build-arg OTP=21.3.8.24 +test
BUILD --build-arg ELIXIR=1.12.1 --build-arg OTP=24.0.2 --build-arg RUN_INSTALLER_TESTS=1 +test
test:
FROM +test-setup
RUN MIX_ENV=test mix deps.compile
COPY --dir assets config installer lib integration_test priv test ./
# Run unit tests
RUN mix test
IF [ "$RUN_INSTALLER_TESTS" = "1" ]
WORKDIR /src/installer
RUN mix test
ELSE
RUN echo "Skipping installer tests"
END
all-integration-test:
BUILD --build-arg ELIXIR=1.12.1 --build-arg OTP=22.3.4.19 +integration-test
BUILD --build-arg ELIXIR=1.12.1 --build-arg OTP=24.0.2 +integration-test
integration-test:
FROM +setup-base
RUN apk add --no-progress --update docker docker-compose
# Install tooling needed to check if the DBs are actually up when performing integration tests
RUN apk add postgresql-client mysql-client
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}"
# Integration test deps
COPY /integration_test/docker-compose.yml ./integration_test/docker-compose.yml
COPY mix.exs ./
COPY /.formatter.exs ./
COPY /installer/mix.exs ./installer/mix.exs
COPY /integration_test/mix.exs ./integration_test/mix.exs
COPY /integration_test/mix.lock ./integration_test/mix.lock
COPY /integration_test/config/config.exs ./integration_test/config/config.exs
WORKDIR /src/integration_test
RUN mix local.hex --force
# Ensure integration_test/mix.lock contains all of the dependencies we need and none we don't
RUN cp mix.lock mix.lock.orig && \
mix deps.get && \
mix deps.unlock --check-unused && \
diff -u mix.lock.orig mix.lock && \
rm mix.lock.orig
# Compile phoenix
COPY --dir assets config installer lib test priv /src
RUN mix local.rebar --force
# Compiling here improves caching, but slows down GHA speed
# Removing until this feature exists https://github.com/earthly/earthly/issues/574
# RUN MIX_ENV=test mix deps.compile
# Run integration tests
COPY integration_test/test ./test
COPY integration_test/config/config.exs ./config/config.exs
WITH DOCKER
# Start docker compose
# In parallel start compiling tests
# Check for DB to be up x 3
# Run the database tests
RUN docker-compose up -d & \
MIX_ENV=test mix deps.compile && \
while ! sqlcmd -S tcp:localhost,1433 -U sa -P 'some!Password' -Q "SELECT 1" > /dev/null 2>&1; do sleep 1; done; \
while ! mysqladmin ping --host=localhost --port=3306 --protocol=TCP --silent; do sleep 1; done; \
while ! pg_isready --host=localhost --port=5432 --quiet; do sleep 1; done; \
mix test --include database
END
npm:
FROM node:12-alpine3.12
WORKDIR /src
RUN mkdir assets
# Copy package.json + lockfile separatelly to improve caching (JS changes don't trigger `npm install` anymore)
COPY assets/package* assets
WORKDIR assets
RUN npm install
COPY assets/ .
RUN npm test
setup-base:
ARG ELIXIR=1.12.1
ARG OTP=24.0.2
FROM hexpm/elixir:$ELIXIR-erlang-$OTP-alpine-3.13.3
RUN apk add --no-progress --update git build-base
ENV ELIXIR_ASSERT_TIMEOUT=10000
WORKDIR /src
test-setup:
FROM +setup-base
COPY mix.exs .
COPY mix.lock .
COPY .formatter.exs .
COPY package.json .
RUN mix local.rebar --force
RUN mix local.hex --force
RUN mix deps.get