From 5315ce1d714d52787826e237a239d23707420ad8 Mon Sep 17 00:00:00 2001 From: Shanshan Wu <790219068@qq.com> Date: Tue, 19 Nov 2024 16:35:53 -0800 Subject: [PATCH 01/34] add docker file --- Dockerfile | 28 ++++++++++++++++++++++++++++ README.md | 15 +++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..5735dc91 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +# Use Python 3.11 slim image as base +FROM python:3.11-slim + +# Set working directory +WORKDIR /app + +# Install system dependencies required for psycopg2 and other packages +RUN apt-get update && apt-get install -y \ + gcc \ + python3-dev \ + libpq-dev \ + && rm -rf /var/lib/apt/lists/* + +# Copy requirements file +COPY requirements.txt . + +# Install Python dependencies +RUN pip install --no-cache-dir -r requirements.txt + +# Copy project files +COPY . . + +# Expose port for FastAPI +EXPOSE 8000 + +# Command to run the application +# Updated to use the correct module path +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] \ No newline at end of file diff --git a/README.md b/README.md index 0a48dc37..bf593ea0 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,18 @@ This will contain the model used for the project that based on the input informa The model works off of dummy data of several combinations of clients alongside the interventions chosen for them as well as their success rate at finding a job afterward. The model will be updated by the case workers by inputing new data for clients with their updated outcome information, and it can be updated on a daily, weekly, or monthly basis. This also has an API file to interact with the front end, and logic in order to process the interventions coming from the front end. This includes functions to clean data, create a matrix of all possible combinations in order to get the ones with the highest increase of success, and output the results in a way the front end can interact with. + +### Build Instructions +1. Clone the repository: + +`git clone https://github.com/MochitheCoderCat/CommonAssessmentTool.git` + +2. Navigate to the backend directory: + +`cd app` + +3. Build and run the Docker container: + +`docker build -t common-assessment-tool .` + +`docker run -p 8000:8000 common-assessment-tool` \ No newline at end of file From 531160d13976e4e83991bae447f23f4dd0ce9da1 Mon Sep 17 00:00:00 2001 From: EffieYang <122754256+EffieYang@users.noreply.github.com> Date: Tue, 19 Nov 2024 17:45:52 -0800 Subject: [PATCH 02/34] Create ci.yml --- .github/workflows/ci.yml | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..1b8853f1 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,52 @@ +name: CI Pipeline + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + + steps: + # Checkout the repository + - name: Checkout repository + uses: actions/checkout@v3 + + # Setup Python environment + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: 3.11 + + # Install dependencies + - name: Install dependencies + run: | + python -m pip install --upgrade pip + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + + # Run tests + - name: Run tests + run: | + pytest # Replace with your preferred test command if different + + # Build Docker image + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} # Set in GitHub Secrets + password: ${{ secrets.DOCKER_PASSWORD }} # Set in GitHub Secrets + + - name: Build Docker image + run: | + docker build -t my-image-name:${{ github.sha }} . + + # Push Docker image + - name: Push Docker image + run: | + docker tag my-image-name:${{ github.sha }} my-dockerhub-username/my-image-name:${{ github.sha }} + docker push my-dockerhub-username/my-image-name:${{ github.sha }} From e87ec20e3f2427db153fa3aec86abf0af7e20aa3 Mon Sep 17 00:00:00 2001 From: Shan533 <96012342+Shan533@users.noreply.github.com> Date: Tue, 19 Nov 2024 17:52:20 -0800 Subject: [PATCH 03/34] Update docker image --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b8853f1..607fcba6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,7 +32,7 @@ jobs: # Run tests - name: Run tests run: | - pytest # Replace with your preferred test command if different + pytest # Build Docker image - name: Log in to Docker Hub @@ -43,10 +43,10 @@ jobs: - name: Build Docker image run: | - docker build -t my-image-name:${{ github.sha }} . + docker build -t shan533/common-assessment-tool:${{ github.sha }} . # Push Docker image - name: Push Docker image run: | - docker tag my-image-name:${{ github.sha }} my-dockerhub-username/my-image-name:${{ github.sha }} - docker push my-dockerhub-username/my-image-name:${{ github.sha }} + docker tag common-assessment-tool:${{ github.sha }} shan533/common-assessment-tool:${{ github.sha }} + docker push shan533/common-assessment-tool:${{ github.sha }} From ae9e3589780ea0a625cb74159bab3992b24311d1 Mon Sep 17 00:00:00 2001 From: Shan533 <96012342+Shan533@users.noreply.github.com> Date: Tue, 19 Nov 2024 18:13:05 -0800 Subject: [PATCH 04/34] Update ci.yml --- .github/workflows/ci.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 607fcba6..9b709377 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,11 +29,6 @@ jobs: python -m pip install --upgrade pip if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - # Run tests - - name: Run tests - run: | - pytest - # Build Docker image - name: Log in to Docker Hub uses: docker/login-action@v2 From 97be773fa8ea52388dc257304a012dea9b00175c Mon Sep 17 00:00:00 2001 From: Shanshan Wu <790219068@qq.com> Date: Tue, 19 Nov 2024 18:48:35 -0800 Subject: [PATCH 05/34] update ci file --- .github/workflows/ci.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9b709377..2c07a904 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,11 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + pip install -r requirements.txt + + # Run tests + - name: Run tests + run: pytest # Build Docker image - name: Log in to Docker Hub From e45e880cf66fa561cb585c4e3229ceab7a99e103 Mon Sep 17 00:00:00 2001 From: Shanshan Wu <790219068@qq.com> Date: Tue, 19 Nov 2024 18:48:49 -0800 Subject: [PATCH 06/34] update tests --- tests/test.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/tests/test.py b/tests/test.py index a911f0a2..fe114697 100644 --- a/tests/test.py +++ b/tests/test.py @@ -1,4 +1,11 @@ -from logic import interpret_and_calculate +import sys +import os +import pytest + +# Add the project root directory to the Python path +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../'))) + +from app.clients.service.logic import interpret_and_calculate from itertools import combinations_with_replacement # def test_interpret_and_calculate(): @@ -20,4 +27,43 @@ result = list(combinations_with_replacement([0, 1], 2)) # Output: [(0, 0), (0, 1), (1, 1)] -print(result) \ No newline at end of file +print(result) + +# Sample test data +data = { + "age": "23", + "gender": "1", + "work_experience": "1", + "canada_workex": "1", + "dep_num": "0", + "canada_born": "1", + "citizen_status": "2", + "level_of_schooling": "2", + "fluent_english": "3", + "reading_english_scale": "2", + "speaking_english_scale": "2", + "writing_english_scale": "3", + "numeracy_scale": "2", + "computer_scale": "3", + "transportation_bool": "2", + "caregiver_bool": "1", + "housing": "1", + "income_source": "5", + "felony_bool": "1", + "attending_school": "0", + "currently_employed": "1", + "substance_use": "1", + "time_unemployed": "1", + "need_mental_health_support_bool": "1" +} + +def test_interpret_and_calculate(): + # Call the function with the sample data + results = interpret_and_calculate(data) + + assert isinstance(results, dict) + assert "baseline" in results + assert "interventions" in results + +if __name__ == "__main__": + pytest.main() \ No newline at end of file From 81283a1032123c12d3e3a2c53ca2a23ed89b9c80 Mon Sep 17 00:00:00 2001 From: Shanshan Wu <790219068@qq.com> Date: Tue, 19 Nov 2024 18:52:58 -0800 Subject: [PATCH 07/34] update ci file --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2c07a904..221fc856 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,8 @@ jobs: # Run tests - name: Run tests - run: pytest + run: | + pytest tests/ --maxfail=1 --disable-warnings -q # Build Docker image - name: Log in to Docker Hub From bd40a1fa2569295897d358c791e4e9d31a3d0d83 Mon Sep 17 00:00:00 2001 From: Shanshan Wu <790219068@qq.com> Date: Tue, 19 Nov 2024 19:03:03 -0800 Subject: [PATCH 08/34] update pytest --- tests/{test.py => test_example.py} | 3 --- 1 file changed, 3 deletions(-) rename tests/{test.py => test_example.py} (97%) diff --git a/tests/test.py b/tests/test_example.py similarity index 97% rename from tests/test.py rename to tests/test_example.py index fe114697..c4d1c95f 100644 --- a/tests/test.py +++ b/tests/test_example.py @@ -64,6 +64,3 @@ def test_interpret_and_calculate(): assert isinstance(results, dict) assert "baseline" in results assert "interventions" in results - -if __name__ == "__main__": - pytest.main() \ No newline at end of file From a629fe0091929af7b4704876d8eee0ea5ebb0e67 Mon Sep 17 00:00:00 2001 From: Amber Qianyun Wang <88248072+MochitheCoderCat@users.noreply.github.com> Date: Tue, 19 Nov 2024 19:21:11 -0800 Subject: [PATCH 09/34] Update ci.yml --- .github/workflows/ci.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 221fc856..590ad4d0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,7 +43,12 @@ jobs: - name: Build Docker image run: | - docker build -t shan533/common-assessment-tool:${{ github.sha }} . + docker build -t common-assessment-tool:${{ github.sha }} . + + # List Docker images + - name: List Docker images + run: | + docker images # Push Docker image - name: Push Docker image From 3f7e971171fa55a53fbfe4f502a211d89b538ae8 Mon Sep 17 00:00:00 2001 From: Shanshan Wu <790219068@qq.com> Date: Tue, 19 Nov 2024 19:45:57 -0800 Subject: [PATCH 10/34] add linter --- .github/workflows/ci.yml | 9 +++++++-- app/requirements.txt | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 590ad4d0..dd09efe3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,6 +29,11 @@ jobs: python -m pip install --upgrade pip pip install -r requirements.txt + # Run linter + - name: Run linter + run: | + pylint ./app + # Run tests - name: Run tests run: | @@ -38,8 +43,8 @@ jobs: - name: Log in to Docker Hub uses: docker/login-action@v2 with: - username: ${{ secrets.DOCKER_USERNAME }} # Set in GitHub Secrets - password: ${{ secrets.DOCKER_PASSWORD }} # Set in GitHub Secrets + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} - name: Build Docker image run: | diff --git a/app/requirements.txt b/app/requirements.txt index 57fc8e6e..319d8f26 100644 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -21,6 +21,7 @@ pandas==2.2.2 pydantic==2.8.2 pydantic_core==2.20.1 Pygments==2.18.0 +pylint==3.0.1 python-dateutil==2.9.0.post0 python-dotenv==1.0.1 python-multipart==0.0.9 From e298d62292fe23b76f08ce6d067a8fd4f4ab1dee Mon Sep 17 00:00:00 2001 From: Shan533 <96012342+Shan533@users.noreply.github.com> Date: Tue, 19 Nov 2024 19:49:10 -0800 Subject: [PATCH 11/34] Update ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dd09efe3..4da54eae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,7 +32,7 @@ jobs: # Run linter - name: Run linter run: | - pylint ./app + pylint ./app || true # Run tests - name: Run tests From ac68a057edbbf98404ed1cd924e3e51fe5194be9 Mon Sep 17 00:00:00 2001 From: Shan533 <96012342+Shan533@users.noreply.github.com> Date: Tue, 19 Nov 2024 19:52:55 -0800 Subject: [PATCH 12/34] Update ci.yml --- .github/workflows/ci.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4da54eae..5aa73731 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,11 +49,6 @@ jobs: - name: Build Docker image run: | docker build -t common-assessment-tool:${{ github.sha }} . - - # List Docker images - - name: List Docker images - run: | - docker images # Push Docker image - name: Push Docker image From d76817aeeb4ef164d2a93da768d5febfbd8f1cd2 Mon Sep 17 00:00:00 2001 From: kehanxiao Date: Tue, 19 Nov 2024 21:08:51 -0800 Subject: [PATCH 13/34] update CI and add pylintrc --- .github/workflows/ci.yml | 2 +- .pylintrc | 634 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 635 insertions(+), 1 deletion(-) create mode 100644 .pylintrc diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5aa73731..7731e97e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,7 +32,7 @@ jobs: # Run linter - name: Run linter run: | - pylint ./app || true + pylint ./app # Run tests - name: Run tests diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 00000000..53c05ad2 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,634 @@ +[MAIN] + +# Analyse import fallback blocks. This can be used to support both Python 2 and +# 3 compatible code, which means that the block might have code that exists +# only in one or another interpreter, leading to false positives when analysed. +analyse-fallback-blocks=no + +# Clear in-memory caches upon conclusion of linting. Useful if running pylint +# in a server-like mode. +clear-cache-post-run=no + +# Load and enable all available extensions. Use --list-extensions to see a list +# all available extensions. +#enable-all-extensions= + +# In error mode, messages with a category besides ERROR or FATAL are +# suppressed, and no reports are done by default. Error mode is compatible with +# disabling specific errors. +#errors-only= + +# Always return a 0 (non-error) status code, even if lint errors are found. +# This is primarily useful in continuous integration scripts. +#exit-zero= + +# A comma-separated list of package or module names from where C extensions may +# be loaded. Extensions are loading into the active Python interpreter and may +# run arbitrary code. +extension-pkg-allow-list= + +# A comma-separated list of package or module names from where C extensions may +# be loaded. Extensions are loading into the active Python interpreter and may +# run arbitrary code. (This is an alternative name to extension-pkg-allow-list +# for backward compatibility.) +extension-pkg-whitelist= + +# Return non-zero exit code if any of these messages/categories are detected, +# even if score is above --fail-under value. Syntax same as enable. Messages +# specified are enabled, while categories only check already-enabled messages. +fail-on= + +# Specify a score threshold under which the program will exit with error. +fail-under=5.5 + +# Interpret the stdin as a python script, whose filename needs to be passed as +# the module_or_package argument. +#from-stdin= + +# Files or directories to be skipped. They should be base names, not paths. +ignore=CVS + +# Add files or directories matching the regular expressions patterns to the +# ignore-list. The regex matches against paths and can be in Posix or Windows +# format. Because '\\' represents the directory delimiter on Windows systems, +# it can't be used as an escape character. +ignore-paths= + +# Files or directories matching the regular expression patterns are skipped. +# The regex matches against base names, not paths. The default value ignores +# Emacs file locks +ignore-patterns=^\.# + +# List of module names for which member attributes should not be checked +# (useful for modules/projects where namespaces are manipulated during runtime +# and thus existing member attributes cannot be deduced by static analysis). It +# supports qualified module names, as well as Unix pattern matching. +ignored-modules= + +# Python code to execute, usually for sys.path manipulation such as +# pygtk.require(). +#init-hook= + +# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the +# number of processors available to use, and will cap the count on Windows to +# avoid hangs. +jobs=1 + +# Control the amount of potential inferred values when inferring a single +# object. This can help the performance when dealing with large functions or +# complex, nested conditions. +limit-inference-results=100 + +# List of plugins (as comma separated values of python module names) to load, +# usually to register additional checkers. +load-plugins= + +# Pickle collected data for later comparisons. +persistent=yes + +# Minimum Python version to use for version dependent checks. Will default to +# the version used to run pylint. +py-version=3.11 + +# Discover python modules and packages in the file system subtree. +recursive=no + +# Add paths to the list of the source roots. Supports globbing patterns. The +# source root is an absolute path or a path relative to the current working +# directory used to determine a package namespace for modules located under the +# source root. +source-roots= + +# When enabled, pylint would attempt to guess common misconfiguration and emit +# user-friendly hints instead of false-positive error messages. +suggestion-mode=yes + +# Allow loading of arbitrary C extensions. Extensions are imported into the +# active Python interpreter and may run arbitrary code. +unsafe-load-any-extension=no + +# In verbose mode, extra non-checker-related info will be displayed. +#verbose= + + +[BASIC] + +# Naming style matching correct argument names. +argument-naming-style=snake_case + +# Regular expression matching correct argument names. Overrides argument- +# naming-style. If left empty, argument names will be checked with the set +# naming style. +#argument-rgx= + +# Naming style matching correct attribute names. +attr-naming-style=snake_case + +# Regular expression matching correct attribute names. Overrides attr-naming- +# style. If left empty, attribute names will be checked with the set naming +# style. +#attr-rgx= + +# Bad variable names which should always be refused, separated by a comma. +bad-names=foo, + bar, + baz, + toto, + tutu, + tata + +# Bad variable names regexes, separated by a comma. If names match any regex, +# they will always be refused +bad-names-rgxs= + +# Naming style matching correct class attribute names. +class-attribute-naming-style=any + +# Regular expression matching correct class attribute names. Overrides class- +# attribute-naming-style. If left empty, class attribute names will be checked +# with the set naming style. +#class-attribute-rgx= + +# Naming style matching correct class constant names. +class-const-naming-style=UPPER_CASE + +# Regular expression matching correct class constant names. Overrides class- +# const-naming-style. If left empty, class constant names will be checked with +# the set naming style. +#class-const-rgx= + +# Naming style matching correct class names. +class-naming-style=PascalCase + +# Regular expression matching correct class names. Overrides class-naming- +# style. If left empty, class names will be checked with the set naming style. +#class-rgx= + +# Naming style matching correct constant names. +const-naming-style=UPPER_CASE + +# Regular expression matching correct constant names. Overrides const-naming- +# style. If left empty, constant names will be checked with the set naming +# style. +#const-rgx= + +# Minimum line length for functions/classes that require docstrings, shorter +# ones are exempt. +docstring-min-length=-1 + +# Naming style matching correct function names. +function-naming-style=snake_case + +# Regular expression matching correct function names. Overrides function- +# naming-style. If left empty, function names will be checked with the set +# naming style. +#function-rgx= + +# Good variable names which should always be accepted, separated by a comma. +good-names=i, + j, + k, + ex, + Run, + _ + +# Good variable names regexes, separated by a comma. If names match any regex, +# they will always be accepted +good-names-rgxs= + +# Include a hint for the correct naming format with invalid-name. +include-naming-hint=no + +# Naming style matching correct inline iteration names. +inlinevar-naming-style=any + +# Regular expression matching correct inline iteration names. Overrides +# inlinevar-naming-style. If left empty, inline iteration names will be checked +# with the set naming style. +#inlinevar-rgx= + +# Naming style matching correct method names. +method-naming-style=snake_case + +# Regular expression matching correct method names. Overrides method-naming- +# style. If left empty, method names will be checked with the set naming style. +#method-rgx= + +# Naming style matching correct module names. +module-naming-style=snake_case + +# Regular expression matching correct module names. Overrides module-naming- +# style. If left empty, module names will be checked with the set naming style. +#module-rgx= + +# Colon-delimited sets of names that determine each other's naming style when +# the name regexes allow several styles. +name-group= + +# Regular expression which should only match function or class names that do +# not require a docstring. +no-docstring-rgx=^_ + +# List of decorators that produce properties, such as abc.abstractproperty. Add +# to this list to register other decorators that produce valid properties. +# These decorators are taken in consideration only for invalid-name. +property-classes=abc.abstractproperty + +# Regular expression matching correct type alias names. If left empty, type +# alias names will be checked with the set naming style. +#typealias-rgx= + +# Regular expression matching correct type variable names. If left empty, type +# variable names will be checked with the set naming style. +#typevar-rgx= + +# Naming style matching correct variable names. +variable-naming-style=snake_case + +# Regular expression matching correct variable names. Overrides variable- +# naming-style. If left empty, variable names will be checked with the set +# naming style. +#variable-rgx= + + +[CLASSES] + +# Warn about protected attribute access inside special methods +check-protected-access-in-special-methods=no + +# List of method names used to declare (i.e. assign) instance attributes. +defining-attr-methods=__init__, + __new__, + setUp, + asyncSetUp, + __post_init__ + +# List of member names, which should be excluded from the protected access +# warning. +exclude-protected=_asdict,_fields,_replace,_source,_make,os._exit + +# List of valid names for the first argument in a class method. +valid-classmethod-first-arg=cls + +# List of valid names for the first argument in a metaclass class method. +valid-metaclass-classmethod-first-arg=mcs + + +[DESIGN] + +# List of regular expressions of class ancestor names to ignore when counting +# public methods (see R0903) +exclude-too-few-public-methods= + +# List of qualified class names to ignore when counting class parents (see +# R0901) +ignored-parents= + +# Maximum number of arguments for function / method. +max-args=5 + +# Maximum number of attributes for a class (see R0902). +max-attributes=7 + +# Maximum number of boolean expressions in an if statement (see R0916). +max-bool-expr=5 + +# Maximum number of branch for function / method body. +max-branches=12 + +# Maximum number of locals for function / method body. +max-locals=15 + +# Maximum number of parents for a class (see R0901). +max-parents=7 + +# Maximum number of public methods for a class (see R0904). +max-public-methods=20 + +# Maximum number of return / yield for function / method body. +max-returns=6 + +# Maximum number of statements in function / method body. +max-statements=50 + +# Minimum number of public methods for a class (see R0903). +min-public-methods=2 + + +[EXCEPTIONS] + +# Exceptions that will emit a warning when caught. +overgeneral-exceptions=builtins.BaseException,builtins.Exception + + +[FORMAT] + +# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. +expected-line-ending-format= + +# Regexp for a line that is allowed to be longer than the limit. +ignore-long-lines=^\s*(# )??$ + +# Number of spaces of indent required inside a hanging or continued line. +indent-after-paren=4 + +# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 +# tab). +indent-string=' ' + +# Maximum number of characters on a single line. +max-line-length=100 + +# Maximum number of lines in a module. +max-module-lines=1000 + +# Allow the body of a class to be on the same line as the declaration if body +# contains single statement. +single-line-class-stmt=no + +# Allow the body of an if to be on the same line as the test if there is no +# else. +single-line-if-stmt=no + + +[IMPORTS] + +# List of modules that can be imported at any level, not just the top level +# one. +allow-any-import-level= + +# Allow explicit reexports by alias from a package __init__. +allow-reexport-from-package=no + +# Allow wildcard imports from modules that define __all__. +allow-wildcard-with-all=no + +# Deprecated modules which should not be used, separated by a comma. +deprecated-modules= + +# Output a graph (.gv or any supported image format) of external dependencies +# to the given file (report RP0402 must not be disabled). +ext-import-graph= + +# Output a graph (.gv or any supported image format) of all (i.e. internal and +# external) dependencies to the given file (report RP0402 must not be +# disabled). +import-graph= + +# Output a graph (.gv or any supported image format) of internal dependencies +# to the given file (report RP0402 must not be disabled). +int-import-graph= + +# Force import order to recognize a module as part of the standard +# compatibility libraries. +known-standard-library= + +# Force import order to recognize a module as part of a third party library. +known-third-party=enchant + +# Couples of modules and preferred modules, separated by a comma. +preferred-modules= + + +[LOGGING] + +# The type of string formatting that logging methods do. `old` means using % +# formatting, `new` is for `{}` formatting. +logging-format-style=old + +# Logging modules to check that the string format arguments are in logging +# function parameter format. +logging-modules=logging + + +[MESSAGES CONTROL] + +# Only show warnings with the listed confidence levels. Leave empty to show +# all. Valid levels: HIGH, CONTROL_FLOW, INFERENCE, INFERENCE_FAILURE, +# UNDEFINED. +confidence=HIGH, + CONTROL_FLOW, + INFERENCE, + INFERENCE_FAILURE, + UNDEFINED + +# Disable the message, report, category or checker with the given id(s). You +# can either give multiple identifiers separated by comma (,) or put this +# option multiple times (only on the command line, not in the configuration +# file where it should appear only once). You can also use "--disable=all" to +# disable everything first and then re-enable specific checks. For example, if +# you want to run only the similarities checker, you can use "--disable=all +# --enable=similarities". If you want to run only the classes checker, but have +# no Warning level messages displayed, use "--disable=all --enable=classes +# --disable=W". +disable=raw-checker-failed, + bad-inline-option, + locally-disabled, + file-ignored, + suppressed-message, + useless-suppression, + deprecated-pragma, + use-symbolic-message-instead, + use-implicit-booleaness-not-comparison-to-string, + use-implicit-booleaness-not-comparison-to-zero + +# Enable the message, report, category or checker with the given id(s). You can +# either give multiple identifier separated by comma (,) or put this option +# multiple time (only on the command line, not in the configuration file where +# it should appear only once). See also the "--disable" option for examples. +enable= + + +[METHOD_ARGS] + +# List of qualified names (i.e., library.method) which require a timeout +# parameter e.g. 'requests.api.get,requests.api.post' +timeout-methods=requests.api.delete,requests.api.get,requests.api.head,requests.api.options,requests.api.patch,requests.api.post,requests.api.put,requests.api.request + + +[MISCELLANEOUS] + +# List of note tags to take in consideration, separated by a comma. +notes=FIXME, + XXX, + TODO + +# Regular expression of note tags to take in consideration. +notes-rgx= + + +[REFACTORING] + +# Maximum number of nested blocks for function / method body +max-nested-blocks=5 + +# Complete name of functions that never returns. When checking for +# inconsistent-return-statements if a never returning function is called then +# it will be considered as an explicit return statement and no message will be +# printed. +never-returning-functions=sys.exit,argparse.parse_error + + +[REPORTS] + +# Python expression which should return a score less than or equal to 10. You +# have access to the variables 'fatal', 'error', 'warning', 'refactor', +# 'convention', and 'info' which contain the number of messages in each +# category, as well as 'statement' which is the total number of statements +# analyzed. This score is used by the global evaluation report (RP0004). +evaluation=max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)) + +# Template used to display messages. This is a python new-style format string +# used to format the message information. See doc for all details. +msg-template= + +# Set the output format. Available formats are: text, parseable, colorized, +# json2 (improved json format), json (old json format) and msvs (visual +# studio). You can also give a reporter class, e.g. +# mypackage.mymodule.MyReporterClass. +#output-format= + +# Tells whether to display a full report or only the messages. +reports=no + +# Activate the evaluation score. +score=yes + + +[SIMILARITIES] + +# Comments are removed from the similarity computation +ignore-comments=yes + +# Docstrings are removed from the similarity computation +ignore-docstrings=yes + +# Imports are removed from the similarity computation +ignore-imports=yes + +# Signatures are removed from the similarity computation +ignore-signatures=yes + +# Minimum lines number of a similarity. +min-similarity-lines=4 + + +[SPELLING] + +# Limits count of emitted suggestions for spelling mistakes. +max-spelling-suggestions=4 + +# Spelling dictionary name. No available dictionaries : You need to install +# both the python package and the system dependency for enchant to work. +spelling-dict= + +# List of comma separated words that should be considered directives if they +# appear at the beginning of a comment and should not be checked. +spelling-ignore-comment-directives=fmt: on,fmt: off,noqa:,noqa,nosec,isort:skip,mypy: + +# List of comma separated words that should not be checked. +spelling-ignore-words= + +# A path to a file that contains the private dictionary; one word per line. +spelling-private-dict-file= + +# Tells whether to store unknown words to the private dictionary (see the +# --spelling-private-dict-file option) instead of raising a message. +spelling-store-unknown-words=no + + +[STRING] + +# This flag controls whether inconsistent-quotes generates a warning when the +# character used as a quote delimiter is used inconsistently within a module. +check-quote-consistency=no + +# This flag controls whether the implicit-str-concat should generate a warning +# on implicit string concatenation in sequences defined over several lines. +check-str-concat-over-line-jumps=no + + +[TYPECHECK] + +# List of decorators that produce context managers, such as +# contextlib.contextmanager. Add to this list to register other decorators that +# produce valid context managers. +contextmanager-decorators=contextlib.contextmanager + +# List of members which are set dynamically and missed by pylint inference +# system, and so shouldn't trigger E1101 when accessed. Python regular +# expressions are accepted. +generated-members= + +# Tells whether to warn about missing members when the owner of the attribute +# is inferred to be None. +ignore-none=yes + +# This flag controls whether pylint should warn about no-member and similar +# checks whenever an opaque object is returned when inferring. The inference +# can return multiple potential results while evaluating a Python object, but +# some branches might not be evaluated, which results in partial inference. In +# that case, it might be useful to still emit no-member and other checks for +# the rest of the inferred objects. +ignore-on-opaque-inference=yes + +# List of symbolic message names to ignore for Mixin members. +ignored-checks-for-mixins=no-member, + not-async-context-manager, + not-context-manager, + attribute-defined-outside-init + +# List of class names for which member attributes should not be checked (useful +# for classes with dynamically set attributes). This supports the use of +# qualified names. +ignored-classes=optparse.Values,thread._local,_thread._local,argparse.Namespace + +# Show a hint with possible names when a member name was not found. The aspect +# of finding the hint is based on edit distance. +missing-member-hint=yes + +# The minimum edit distance a name should have in order to be considered a +# similar match for a missing member name. +missing-member-hint-distance=1 + +# The total number of similar names that should be taken in consideration when +# showing a hint for a missing member. +missing-member-max-choices=1 + +# Regex pattern to define which classes are considered mixins. +mixin-class-rgx=.*[Mm]ixin + +# List of decorators that change the signature of a decorated function. +signature-mutators= + + +[VARIABLES] + +# List of additional names supposed to be defined in builtins. Remember that +# you should avoid defining new builtins when possible. +additional-builtins= + +# Tells whether unused global variables should be treated as a violation. +allow-global-unused-variables=yes + +# List of names allowed to shadow builtins +allowed-redefined-builtins= + +# List of strings which can identify a callback function by name. A callback +# name must start or end with one of those strings. +callbacks=cb_, + _cb + +# A regular expression matching the name of dummy variables (i.e. expected to +# not be used). +dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ + +# Argument names that match this expression will be ignored. +ignored-argument-names=_.*|^ignored_|^unused_ + +# Tells whether we should check for unused import in __init__ files. +init-import=no + +# List of qualified module names which can have objects that can redefine +# builtins. +redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io From b73452d55997a4d5bd685d4f29365b9451d46d90 Mon Sep 17 00:00:00 2001 From: Amber Qianyun Wang <88248072+MochitheCoderCat@users.noreply.github.com> Date: Tue, 26 Nov 2024 20:09:49 -0800 Subject: [PATCH 14/34] Create cd.yml --- .github/workflows/cd.yml | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/cd.yml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 00000000..bfbb5fb2 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,45 @@ +name: CD Pipeline + +on: + workflow_run: + workflows: ["CI Pipeline"] + types: + - completed + +jobs: + deploy: + runs-on: ubuntu-latest + needs: build # Ensure this runs only after the CI job completes successfully + + steps: + # Checkout the repository (optional, for access to scripts or configs) + - name: Checkout repository + uses: actions/checkout@v3 + + # Log in to Docker Hub + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + # Pull the Docker image on the target server and deploy + # - name: Deploy to Server + # env: + # SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} + # SERVER_USER: ${{ secrets.SERVER_USER }} + # SERVER_HOST: ${{ secrets.SERVER_HOST }} + # run: | + # # Add the server to known hosts + # mkdir -p ~/.ssh + # echo "${SSH_PRIVATE_KEY}" > ~/.ssh/id_rsa + # chmod 600 ~/.ssh/id_rsa + # ssh-keyscan -H "${SERVER_HOST}" >> ~/.ssh/known_hosts + + # # SSH into the server and deploy the container + # ssh ${SERVER_USER}@${SERVER_HOST} " + # docker pull shan533/common-assessment-tool:${{ github.sha }} && + # docker stop common-assessment-container || true && + # docker rm common-assessment-container || true && + # docker run -d --name common-assessment-container -p 8000:8000 shan533/common-assessment-tool:${{ github.sha }} + # " From 3f08dcc1a983243bc55f3fe7ed76f945f0424e97 Mon Sep 17 00:00:00 2001 From: Amber Qianyun Wang <88248072+MochitheCoderCat@users.noreply.github.com> Date: Tue, 26 Nov 2024 20:16:02 -0800 Subject: [PATCH 15/34] Update cd.yml --- .github/workflows/cd.yml | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index bfbb5fb2..aaf8c423 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -7,39 +7,25 @@ on: - completed jobs: + prepare-deployment: + runs-on: ubuntu-latest + steps: + # This step is standalone and ensures the workflow is valid + - name: Dummy Preparation Step + run: echo "Preparing deployment (server not ready yet)" + deploy: runs-on: ubuntu-latest - needs: build # Ensure this runs only after the CI job completes successfully + needs: prepare-deployment # Depends on the dummy preparation job + if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - # Checkout the repository (optional, for access to scripts or configs) - - name: Checkout repository - uses: actions/checkout@v3 - - # Log in to Docker Hub - name: Log in to Docker Hub uses: docker/login-action@v2 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - # Pull the Docker image on the target server and deploy - # - name: Deploy to Server - # env: - # SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} - # SERVER_USER: ${{ secrets.SERVER_USER }} - # SERVER_HOST: ${{ secrets.SERVER_HOST }} - # run: | - # # Add the server to known hosts - # mkdir -p ~/.ssh - # echo "${SSH_PRIVATE_KEY}" > ~/.ssh/id_rsa - # chmod 600 ~/.ssh/id_rsa - # ssh-keyscan -H "${SERVER_HOST}" >> ~/.ssh/known_hosts - - # # SSH into the server and deploy the container - # ssh ${SERVER_USER}@${SERVER_HOST} " - # docker pull shan533/common-assessment-tool:${{ github.sha }} && - # docker stop common-assessment-container || true && - # docker rm common-assessment-container || true && - # docker run -d --name common-assessment-container -p 8000:8000 shan533/common-assessment-tool:${{ github.sha }} - # " + - name: Pull Docker image (no server yet) + run: | + echo "Server is not yet running; simulating deployment steps." From 99bd1d7ced5e4d1ea96cd2e714bf012a96e8c5e7 Mon Sep 17 00:00:00 2001 From: Xiaoxi Yang Date: Mon, 2 Dec 2024 22:02:59 -0800 Subject: [PATCH 16/34] specify deployment process --- appspec.yml | 14 ++++++++++++++ scripts/install_dependencies.sh | 2 ++ scripts/start_server.sh | 2 ++ 3 files changed, 18 insertions(+) create mode 100644 appspec.yml create mode 100644 scripts/install_dependencies.sh create mode 100644 scripts/start_server.sh diff --git a/appspec.yml b/appspec.yml new file mode 100644 index 00000000..8ec23d4a --- /dev/null +++ b/appspec.yml @@ -0,0 +1,14 @@ +version: 0.0 +os: ubuntu +files: + - source: / + destination: /var/www/html +hooks: + BeforeInstall: + - location: scripts/install_dependencies.sh + timeout: 300 + runas: root + AfterInstall: + - location: scripts/start_server.sh + timeout: 300 + runas: root diff --git a/scripts/install_dependencies.sh b/scripts/install_dependencies.sh new file mode 100644 index 00000000..175907fe --- /dev/null +++ b/scripts/install_dependencies.sh @@ -0,0 +1,2 @@ +#!/bin/bash +sudo yum install -y httpd diff --git a/scripts/start_server.sh b/scripts/start_server.sh new file mode 100644 index 00000000..a2531862 --- /dev/null +++ b/scripts/start_server.sh @@ -0,0 +1,2 @@ +#!/bin/bash +sudo service httpd start \ No newline at end of file From 0f8b562de84e432f297e23ae99b8769c3dd89bb3 Mon Sep 17 00:00:00 2001 From: Xiaoxi Yang Date: Mon, 2 Dec 2024 23:03:40 -0800 Subject: [PATCH 17/34] specify deployment process1 --- scripts/install_dependencies.sh | 6 +++++- scripts/start_server.sh | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/install_dependencies.sh b/scripts/install_dependencies.sh index 175907fe..196d5dae 100644 --- a/scripts/install_dependencies.sh +++ b/scripts/install_dependencies.sh @@ -1,2 +1,6 @@ #!/bin/bash -sudo yum install -y httpd +# Update package lists +sudo apt update -y + +# Install Apache (httpd equivalent) +sudo apt install -y apache2 diff --git a/scripts/start_server.sh b/scripts/start_server.sh index a2531862..ed16c08f 100644 --- a/scripts/start_server.sh +++ b/scripts/start_server.sh @@ -1,2 +1,6 @@ #!/bin/bash -sudo service httpd start \ No newline at end of file +# Start the Apache server +sudo systemctl start apache2 + +# Enable Apache to start on boot +sudo systemctl enable apache2 From 67177a5b0c42ffd93ef24c25290c2633c0647053 Mon Sep 17 00:00:00 2001 From: Xiaoxi Yang Date: Mon, 2 Dec 2024 23:20:52 -0800 Subject: [PATCH 18/34] Fix: Change OS from ubuntu to linux in appspec.yml --- appspec.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appspec.yml b/appspec.yml index 8ec23d4a..dd8d1584 100644 --- a/appspec.yml +++ b/appspec.yml @@ -1,5 +1,5 @@ version: 0.0 -os: ubuntu +os: linux files: - source: / destination: /var/www/html From 5d93ef9758d47430f10770cc1eb91b1a75299d80 Mon Sep 17 00:00:00 2001 From: Xiaoxi Yang Date: Tue, 3 Dec 2024 10:34:35 -0800 Subject: [PATCH 19/34] add comment for appspec.yml --- appspec.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/appspec.yml b/appspec.yml index dd8d1584..3a7a40f0 100644 --- a/appspec.yml +++ b/appspec.yml @@ -1,3 +1,4 @@ +# specifies the deployment lifecycle events version: 0.0 os: linux files: From b6263a716545c6fabaffced593dee529a2699d4d Mon Sep 17 00:00:00 2001 From: Xiaoxi Yang Date: Tue, 3 Dec 2024 11:53:31 -0800 Subject: [PATCH 20/34] delete comment --- appspec.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/appspec.yml b/appspec.yml index 3a7a40f0..dd8d1584 100644 --- a/appspec.yml +++ b/appspec.yml @@ -1,4 +1,3 @@ -# specifies the deployment lifecycle events version: 0.0 os: linux files: From 7c35e5c8cda0ca289c131ec72de53063e12a20ee Mon Sep 17 00:00:00 2001 From: MochitheCoderCat Date: Tue, 3 Dec 2024 12:30:36 -0800 Subject: [PATCH 21/34] updated main.py for root route --- app/main.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/main.py b/app/main.py index 5b6bf162..ea5400a5 100644 --- a/app/main.py +++ b/app/main.py @@ -6,6 +6,16 @@ app = FastAPI() +# Root route +@app.get("/") +def read_root(): + return { + "message": "Welcome to the application!", + "status": "healthy", + "version": "1.0.0", + "docs_url": "/docs" + } + # Set API endpoints on router app.include_router(clients_router) From a18fd55610ea4d324f3cd7010638e1111d325a6c Mon Sep 17 00:00:00 2001 From: Shan533 <96012342+Shan533@users.noreply.github.com> Date: Tue, 3 Dec 2024 13:03:44 -0800 Subject: [PATCH 22/34] test test --- tests/test_example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_example.py b/tests/test_example.py index c4d1c95f..ff9b916c 100644 --- a/tests/test_example.py +++ b/tests/test_example.py @@ -62,5 +62,5 @@ def test_interpret_and_calculate(): results = interpret_and_calculate(data) assert isinstance(results, dict) - assert "baseline" in results + assert "baselines" in results assert "interventions" in results From 84384ae73cf7d218a9381f210d0f6548cfbda8d7 Mon Sep 17 00:00:00 2001 From: Shan533 <96012342+Shan533@users.noreply.github.com> Date: Tue, 3 Dec 2024 13:06:44 -0800 Subject: [PATCH 23/34] Update test_example.py --- tests/test_example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_example.py b/tests/test_example.py index ff9b916c..c4d1c95f 100644 --- a/tests/test_example.py +++ b/tests/test_example.py @@ -62,5 +62,5 @@ def test_interpret_and_calculate(): results = interpret_and_calculate(data) assert isinstance(results, dict) - assert "baselines" in results + assert "baseline" in results assert "interventions" in results From c66e4cad1311f9f854ec53698909b25477aca518 Mon Sep 17 00:00:00 2001 From: Amber Qianyun Wang <88248072+MochitheCoderCat@users.noreply.github.com> Date: Tue, 3 Dec 2024 14:36:45 -0800 Subject: [PATCH 24/34] Update cd.yml for application deploy --- .github/workflows/cd.yml | 42 ++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index aaf8c423..25a36f6d 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -1,31 +1,45 @@ name: CD Pipeline - + on: workflow_run: workflows: ["CI Pipeline"] types: - completed - + jobs: - prepare-deployment: - runs-on: ubuntu-latest - steps: - # This step is standalone and ensures the workflow is valid - - name: Dummy Preparation Step - run: echo "Preparing deployment (server not ready yet)" - deploy: runs-on: ubuntu-latest - needs: prepare-deployment # Depends on the dummy preparation job if: ${{ github.event.workflow_run.conclusion == 'success' }} - + steps: + # Step 1: Checkout Repository + - name: Checkout Repository + uses: actions/checkout@v3 + + # Step 2: Log in to Docker Hub - name: Log in to Docker Hub uses: docker/login-action@v2 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Pull Docker image (no server yet) + + # Step 3: Pull the Latest Docker Image + - name: Pull Latest Docker Image run: | - echo "Server is not yet running; simulating deployment steps." + docker pull shan533/common-assessment-tool:latest + echo "Pulled the latest Docker image: shan533/common-assessment-tool:latest" + + # Step 4: Deploy to EC2 + - name: Deploy Application to EC2 + uses: appleboy/ssh-action@v0.1.7 + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USER }} + key: ${{ secrets.EC2_PRIVATE_KEY }} + port: 22 + script: | + echo "Stopping any running container..." + sudo docker stop my-container || true + sudo docker rm my-container || true + echo "Starting the new container..." + sudo docker run -d --name my-container -p 8000:8000 shan533/common-assessment-tool:latest From e0c319fe232acd8603a795835f8fe64f2b7632f2 Mon Sep 17 00:00:00 2001 From: Amber Qianyun Wang <88248072+MochitheCoderCat@users.noreply.github.com> Date: Tue, 3 Dec 2024 14:43:43 -0800 Subject: [PATCH 25/34] Update cd.yml --- .github/workflows/cd.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 25a36f6d..878d9ae2 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -23,11 +23,10 @@ jobs: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - # Step 3: Pull the Latest Docker Image - - name: Pull Latest Docker Image + # Step 3: Pull Docker Image + - name: Pull Docker Image run: | - docker pull shan533/common-assessment-tool:latest - echo "Pulled the latest Docker image: shan533/common-assessment-tool:latest" + docker pull ${{ secrets.DOCKER_IMAGE }} # Step 4: Deploy to EC2 - name: Deploy Application to EC2 @@ -42,4 +41,4 @@ jobs: sudo docker stop my-container || true sudo docker rm my-container || true echo "Starting the new container..." - sudo docker run -d --name my-container -p 8000:8000 shan533/common-assessment-tool:latest + sudo docker run -d --name my-container -p 8000:8000 ${{ secrets.DOCKER_IMAGE }} From 8082b65fad0a3252ec5beecfeee05008623d968d Mon Sep 17 00:00:00 2001 From: Xiaoxi Yang Date: Tue, 3 Dec 2024 15:09:31 -0800 Subject: [PATCH 26/34] update appspec.yml --- appspec.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/appspec.yml b/appspec.yml index dd8d1584..aa6a0d0c 100644 --- a/appspec.yml +++ b/appspec.yml @@ -1,8 +1,8 @@ version: 0.0 os: linux -files: - - source: / - destination: /var/www/html +# files: +# - source: / +# destination: /var/www/html hooks: BeforeInstall: - location: scripts/install_dependencies.sh From 215a0654a8fe939d70954e4e7b1ffee4a499055f Mon Sep 17 00:00:00 2001 From: Amber Qianyun Wang <88248072+MochitheCoderCat@users.noreply.github.com> Date: Tue, 3 Dec 2024 15:43:34 -0800 Subject: [PATCH 27/34] Update main.py --- app/main.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index ea5400a5..241cc2a3 100644 --- a/app/main.py +++ b/app/main.py @@ -15,7 +15,10 @@ def read_root(): "version": "1.0.0", "docs_url": "/docs" } - +@app.get("/health") +def health_check(): + return {"status": "healthy"} + # Set API endpoints on router app.include_router(clients_router) From 501c2433ec0fec3ab5eb70d0669c98da4272a63c Mon Sep 17 00:00:00 2001 From: Xiaoxi Yang Date: Tue, 3 Dec 2024 16:04:09 -0800 Subject: [PATCH 28/34] update appspec.yml and scripts --- .github/workflows/cd.yml | 57 ++++++++++++--------------------- appspec.yml | 10 ++++-- scripts/deploy.sh | 6 ++++ scripts/install_dependencies.sh | 14 +++++--- 4 files changed, 42 insertions(+), 45 deletions(-) create mode 100644 scripts/deploy.sh diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 878d9ae2..7f2fa306 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -1,44 +1,27 @@ name: CD Pipeline on: - workflow_run: - workflows: ["CI Pipeline"] - types: - - completed - + push: + branches: + - main + jobs: deploy: runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.conclusion == 'success' }} - + steps: - # Step 1: Checkout Repository - - name: Checkout Repository - uses: actions/checkout@v3 - - # Step 2: Log in to Docker Hub - - name: Log in to Docker Hub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - # Step 3: Pull Docker Image - - name: Pull Docker Image - run: | - docker pull ${{ secrets.DOCKER_IMAGE }} - - # Step 4: Deploy to EC2 - - name: Deploy Application to EC2 - uses: appleboy/ssh-action@v0.1.7 - with: - host: ${{ secrets.EC2_HOST }} - username: ${{ secrets.EC2_USER }} - key: ${{ secrets.EC2_PRIVATE_KEY }} - port: 22 - script: | - echo "Stopping any running container..." - sudo docker stop my-container || true - sudo docker rm my-container || true - echo "Starting the new container..." - sudo docker run -d --name my-container -p 8000:8000 ${{ secrets.DOCKER_IMAGE }} + - name: Checkout code + uses: actions/checkout@v2 + + - name: Trigger AWS CodeDeploy + env: + AWS_REGION: ${{ secrets.AWS_REGION }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + APPLICATION_NAME: ${{ secrets.APPLICATION_NAME }} + DEPLOYMENT_GROUP_NAME: ${{ secrets.DEPLOYMENT_GROUP_NAME }} + run: | + aws deploy create-deployment \ + --application-name $APPLICATION_NAME \ + --deployment-group-name $DEPLOYMENT_GROUP_NAME \ + --region $AWS_REGION \ No newline at end of file diff --git a/appspec.yml b/appspec.yml index aa6a0d0c..a23b9a31 100644 --- a/appspec.yml +++ b/appspec.yml @@ -1,14 +1,18 @@ version: 0.0 os: linux -# files: -# - source: / -# destination: /var/www/html +files: + - source: / + destination: /home/ubuntu/app hooks: BeforeInstall: - location: scripts/install_dependencies.sh timeout: 300 runas: root AfterInstall: + - location: scripts/deploy.sh + timeout: 300 + runas: root + ApplicationStart: - location: scripts/start_server.sh timeout: 300 runas: root diff --git a/scripts/deploy.sh b/scripts/deploy.sh new file mode 100644 index 00000000..c975fee1 --- /dev/null +++ b/scripts/deploy.sh @@ -0,0 +1,6 @@ +#!/bin/bash +aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com +docker pull $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/my-app:latest +docker stop my-app || true +docker rm my-app || true +docker run -d -p 8000:8000 --name my-app $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/my-app:latest \ No newline at end of file diff --git a/scripts/install_dependencies.sh b/scripts/install_dependencies.sh index 196d5dae..f2ea6ffb 100644 --- a/scripts/install_dependencies.sh +++ b/scripts/install_dependencies.sh @@ -1,6 +1,10 @@ #!/bin/bash -# Update package lists -sudo apt update -y - -# Install Apache (httpd equivalent) -sudo apt install -y apache2 +sudo apt-get update +sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - +sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" +sudo apt-get update +sudo apt-get install -y docker-ce +sudo systemctl start docker +sudo systemctl enable docker +sudo usermod -aG docker ubuntu From 17c24d047b6b44a4e9681bf1f00c033891d60417 Mon Sep 17 00:00:00 2001 From: Amber Qianyun Wang <88248072+MochitheCoderCat@users.noreply.github.com> Date: Tue, 3 Dec 2024 16:14:42 -0800 Subject: [PATCH 29/34] Update cd.yml --- .github/workflows/cd.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 7f2fa306..21582153 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -24,4 +24,5 @@ jobs: aws deploy create-deployment \ --application-name $APPLICATION_NAME \ --deployment-group-name $DEPLOYMENT_GROUP_NAME \ - --region $AWS_REGION \ No newline at end of file + --revision revisionType=GitHubLocation,gitHubLocation={repository=${{ github.repository }},commitId=${{ github.sha }}} \ + --region $AWS_REGION From 107c68cd8f5239e4cc07b83984f5533158e3d51e Mon Sep 17 00:00:00 2001 From: Amber Qianyun Wang <88248072+MochitheCoderCat@users.noreply.github.com> Date: Tue, 3 Dec 2024 16:21:19 -0800 Subject: [PATCH 30/34] Update cd.yml --- .github/workflows/cd.yml | 58 +++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 21582153..878d9ae2 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -1,28 +1,44 @@ name: CD Pipeline on: - push: - branches: - - main - + workflow_run: + workflows: ["CI Pipeline"] + types: + - completed + jobs: deploy: runs-on: ubuntu-latest - + if: ${{ github.event.workflow_run.conclusion == 'success' }} + steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Trigger AWS CodeDeploy - env: - AWS_REGION: ${{ secrets.AWS_REGION }} - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - APPLICATION_NAME: ${{ secrets.APPLICATION_NAME }} - DEPLOYMENT_GROUP_NAME: ${{ secrets.DEPLOYMENT_GROUP_NAME }} - run: | - aws deploy create-deployment \ - --application-name $APPLICATION_NAME \ - --deployment-group-name $DEPLOYMENT_GROUP_NAME \ - --revision revisionType=GitHubLocation,gitHubLocation={repository=${{ github.repository }},commitId=${{ github.sha }}} \ - --region $AWS_REGION + # Step 1: Checkout Repository + - name: Checkout Repository + uses: actions/checkout@v3 + + # Step 2: Log in to Docker Hub + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + # Step 3: Pull Docker Image + - name: Pull Docker Image + run: | + docker pull ${{ secrets.DOCKER_IMAGE }} + + # Step 4: Deploy to EC2 + - name: Deploy Application to EC2 + uses: appleboy/ssh-action@v0.1.7 + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USER }} + key: ${{ secrets.EC2_PRIVATE_KEY }} + port: 22 + script: | + echo "Stopping any running container..." + sudo docker stop my-container || true + sudo docker rm my-container || true + echo "Starting the new container..." + sudo docker run -d --name my-container -p 8000:8000 ${{ secrets.DOCKER_IMAGE }} From a05c0e2aea667dbf8b6215029a8fee64f78d9801 Mon Sep 17 00:00:00 2001 From: Xiaoxi Yang Date: Tue, 3 Dec 2024 17:56:23 -0800 Subject: [PATCH 31/34] add comment --- appspec.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/appspec.yml b/appspec.yml index a23b9a31..91d44180 100644 --- a/appspec.yml +++ b/appspec.yml @@ -1,3 +1,4 @@ +# specify the lifecycle event version: 0.0 os: linux files: From 687576ffa86ea249f28c8f57d8dc3530aa0ebcb7 Mon Sep 17 00:00:00 2001 From: Xiaoxi Yang Date: Tue, 3 Dec 2024 18:11:59 -0800 Subject: [PATCH 32/34] update appspec.yml and scripts --- appspec.yml | 10 +++------- scripts/install_dependencies.sh | 13 ++++--------- scripts/start_server.sh | 3 +-- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/appspec.yml b/appspec.yml index 91d44180..6b6b0450 100644 --- a/appspec.yml +++ b/appspec.yml @@ -1,19 +1,15 @@ # specify the lifecycle event version: 0.0 os: linux -files: - - source: / - destination: /home/ubuntu/app +# files: +# - source: / +# destination: /home/ubuntu/app hooks: BeforeInstall: - location: scripts/install_dependencies.sh timeout: 300 runas: root AfterInstall: - - location: scripts/deploy.sh - timeout: 300 - runas: root - ApplicationStart: - location: scripts/start_server.sh timeout: 300 runas: root diff --git a/scripts/install_dependencies.sh b/scripts/install_dependencies.sh index f2ea6ffb..39109068 100644 --- a/scripts/install_dependencies.sh +++ b/scripts/install_dependencies.sh @@ -1,10 +1,5 @@ #!/bin/bash -sudo apt-get update -sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common -curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - -sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" -sudo apt-get update -sudo apt-get install -y docker-ce -sudo systemctl start docker -sudo systemctl enable docker -sudo usermod -aG docker ubuntu +# Update package lists +sudo apt update -y +# Install Apache (httpd equivalent) +sudo apt install -y apache2 diff --git a/scripts/start_server.sh b/scripts/start_server.sh index ed16c08f..0e0c0c68 100644 --- a/scripts/start_server.sh +++ b/scripts/start_server.sh @@ -1,6 +1,5 @@ #!/bin/bash # Start the Apache server sudo systemctl start apache2 - # Enable Apache to start on boot -sudo systemctl enable apache2 +sudo systemctl enable apache2 \ No newline at end of file From 8c78e0a4631233653750d47745f842997eb7cc06 Mon Sep 17 00:00:00 2001 From: Amber Qianyun Wang <88248072+MochitheCoderCat@users.noreply.github.com> Date: Tue, 3 Dec 2024 20:22:37 -0800 Subject: [PATCH 33/34] Update test_example.py modified test --- tests/test_example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_example.py b/tests/test_example.py index c4d1c95f..ff9b916c 100644 --- a/tests/test_example.py +++ b/tests/test_example.py @@ -62,5 +62,5 @@ def test_interpret_and_calculate(): results = interpret_and_calculate(data) assert isinstance(results, dict) - assert "baseline" in results + assert "baselines" in results assert "interventions" in results From 7ab862985f4caaa94ac8c0b02c288b7a60776f7b Mon Sep 17 00:00:00 2001 From: Amber Qianyun Wang <88248072+MochitheCoderCat@users.noreply.github.com> Date: Tue, 3 Dec 2024 20:25:48 -0800 Subject: [PATCH 34/34] Update test_example.py --- tests/test_example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_example.py b/tests/test_example.py index ff9b916c..c4d1c95f 100644 --- a/tests/test_example.py +++ b/tests/test_example.py @@ -62,5 +62,5 @@ def test_interpret_and_calculate(): results = interpret_and_calculate(data) assert isinstance(results, dict) - assert "baselines" in results + assert "baseline" in results assert "interventions" in results