Skip to content

Commit

Permalink
Run tests in Docker in CI (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
kongzii authored Sep 12, 2024
1 parent fc60d0d commit ed3f034
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
29 changes: 23 additions & 6 deletions .github/workflows/python_ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,40 @@ jobs:
mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ./.github/actions/python_prepare
- name: Run mypy
run: poetry run mypy

pytest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ./.github/actions/python_prepare
- name: Run pytest
run: poetry run pytest tests

pytest-docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Extract environment variables for Docker container
run: |
echo "MANIFOLD_API_KEY=${{ secrets.MANIFOLD_API_KEY }}" >> .env
echo "SERP_API_KEY=${{ secrets.SERP_API_KEY }}" >> .env
echo "OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}" >> .env
echo "BET_FROM_PRIVATE_KEY=${{ secrets.BET_FROM_PRIVATE_KEY }}" >> .env
echo "GRAPH_API_KEY=${{ secrets.GRAPH_API_KEY }}" >> .env
echo "PINECONE_API_KEY=${{ secrets.PINECONE_API_KEY }}" >> .env
- name: Build Dockerimage
run: make build
- name: Run pytest in Docker
run: make tests-docker

pytest-paid:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ./.github/actions/python_prepare
- name: Run pytest
run: poetry run pytest tests
Expand All @@ -57,15 +74,15 @@ jobs:
black:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ./.github/actions/python_prepare
- name: Check with black
run: poetry run black --check .

autoflake:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ./.github/actions/python_prepare
- name: Check with autoflake
run: |
Expand All @@ -75,7 +92,7 @@ jobs:
isort:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ./.github/actions/python_prepare
- name: Check with isort
run: |
Expand Down
6 changes: 2 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ WORKDIR /app

COPY pyproject.toml poetry.lock ./

RUN --mount=type=cache,target=$POETRY_CACHE_DIR poetry install --no-root --only main
RUN --mount=type=cache,target=$POETRY_CACHE_DIR poetry install --no-root

FROM --platform=linux/amd64 python:3.10.14-bookworm AS runtime

Expand All @@ -26,9 +26,7 @@ WORKDIR /app

COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}

COPY tokenizers ./tokenizers
COPY prediction_market_agent ./prediction_market_agent
COPY scripts ./scripts
COPY . .

ENV PYTHONPATH=/app
ENV PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
Expand Down
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.PHONY: build push tests-docker

IMAGE_NAME := ghcr.io/gnosis/prediction-market-agent:$(if $(GITHUB_SHA),$(GITHUB_SHA),test)

build:
docker build . -t $(IMAGE_NAME)

push:
# This should be done from Github's CD pipeline, but keeping it here for any testing purposes required in the future.
docker push $(IMAGE_NAME)

tests-docker: build
docker run --env-file .env --rm $(IMAGE_NAME) pytest tests
4 changes: 0 additions & 4 deletions build_and_push.sh

This file was deleted.

0 comments on commit ed3f034

Please sign in to comment.