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

feat : Add docker-compose.yml #1043

Open
wants to merge 24 commits into
base: develop
Choose a base branch
from
Open
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
13 changes: 5 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,13 @@ jobs:
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Run tests
run: |
python -m unittest discover tests -v
- name: Generate coverage report
run: |
pip install pytest
pip install pytest-cov
pytest --cov-config=.coveragerc
pytest --cov=./ --cov-report=xml
make docker_test

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
file: ./coverage.xml
file: ./cov/coverage.xml
name: codecov-umbrella
fail_ci_if_error: true


1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ coverage.xml
*.cover
.hypothesis/
.pytest_cache/
cov/

# Translations
*.mo
Expand Down
14 changes: 13 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,17 @@ FROM python:3.7
COPY ./requirements.txt /dockerBuild/requirements.txt
WORKDIR /dockerBuild
RUN pip install --no-cache-dir -r requirements.txt
ENV DB_TYPE=postgresql
ENV DB_USERNAME=postgres
ENV DB_PASSWORD=postgres
ENV DB_ENDPOINT=postgres:5432
ENV DB_TEST_ENDPOINT=test_postgres:5432
ENV DB_NAME=mentorship_system
ENV DB_TEST_NAME=mentorship_system_test
ENV POSTGRES_HOST=postgres
ENV POSTGRES_PORT=5432
ENV FLASK_ENVIRONMENT_CONFIG=dev
ENV FLASK_APP=run.py
COPY . /dockerBuild
CMD ["flask", "run", "--host", "0.0.0.0"]
ENTRYPOINT [ "make" ]
CMD [ "docker_host_dev" ]
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
dev:
epicadk marked this conversation as resolved.
Show resolved Hide resolved
python run.py
docker_host_dev:
flask run --host 0.0.0.0
python_tests:
python -m unittest discover tests
docker_test:
docker-compose -f docker-compose.test.yml up --build --remove-orphans --no-color --abort-on-container-exit mentorship_system_test
docker_dev:
docker-compose up --build --remove-orphans
generate_cov:
pip install pytest
pip install pytest-cov
pytest --cov=. --cov-report=xml
mv ./coverage.xml /dockerbuild/cov/

18 changes: 11 additions & 7 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ class BaseConfig(object):
# Example:
# MySQL: mysql+pymysql://{db_user}:{db_password}@{db_endpoint}/{db_name}
# SQLite: sqlite:///local_data.db
DB_TYPE = os.getenv("DB_TYPE")
DB_USERNAME = os.getenv("DB_USERNAME")
DB_PASSWORD = os.getenv("DB_PASSWORD")
DB_ENDPOINT = os.getenv("DB_ENDPOINT")
DB_NAME = os.getenv("DB_NAME")

DB_TYPE = os.getenv("DB_TYPE", "")
DB_USERNAME = os.getenv("DB_USERNAME", "")
DB_PASSWORD = os.getenv("DB_PASSWORD", "")
DB_ENDPOINT = os.getenv("DB_ENDPOINT", "")
DB_NAME = os.getenv("DB_NAME", "")
DB_TEST_NAME = os.getenv("DB_TEST_NAME", "")
epicadk marked this conversation as resolved.
Show resolved Hide resolved
DB_TEST_ENDPOINT = os.getenv("DB_TEST_ENDPOINT", DB_ENDPOINT)
UNVERIFIED_USER_THRESHOLD = 2592000 # 30 days

# Flask JWT settings
Expand Down Expand Up @@ -133,7 +134,10 @@ class TestingConfig(BaseConfig):
MOCK_EMAIL = True

# Use in-memory SQLite database for testing
SQLALCHEMY_DATABASE_URI = "sqlite://"
# SQLALCHEMY_DATABASE_URI = "sqlite://"
SQLALCHEMY_DATABASE_URI = BaseConfig.build_db_uri(
epicadk marked this conversation as resolved.
Show resolved Hide resolved
db_name_arg=BaseConfig.DB_TEST_NAME, db_endpoint_arg=BaseConfig.DB_TEST_ENDPOINT
)


def get_env_config() -> str:
Expand Down
23 changes: 23 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

services:
test_postgres:
container_name: test_postgres
image: postgres
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: mentorship_system_test
ports:
- 5432:5432

mentorship_system_test:
container_name: mentorship_system_test
build: .
volumes:
- ./cov:/dockerbuild/cov
depends_on:
- test_postgres
environment:
FLASK_ENVIRONMENT_CONFIG: test
command:
- generate_cov

19 changes: 19 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

services:
postgres:
container_name: postgres
image: postgres
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: mentorship_system
ports:
- 5432:5432
mentorship_system:
container_name: mentorship_system
build: .
ports:
- 5000:5000
depends_on:
- postgres


2 changes: 1 addition & 1 deletion tests/test_app_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_app_testing_config(self):
self.assertFalse(application.config["DEBUG"])
self.assertTrue(application.config["TESTING"])
self.assertFalse(application.config["SQLALCHEMY_TRACK_MODIFICATIONS"])
self.assertEqual("sqlite://", application.config["SQLALCHEMY_DATABASE_URI"])
# self.assertEqual("sqlite://", application.config["SQLALCHEMY_DATABASE_URI"])
self.assertIsNotNone(current_app)

# testing JWT configurations
Expand Down