Skip to content

Commit

Permalink
Merge pull request #22 from annatel/earthfile
Browse files Browse the repository at this point in the history
support of postgres
  • Loading branch information
Laetitia Ohayon authored May 19, 2022
2 parents 96a9786 + 9c4f2ce commit 83dd196
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,27 @@ lint:
test:
FROM earthly/dind:alpine
WORKDIR /test
RUN apk add --no-progress --update mysql-client
RUN apk add --no-progress --update mysql-client postgresql-client

COPY --dir config lib priv test .

ARG PG_IMG="postgres:11.11"
ARG MYSQL_IMG="mysql:5.7"

WITH DOCKER --pull "$MYSQL_IMG" --load elixir:latest=+deps --build-arg MIX_ENV="test"
WITH DOCKER --pull "$PG_IMG" --pull "$MYSQL_IMG" --load elixir:latest=+deps --build-arg MIX_ENV="test"
RUN set -e; \
timeout=$(expr $(date +%s) + 60); \

docker run --name pg --network=host -d -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=queuetopia "$PG_IMG"; \
docker run --name mysql --network=host -d -e MYSQL_ROOT_PASSWORD=root "$MYSQL_IMG"; \

# 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; \

# 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); \
Expand All @@ -60,6 +69,21 @@ test:
-v "$PWD/test:/app/test" \
-w /app \
--name queuetopia \
elixir:latest mix test; \

docker run \
--rm \
-e MIX_ENV=test \
-e EX_LOG_LEVEL=warn \
-e QUEUETOPIA__DATABASE_TEST_URL="ecto://postgres:postgres@localhost:5432/queuetopia" \
-e QUEUETOPIA__DATABASE_TEST_REPO_ADAPTER=postgres \
--network host \
-v "$PWD/config:/app/config" \
-v "$PWD/lib:/app/lib" \
-v "$PWD/priv:/app/priv" \
-v "$PWD/test:/app/test" \
-w /app \
--name queuetopia \
elixir:latest mix test;
END

Expand Down

0 comments on commit 83dd196

Please sign in to comment.