From cf21c549ea5e4b3f696cdbb311294bdf8e135103 Mon Sep 17 00:00:00 2001 From: epicadk Date: Wed, 10 Mar 2021 20:15:28 +0530 Subject: [PATCH 01/20] feat : Add docker-compose.yml --- Dockerfile | 14 +++++++++++++- Makefile | 14 ++++++++++++++ config.py | 18 +++++++++++------- docker-compose.test.yml | 21 +++++++++++++++++++++ docker-compose.yml | 19 +++++++++++++++++++ tests/test_app_config.py | 2 +- 6 files changed, 79 insertions(+), 9 deletions(-) create mode 100644 Makefile create mode 100644 docker-compose.test.yml create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile index 7de5c3ab5..689b0c5f8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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" ] diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..7dd88c16d --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +dev: + 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 --exit-code-from mentorship_system_test --remove-orphans +docker_dev: + docker-compose up --build --remove-orphans + + + + diff --git a/config.py b/config.py index 5d655f9de..2f7dd9fe3 100644 --- a/config.py +++ b/config.py @@ -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", "") + DB_TEST_ENDPOINT = os.getenv("DB_TEST_ENDPOINT", DB_ENDPOINT) UNVERIFIED_USER_THRESHOLD = 2592000 # 30 days # Flask JWT settings @@ -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( + db_name_arg=BaseConfig.DB_TEST_NAME, db_endpoint_arg=BaseConfig.DB_TEST_ENDPOINT + ) def get_env_config() -> str: diff --git a/docker-compose.test.yml b/docker-compose.test.yml new file mode 100644 index 000000000..4ec5a7358 --- /dev/null +++ b/docker-compose.test.yml @@ -0,0 +1,21 @@ + +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: . + depends_on: + - test_postgres + environment: + FLASK_ENVIRONMENT_CONFIG: test + command: + - python_tests + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..d8bdf24da --- /dev/null +++ b/docker-compose.yml @@ -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 + + diff --git a/tests/test_app_config.py b/tests/test_app_config.py index 6f33475d0..5aaca5631 100644 --- a/tests/test_app_config.py +++ b/tests/test_app_config.py @@ -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 From 131f010fa99d994d333dfed56da4b93102ce5d9d Mon Sep 17 00:00:00 2001 From: Aditya Kurkure <56596662+epicadk@users.noreply.github.com> Date: Wed, 17 Mar 2021 09:31:32 +0530 Subject: [PATCH 02/20] Update main.yml --- .github/workflows/main.yml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2589843ca..2e70fc2b7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,15 +18,10 @@ jobs: - uses: actions/checkout@v2 - name: Set up Python 3.6 uses: actions/setup-python@v2 - with: - python-version: 3.6 - - name: Install dependencies - run: | - python -m pip install --upgrade pip - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Run tests run: | - python -m unittest discover tests -v + make docker_test - name: Generate coverage report run: | pip install pytest From 81673753cb6c303e17be2b2f53923eb3d9c394a3 Mon Sep 17 00:00:00 2001 From: epicadk Date: Thu, 15 Apr 2021 10:36:14 +0530 Subject: [PATCH 03/20] minor fix --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 689b0c5f8..629e7a957 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,7 @@ ENV DB_PASSWORD=postgres ENV DB_ENDPOINT=postgres:5432 ENV DB_TEST_ENDPOINT=test_postgres:5432 ENV DB_NAME=mentorship_system +ENV CI = $CI ENV DB_TEST_NAME=mentorship_system_test ENV POSTGRES_HOST=postgres ENV POSTGRES_PORT=5432 From f9baf2f5d1ed5015b6b0a932d04a2411e6ffea1a Mon Sep 17 00:00:00 2001 From: Aditya Kurkure <56596662+epicadk@users.noreply.github.com> Date: Thu, 15 Apr 2021 10:52:09 +0530 Subject: [PATCH 04/20] Update main.yml --- .github/workflows/main.yml | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2e70fc2b7..4e79986e9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,20 +16,7 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Set up Python 3.6 - uses: actions/setup-python@v2 - name: Run tests run: | make docker_test - - name: Generate coverage report - run: | - pip install pytest - pip install pytest-cov - pytest --cov=./ --cov-report=xml - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v1 - with: - file: ./coverage.xml - name: codecov-umbrella - fail_ci_if_error: true From 485f86ce2911b8585a856ff0080ffa4c226eb078 Mon Sep 17 00:00:00 2001 From: epicadk Date: Thu, 15 Apr 2021 12:51:06 +0530 Subject: [PATCH 05/20] test --- Makefile | 6 ++++++ docker-compose.test.yml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 7dd88c16d..fc49c292d 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,12 @@ docker_test: docker-compose -f docker-compose.test.yml up --build --exit-code-from mentorship_system_test --remove-orphans docker_dev: docker-compose up --build --remove-orphans +generate_cov: + pip install pytest + pip install pytest-cov + pytest --cov-config=.coveragerc + pytest --cov=./ --cov-report=xml + diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 4ec5a7358..75c939572 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -17,5 +17,5 @@ services: environment: FLASK_ENVIRONMENT_CONFIG: test command: - - python_tests + - generate_cov From 3c40acd3e5a73b1fea0a7e1556b87e94a2cac399 Mon Sep 17 00:00:00 2001 From: epicadk Date: Thu, 15 Apr 2021 12:51:45 +0530 Subject: [PATCH 06/20] test --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 629e7a957..43232f584 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ ENV DB_PASSWORD=postgres ENV DB_ENDPOINT=postgres:5432 ENV DB_TEST_ENDPOINT=test_postgres:5432 ENV DB_NAME=mentorship_system -ENV CI = $CI +ENV CI=true ENV DB_TEST_NAME=mentorship_system_test ENV POSTGRES_HOST=postgres ENV POSTGRES_PORT=5432 From 4da00682a7a08718cb3107592a3543e91413d63a Mon Sep 17 00:00:00 2001 From: epicadk Date: Thu, 15 Apr 2021 13:15:59 +0530 Subject: [PATCH 07/20] test --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index fc49c292d..109b6521f 100644 --- a/Makefile +++ b/Makefile @@ -9,10 +9,10 @@ docker_test: docker_dev: docker-compose up --build --remove-orphans generate_cov: - pip install pytest + pip install pytest pip install pytest-cov pytest --cov-config=.coveragerc - pytest --cov=./ --cov-report=xml + pytest --cov=./ --cov-report=xml From b663eeba802830b4d66d2dadd9ec269e9f8e3245 Mon Sep 17 00:00:00 2001 From: epicadk Date: Thu, 15 Apr 2021 13:28:37 +0530 Subject: [PATCH 08/20] test --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 109b6521f..90ddd7098 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,8 @@ generate_cov: pip install pytest pip install pytest-cov pytest --cov-config=.coveragerc - pytest --cov=./ --cov-report=xml + pytest --cov=./ --cov-report=xml + bash < (curl -s https://codecov.io/bash) From a9bd9561b98859438ef54b43261df53422c77021 Mon Sep 17 00:00:00 2001 From: epicadk Date: Thu, 15 Apr 2021 14:17:21 +0530 Subject: [PATCH 09/20] test --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 90ddd7098..ed7f318b0 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ docker_host_dev: python_tests: python -m unittest discover tests docker_test: - docker-compose -f docker-compose.test.yml up --build --exit-code-from mentorship_system_test --remove-orphans + docker-compose -f docker-compose.test.yml up --build --remove-orphans docker_dev: docker-compose up --build --remove-orphans generate_cov: From 0cd24e47691fb0b0880eb9e2593b59d9d67c275b Mon Sep 17 00:00:00 2001 From: epicadk Date: Thu, 15 Apr 2021 14:33:07 +0530 Subject: [PATCH 10/20] test --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index ed7f318b0..0a6f7a116 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ docker_host_dev: python_tests: python -m unittest discover tests docker_test: - docker-compose -f docker-compose.test.yml up --build --remove-orphans + docker-compose -f docker-compose.test.yml run --build --remove-orphans docker_dev: docker-compose up --build --remove-orphans generate_cov: @@ -13,7 +13,7 @@ generate_cov: pip install pytest-cov pytest --cov-config=.coveragerc pytest --cov=./ --cov-report=xml - bash < (curl -s https://codecov.io/bash) + bash < curl -s https://codecov.io/bash From 8f71e4fcbc21776a380bbdd6b5159bfe46df1c3c Mon Sep 17 00:00:00 2001 From: epicadk Date: Thu, 15 Apr 2021 14:39:50 +0530 Subject: [PATCH 11/20] Update main.yml --- .github/workflows/main.yml | 1 + Makefile | 5 +++-- docker-compose.test.yml | 5 ++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index baf863e0f..d52c0bd94 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -26,4 +26,5 @@ jobs: - name: Run tests run: | make docker_test + diff --git a/Makefile b/Makefile index 0a6f7a116..00b661ca2 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ docker_host_dev: python_tests: python -m unittest discover tests docker_test: - docker-compose -f docker-compose.test.yml run --build --remove-orphans + docker-compose -f docker-compose.test.yml up --build --remove-orphans --abort-on-container-exit mentorship_system_test docker_dev: docker-compose up --build --remove-orphans generate_cov: @@ -13,7 +13,8 @@ generate_cov: pip install pytest-cov pytest --cov-config=.coveragerc pytest --cov=./ --cov-report=xml - bash < curl -s https://codecov.io/bash + apt install curl + curl -s https://codecov.io/bash diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 75c939572..9ddc13b39 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -11,11 +11,10 @@ services: mentorship_system_test: container_name: mentorship_system_test - build: . + build: . depends_on: - test_postgres environment: FLASK_ENVIRONMENT_CONFIG: test command: - - generate_cov - + - generate_cov \ No newline at end of file From 9df5829417dc4efec16634260805530f0e1165a6 Mon Sep 17 00:00:00 2001 From: epicadk Date: Thu, 15 Apr 2021 17:32:55 +0530 Subject: [PATCH 12/20] pipe --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 00b661ca2..4cf144565 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ generate_cov: pytest --cov-config=.coveragerc pytest --cov=./ --cov-report=xml apt install curl - curl -s https://codecov.io/bash + bash | curl -s https://codecov.io/bash From 4732e6f92866340b23b25b71ebf11c0f19b3de56 Mon Sep 17 00:00:00 2001 From: epicadk Date: Thu, 15 Apr 2021 18:47:57 +0530 Subject: [PATCH 13/20] volume --- Makefile | 5 ++--- docker-compose.test.yml | 4 +++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 4cf144565..62a9e9fdc 100644 --- a/Makefile +++ b/Makefile @@ -12,9 +12,8 @@ generate_cov: pip install pytest pip install pytest-cov pytest --cov-config=.coveragerc - pytest --cov=./ --cov-report=xml - apt install curl - bash | curl -s https://codecov.io/bash + pytest --cov=. --cov-report=xml + mv ./coverage.xml /dockerbuild/cov/ diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 9ddc13b39..15216c64c 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -11,7 +11,9 @@ services: mentorship_system_test: container_name: mentorship_system_test - build: . + build: . + volumes: + - ./cov:/dockerbuild/cov depends_on: - test_postgres environment: From fcc4ae1f5a881ddfe0fcb3e7efb2044ae9181bca Mon Sep 17 00:00:00 2001 From: Aditya Kurkure <56596662+epicadk@users.noreply.github.com> Date: Thu, 15 Apr 2021 18:48:44 +0530 Subject: [PATCH 14/20] Update main.yml --- .github/workflows/main.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d52c0bd94..2a4b05b1a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -26,5 +26,12 @@ jobs: - name: Run tests run: | make docker_test + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v1 + with: + file: ./coverage.xml + name: codecov-umbrella + fail_ci_if_error: true From 37c16279199f4067376a6b5722f05086248b3084 Mon Sep 17 00:00:00 2001 From: Aditya Kurkure <56596662+epicadk@users.noreply.github.com> Date: Thu, 15 Apr 2021 18:55:51 +0530 Subject: [PATCH 15/20] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2a4b05b1a..ee2064b7c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -30,7 +30,7 @@ jobs: - 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 From df3ee417b7b9ae587a56461b5cde20657277bedf Mon Sep 17 00:00:00 2001 From: epicadk Date: Thu, 15 Apr 2021 19:13:55 +0530 Subject: [PATCH 16/20] improve performance --- .gitignore | 1 + Makefile | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9056251db..cd8c54486 100644 --- a/.gitignore +++ b/.gitignore @@ -46,6 +46,7 @@ coverage.xml *.cover .hypothesis/ .pytest_cache/ +cov/ # Translations *.mo diff --git a/Makefile b/Makefile index 62a9e9fdc..ea0d33b73 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ docker_host_dev: python_tests: python -m unittest discover tests docker_test: - docker-compose -f docker-compose.test.yml up --build --remove-orphans --abort-on-container-exit mentorship_system_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: From 1741ac15012a0d54c5a04e68380ac571b9591305 Mon Sep 17 00:00:00 2001 From: Aditya Kurkure <56596662+epicadk@users.noreply.github.com> Date: Fri, 16 Apr 2021 09:22:58 +0530 Subject: [PATCH 17/20] Update Makefile --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index ea0d33b73..1d6d0c8f0 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,6 @@ docker_dev: generate_cov: pip install pytest pip install pytest-cov - pytest --cov-config=.coveragerc pytest --cov=. --cov-report=xml mv ./coverage.xml /dockerbuild/cov/ From c4bc4475c704f939e642daf904efe506b41ee930 Mon Sep 17 00:00:00 2001 From: Aditya Kurkure <56596662+epicadk@users.noreply.github.com> Date: Thu, 6 May 2021 01:13:44 +0530 Subject: [PATCH 18/20] Update Dockerfile --- Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 43232f584..689b0c5f8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,6 @@ ENV DB_PASSWORD=postgres ENV DB_ENDPOINT=postgres:5432 ENV DB_TEST_ENDPOINT=test_postgres:5432 ENV DB_NAME=mentorship_system -ENV CI=true ENV DB_TEST_NAME=mentorship_system_test ENV POSTGRES_HOST=postgres ENV POSTGRES_PORT=5432 From ada126cc11d50da9bd79ac98791369166eb7fc1b Mon Sep 17 00:00:00 2001 From: Aditya Kurkure <56596662+epicadk@users.noreply.github.com> Date: Thu, 6 May 2021 01:14:05 +0530 Subject: [PATCH 19/20] Update docker-compose.test.yml --- docker-compose.test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 15216c64c..ba4790bca 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -19,4 +19,5 @@ services: environment: FLASK_ENVIRONMENT_CONFIG: test command: - - generate_cov \ No newline at end of file + - generate_cov + From de1f024dca65abf565f8f16640cf656b723aac28 Mon Sep 17 00:00:00 2001 From: Aditya Kurkure <56596662+epicadk@users.noreply.github.com> Date: Thu, 6 May 2021 01:14:29 +0530 Subject: [PATCH 20/20] Update Makefile --- Makefile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Makefile b/Makefile index 1d6d0c8f0..2489f6460 100644 --- a/Makefile +++ b/Makefile @@ -13,8 +13,4 @@ generate_cov: pip install pytest-cov pytest --cov=. --cov-report=xml mv ./coverage.xml /dockerbuild/cov/ - - - -