Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run pytest in Docker #8

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions .github/workflows/python_ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,38 @@ 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

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
- 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
Expand All @@ -45,15 +60,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 @@ -63,7 +78,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 All @@ -73,7 +88,7 @@ jobs:
build-image-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`.
- name: Build and push Docker image
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56
Expand Down
4 changes: 2 additions & 2 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 @@ -24,7 +24,7 @@ WORKDIR /app

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

COPY mech_tool_deployment ./mech_tool_deployment
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/mech-tool-deployment:$(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.

Loading