|
| 1 | +all: |
| 2 | + BUILD +test-all |
| 3 | + BUILD +integration-test-all |
| 4 | + |
| 5 | + |
| 6 | +test-all: |
| 7 | + BUILD \ |
| 8 | + --build-arg ELIXIR_BASE=1.11.0-erlang-23.1.1-alpine-3.13.1 \ |
| 9 | + --build-arg ELIXIR_BASE=1.11.0-erlang-21.3.8.21-alpine-3.13.1 \ |
| 10 | + +test |
| 11 | + |
| 12 | + |
| 13 | +test: |
| 14 | + FROM +test-setup |
| 15 | + RUN MIX_ENV=test mix deps.compile |
| 16 | + COPY --dir bench integration_test lib test ./ |
| 17 | + |
| 18 | + RUN mix deps.get && mix deps.unlock --check-unused |
| 19 | + RUN mix deps.compile |
| 20 | + RUN mix compile #--warnings-as-errors |
| 21 | + RUN mix test |
| 22 | + |
| 23 | + |
| 24 | +integration-test-all: |
| 25 | + ARG ELIXIR_BASE=1.11.0-erlang-23.1.1-alpine-3.13.1 |
| 26 | + BUILD \ |
| 27 | + --build-arg POSTGRES=11.11 \ |
| 28 | + --build-arg POSTGRES=9.6 \ |
| 29 | + --build-arg POSTGRES=9.5 \ |
| 30 | + +integration-test-postgres |
| 31 | + |
| 32 | + BUILD \ |
| 33 | + --build-arg MYSQL=5.7 \ |
| 34 | + +integration-test-mysql |
| 35 | + |
| 36 | + BUILD \ |
| 37 | + --build-arg MSSQL=2017 \ |
| 38 | + --build-arg MSSQL=2019 \ |
| 39 | + +integration-test-mssql |
| 40 | + |
| 41 | + |
| 42 | +integration-test-base: |
| 43 | + FROM +setup-base |
| 44 | + RUN apk add --no-progress --update docker docker-compose |
| 45 | + |
| 46 | + RUN mix local.rebar --force |
| 47 | + RUN mix local.hex --force |
| 48 | + |
| 49 | + |
| 50 | +COMMON_INTEGRATION_SETUP_AND_MIX: |
| 51 | + COMMAND |
| 52 | + COPY mix.exs mix.lock .formatter.exs . |
| 53 | + COPY --dir bench integration_test lib test ./ |
| 54 | + RUN mix deps.get |
| 55 | + RUN mix deps.compile |
| 56 | + RUN mix compile #--warnings-as-errors |
| 57 | + |
| 58 | + |
| 59 | +integration-test-postgres: |
| 60 | + FROM +integration-test-base |
| 61 | + ARG POSTGRES="11.11" |
| 62 | + |
| 63 | + IF [ "$POSTGRES" = "9.5" ] |
| 64 | + # for 9.5 we require a downgraded version of pg_dump; |
| 65 | + # and in the 3.4 version, it is not included in postgresql-client but rather in postgresql |
| 66 | + RUN echo 'http://dl-cdn.alpinelinux.org/alpine/v3.4/main' >> /etc/apk/repositories |
| 67 | + RUN apk add postgresql=9.5.13-r0 |
| 68 | + ELSE |
| 69 | + RUN apk add postgresql-client |
| 70 | + END |
| 71 | + |
| 72 | + DO +COMMON_INTEGRATION_SETUP_AND_MIX |
| 73 | + |
| 74 | + # then run the tests |
| 75 | + WITH DOCKER \ |
| 76 | + --pull "postgres:$POSTGRES" |
| 77 | + RUN set -e; \ |
| 78 | + timeout=$(expr $(date +%s) + 30); \ |
| 79 | + docker run --name pg --network=host -d -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=postgres "postgres:$POSTGRES"; \ |
| 80 | + # wait for postgres to start |
| 81 | + while ! pg_isready --host=127.0.0.1 --port=5432 --quiet; do \ |
| 82 | + test "$(date +%s)" -le "$timeout" || (echo "timed out waiting for postgres"; exit 1); \ |
| 83 | + echo "waiting for postgres"; \ |
| 84 | + sleep 1; \ |
| 85 | + done; \ |
| 86 | + # run tests |
| 87 | + PG_URL=postgres:postgres@127.0.0.1 ECTO_ADAPTER=pg mix test; |
| 88 | + END |
| 89 | + |
| 90 | + |
| 91 | +integration-test-mysql: |
| 92 | + FROM +integration-test-base |
| 93 | + RUN apk add mysql-client |
| 94 | + |
| 95 | + DO +COMMON_INTEGRATION_SETUP_AND_MIX |
| 96 | + |
| 97 | + ARG MYSQL="5.7" |
| 98 | + WITH DOCKER \ |
| 99 | + --pull "mysql:$MYSQL" |
| 100 | + RUN set -e; \ |
| 101 | + timeout=$(expr $(date +%s) + 30); \ |
| 102 | + docker run --name mysql --network=host -d -e MYSQL_ROOT_PASSWORD=root "mysql:$MYSQL"; \ |
| 103 | + # wait for mysql to start |
| 104 | + while ! mysqladmin ping --host=127.0.0.1 --port=3306 --protocol=TCP --silent; do \ |
| 105 | + test "$(date +%s)" -le "$timeout" || (echo "timed out waiting for mysql"; exit 1); \ |
| 106 | + echo "waiting for mysql"; \ |
| 107 | + sleep 1; \ |
| 108 | + done; \ |
| 109 | + # run tests |
| 110 | + MYSQL_URL=root:root@127.0.0.1 ECTO_ADAPTER=myxql mix test; |
| 111 | + END |
| 112 | + |
| 113 | + |
| 114 | +integration-test-mssql: |
| 115 | + FROM +integration-test-base |
| 116 | + |
| 117 | + RUN apk add --no-cache curl gnupg --virtual .build-dependencies -- && \ |
| 118 | + curl -O https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8d28ddafb39b/msodbcsql17_17.5.2.1-1_amd64.apk && \ |
| 119 | + curl -O https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8d28ddafb39b/mssql-tools_17.5.2.1-1_amd64.apk && \ |
| 120 | + echo y | apk add --allow-untrusted msodbcsql17_17.5.2.1-1_amd64.apk mssql-tools_17.5.2.1-1_amd64.apk && \ |
| 121 | + apk del .build-dependencies && rm -f msodbcsql*.sig mssql-tools*.apk |
| 122 | + ENV PATH="/opt/mssql-tools/bin:${PATH}" |
| 123 | + |
| 124 | + DO +COMMON_INTEGRATION_SETUP_AND_MIX |
| 125 | + |
| 126 | + ARG MSSQL="2017" |
| 127 | + WITH DOCKER \ |
| 128 | + --pull "mcr.microsoft.com/mssql/server:$MSSQL-latest" |
| 129 | + RUN set -e; \ |
| 130 | + timeout=$(expr $(date +%s) + 30); \ |
| 131 | + 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"; \ |
| 132 | + # wait for mssql to start |
| 133 | + while ! sqlcmd -S tcp:127.0.0.1,1433 -U sa -P 'some!Password' -Q "SELECT 1" >/dev/null 2>&1; do \ |
| 134 | + test "$(date +%s)" -le "$timeout" || (echo "timed out waiting for mssql"; exit 1); \ |
| 135 | + echo "waiting for mssql"; \ |
| 136 | + sleep 1; \ |
| 137 | + done; \ |
| 138 | + # run tests |
| 139 | + ECTO_ADAPTER=tds mix test; |
| 140 | + END |
| 141 | + |
| 142 | + |
| 143 | +setup-base: |
| 144 | + ARG ELIXIR_BASE=1.11.0-erlang-23.1.1-alpine-3.13.1 |
| 145 | + FROM hexpm/elixir:$ELIXIR_BASE |
| 146 | + RUN apk add --no-progress --update git build-base |
| 147 | + ENV ELIXIR_ASSERT_TIMEOUT=10000 |
| 148 | + WORKDIR /src/ecto_sql |
| 149 | + |
| 150 | + |
| 151 | +test-setup: |
| 152 | + FROM +setup-base |
| 153 | + COPY mix.exs . |
| 154 | + COPY mix.lock . |
| 155 | + COPY .formatter.exs . |
| 156 | + RUN mix local.rebar --force |
| 157 | + RUN mix local.hex --force |
| 158 | + RUN mix deps.get |
0 commit comments