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

Create separate testing 🐳 container #1081

Closed
wants to merge 22 commits into from
Closed
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
8 changes: 0 additions & 8 deletions .github/workflows/test_prs.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
name: CI

# Controls when the action will run.
on:
pull_request:
branches:
- develop
- main

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build:
# The type of runner that the job will run on
runs-on: ubuntu-20.04
env:
FLASK_APP: OpenOversight.app
strategy:
matrix:
python-version: ["3.11", "3.12"]
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- name: Run tests
run: PYTHON_VERSION=${{ matrix.python-version }} make test_with_version
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ build_with_version: create_empty_secret

.PHONY: test_with_version
test_with_version: build_with_version assets
ENV=testing docker-compose run --rm web pytest --cov=OpenOversight --cov-report xml:OpenOversight/tests/coverage.xml --doctest-modules -n 4 --dist=loadfile -v OpenOversight/tests/
docker-compose run --rm web-test pytest --cov=OpenOversight --cov-report xml:OpenOversight/tests/coverage.xml --doctest-modules -n 4 --dist=loadfile -v OpenOversight/tests/

.PHONY: start
start: build ## Run containers
Expand Down Expand Up @@ -48,9 +48,9 @@ populate: create_db ## Build and run containers
.PHONY: test
test: start ## Run tests
if [ -z "$(name)" ]; then \
ENV=testing docker-compose run --rm web pytest --cov --doctest-modules -n auto --dist=loadfile -v OpenOversight/tests/; \
docker-compose run --rm web-test pytest --cov --doctest-modules -n auto --dist=loadfile -v OpenOversight/tests/; \
else \
ENV=testing docker-compose run --rm web pytest --cov --doctest-modules -v OpenOversight/tests/ -k $(name); \
docker-compose run --rm web-test pytest --cov --doctest-modules -v OpenOversight/tests/ -k $(name); \
fi

.PHONY: lint
Expand Down
18 changes: 17 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ services:
AWS_ACCESS_KEY_ID: "${AWS_ACCESS_KEY_ID}"
AWS_DEFAULT_REGION: "${AWS_DEFAULT_REGION}"
AWS_SECRET_ACCESS_KEY: "${AWS_SECRET_ACCESS_KEY}"
ENV: "${ENV:-development}"
ENV: "development"
FLASK_APP: OpenOversight.app
FLASK_DEBUG: 1
OO_HELP_EMAIL: "[email protected]"
Expand All @@ -55,3 +55,19 @@ services:
- "3000"
ports:
- "3000:3000"

web-test:
restart: always
build:
context: .
args:
- MAKE_PYTHON_VERSION
dockerfile: ./dockerfiles/web/Dockerfile-test
environment:
ENV: "testing"
FLASK_APP: OpenOversight.app
OO_HELP_EMAIL: "[email protected]"
OO_SERVICE_EMAIL: "[email protected]"
TIMEZONE: "America/Chicago"
volumes:
- ./OpenOversight/:/usr/src/app/OpenOversight/:z
4 changes: 2 additions & 2 deletions dockerfiles/web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ ENV DEBIAN-FRONTEND noninteractive
ENV DISPLAY=:1

# install apt dependencies
RUN apt-get update && apt-get install -y xvfb firefox-esr libpq-dev python3-dev && \
apt-get install -y libsqlite3-0 && apt-get clean
RUN apt-get update && apt-get install -y xvfb firefox-esr libpq-dev python3-dev \
&& apt-get clean

# install node
ENV NODE_SETUP_SHA=5d07994f59e3edc2904c547e772b818d10abb066f6ff36ab3db5d686b0fe9a73
Expand Down
56 changes: 56 additions & 0 deletions dockerfiles/web/Dockerfile-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
ARG MAKE_PYTHON_VERSION
ARG DOCKER_BUILD_ENV
FROM python:${MAKE_PYTHON_VERSION:-3.11}-bullseye

WORKDIR /usr/src/app

ENV CURL_FLAGS="--proto =https --tlsv1.2 -sSf -L --max-redirs 1 -O"

ENV DEBIAN-FRONTEND noninteractive
ENV DISPLAY=:1

# install apt dependencies
RUN apt-get update && apt-get install -y xvfb libpq-dev python3-dev libsqlite3-0 && \
apt-get clean

# install node
ENV NODE_SETUP_SHA=5d07994f59e3edc2904c547e772b818d10abb066f6ff36ab3db5d686b0fe9a73
RUN curl ${CURL_FLAGS} \
https://raw.githubusercontent.com/nodesource/distributions/b8510857fb4ce4b023161be8490b00119884974c/deb/setup_12.x
RUN echo "${NODE_SETUP_SHA} setup_12.x" | sha256sum --check -
RUN bash setup_12.x
RUN apt-get install -y nodejs

# install geckodriver
ENV GECKODRIVER_VERSION="v0.26.0"
ENV GECKODRIVER_SHA=d59ca434d8e41ec1e30dd7707b0c95171dd6d16056fb6db9c978449ad8b93cc0
ENV GECKODRIVER_BASE_URL="https://github.com/mozilla/geckodriver/releases/download"
RUN curl ${CURL_FLAGS} \
${GECKODRIVER_BASE_URL}/${GECKODRIVER_VERSION}/geckodriver-${GECKODRIVER_VERSION}-linux64.tar.gz
RUN echo "${GECKODRIVER_SHA} geckodriver-${GECKODRIVER_VERSION}-linux64.tar.gz" | sha256sum --check -
RUN mkdir geckodriver
RUN tar -xzf geckodriver-${GECKODRIVER_VERSION}-linux64.tar.gz -C geckodriver

# install yarn
RUN npm install -g yarn
RUN mkdir /var/www ./node_modules /.cache /.yarn /.mozilla
RUN touch /usr/src/app/yarn-error.log
COPY yarn.lock /usr/src/app/
RUN chmod -R 777 /usr/src/app/ /var/lib/xkb /.cache /.yarn /.mozilla


COPY requirements.txt dev-requirements.txt /usr/src/app/
RUN pip3 install --no-cache-dir -r requirements.txt

RUN pip3 install --no-cache-dir -r dev-requirements.txt

COPY package.json /usr/src/app/
RUN yarn

COPY test_data.py /usr/src/app/
COPY mypy.ini /usr/src/app/

ENV PATH="/usr/src/app/geckodriver:${PATH}"
ENV SECRET_KEY 4Q6ZaQQdiqtmvZaxP1If

WORKDIR /usr/src/app/
Loading