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 test-specific 🐳 file #1082

Merged
merged 36 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
1e8ff2a
Update test_prs.yml
michplunkett Dec 30, 2023
5dd6e11
Update Dockerfile
michplunkett Dec 30, 2023
3d4500a
Create Dockerfile-test
michplunkett Dec 30, 2023
61e966b
Update Makefile
michplunkett Dec 30, 2023
65deb3b
Update docker-compose.yml
michplunkett Dec 30, 2023
f1ad1dd
Update docker-compose.yml
michplunkett Dec 30, 2023
e6aeccc
Update Makefile
michplunkett Dec 30, 2023
735da8f
Update docker-compose.yml
michplunkett Dec 30, 2023
d073535
Update Dockerfile-test
michplunkett Dec 30, 2023
13dbf11
Update Dockerfile-test
michplunkett Dec 30, 2023
2c30c68
Update Dockerfile-test
michplunkett Dec 30, 2023
34719c2
Revert "Update Dockerfile-test"
michplunkett Dec 30, 2023
38e5529
Update dev-requirements.txt
michplunkett Dec 30, 2023
4d00bd6
Update dev-requirements.txt
michplunkett Dec 30, 2023
17b1c09
Update Dockerfile-test
michplunkett Dec 30, 2023
fbca017
Update Dockerfile
michplunkett Dec 30, 2023
139c375
Update Dockerfile-test
michplunkett Dec 30, 2023
c0edc4b
Update Dockerfile
michplunkett Dec 30, 2023
551d972
Update docker-compose.yml
michplunkett Dec 30, 2023
0904a7d
Rename file
michplunkett Dec 30, 2023
12c6f08
Update docker-compose.yml
michplunkett Dec 30, 2023
2fde15b
Update docker-compose.yml
michplunkett Dec 30, 2023
7dea044
Update docker-compose.yml
michplunkett Dec 30, 2023
f5bbba5
Remove python version from dev
michplunkett Dec 30, 2023
a56bdad
Update Dockerfile-dev
michplunkett Dec 30, 2023
f82d562
Merge branch 'develop' into test_docker_file
michplunkett Dec 31, 2023
c5d175e
Update test_prs.yml
michplunkett Dec 31, 2023
910865a
Merge branch 'develop' into test_docker_file
michplunkett Jan 3, 2024
69c0074
Merge branch 'develop' into test_docker_file
michplunkett Jan 5, 2024
9b6f0bd
Merge branch 'develop' into test_docker_file
michplunkett Jan 23, 2024
061339d
Merge branch 'develop' into test_docker_file
michplunkett Feb 12, 2024
b9de4a8
Merge branch 'develop' into test_docker_file
michplunkett Feb 22, 2024
64249c6
Merge branch 'develop' into test_docker_file
michplunkett Apr 8, 2024
5b148c9
Merge branch 'develop' into test_docker_file
michplunkett Apr 17, 2024
06db655
Update Makefile
michplunkett Apr 30, 2024
fc79786
Update Makefile
michplunkett Apr 30, 2024
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
9 changes: 0 additions & 9 deletions .github/workflows/test_prs.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
name: CI

# Controls when the action will run.
on:
pull_request:
branches:
- develop
- main
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have stopped using main, so I removed it from this file.


# 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
36 changes: 23 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ export UID=$(shell id -u)

default: build start create_db populate test stop clean

# Build containers
.PHONY: build
build: ## Build containers
build:
docker-compose build

.PHONY: build_with_version
Expand All @@ -12,10 +13,11 @@ 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/

# Run containers
.PHONY: start
start: build ## Run containers
start: build
docker-compose up -d

.PHONY: create_db
Expand All @@ -35,8 +37,9 @@ assets:
.PHONY: dev
dev: create_empty_secret build start create_db populate

# Build and run containers
.PHONY: populate
populate: create_db ## Build and run containers
populate: create_db
@until docker-compose exec postgres psql -h localhost -U openoversight -c '\l' postgres &>/dev/null; do \
echo "Postgres is unavailable - sleeping..."; \
sleep 1; \
Expand All @@ -45,12 +48,13 @@ populate: create_db ## Build and run containers
## Populate database with test data
docker-compose run --rm web python ./test_data.py -p

# Run tests
.PHONY: test
test: start ## Run tests
test: start
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 All @@ -61,24 +65,29 @@ lint:
clean_assets:
rm -rf ./OpenOversight/app/static/dist/

# Stop containers
.PHONY: stop
stop: ## Stop containers
stop:
docker-compose stop

# Remove containers
.PHONY: clean
clean: clean_assets stop ## Remove containers
clean: clean_assets stop
docker-compose rm -f

# Wipe database
.PHONY: clean_all
clean_all: clean stop ## Wipe database
clean_all: clean stop
docker-compose down -v

# Build project documentation in live reload for editing
.PHONY: docs
docs: ## Build project documentation in live reload for editing
docs:
make -C docs/ clean && sphinx-autobuild docs/ docs/_build/html

# Print this message and exit
.PHONY: help
help: ## Print this message and exit
help:
@printf "OpenOversight: Makefile for development, documentation and testing.\n"
@printf "Subcommands:\n\n"
@awk 'BEGIN {FS = ":.*?## "} /^[0-9a-zA-Z_-]+:.*?## / {printf "\033[36m%s\033[0m : %s\n", $$1, $$2}' $(MAKEFILE_LIST) \
Expand All @@ -89,8 +98,9 @@ help: ## Print this message and exit
attach:
docker-compose exec postgres psql -h localhost -U openoversight openoversight-dev

# This is needed to make sure docker doesn't create an empty directory, or delete that directory first
.PHONY: create_empty_secret
create_empty_secret: ## This is needed to make sure docker doesn't create an empty directory, or delete that directory first
create_empty_secret:
touch service_account_key.json || \
(echo "Need to delete that empty directory first"; \
sudo rm -d service_account_key.json/; \
Expand Down
23 changes: 18 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,13 @@ services:
restart: always
build:
context: .
args:
- DOCKER_BUILD_ENV
- MAKE_PYTHON_VERSION
dockerfile: ./dockerfiles/web/Dockerfile
dockerfile: dockerfiles/web/Dockerfile-dev
environment:
APPROVE_REGISTRATIONS: "${APPROVE_REGISTRATIONS}"
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 +52,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
43 changes: 43 additions & 0 deletions dockerfiles/web/Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
FROM python: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 && \
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 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 /usr/src/app/
RUN pip3 install --no-cache-dir -r requirements.txt

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

COPY test_data.py /usr/src/app/

ENV SECRET_KEY 4Q6ZaQQdiqtmvZaxP1If
ENV SQLALCHEMY_DATABASE_URI postgresql://openoversight:terriblepassword@postgres/openoversight-dev

WORKDIR /usr/src/app/

CMD ["OpenOversight/scripts/entrypoint_dev.sh"]
10 changes: 1 addition & 9 deletions dockerfiles/web/Dockerfile → dockerfiles/web/Dockerfile-test
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
ARG MAKE_PYTHON_VERSION
ARG DOCKER_BUILD_ENV
FROM python:${MAKE_PYTHON_VERSION:-3.11}-bullseye

WORKDIR /usr/src/app
Expand Down Expand Up @@ -40,21 +39,14 @@ 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 test "${DOCKER_BUILD_ENV}" = production || pip3 install --no-cache-dir -r dev-requirements.txt
RUN pip3 install --no-cache-dir -r requirements.txt && 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/
EXPOSE 3000

ENV PATH="/usr/src/app/geckodriver:${PATH}"
ENV SECRET_KEY 4Q6ZaQQdiqtmvZaxP1If
ENV SQLALCHEMY_DATABASE_URI postgresql://openoversight:terriblepassword@postgres/openoversight-dev

WORKDIR /usr/src/app/

CMD ["OpenOversight/scripts/entrypoint_dev.sh"]
Loading