From 04d642c5f20783af22955ca9022b09ae0e98a009 Mon Sep 17 00:00:00 2001 From: pvdevs Date: Fri, 15 Nov 2024 00:33:05 -0300 Subject: [PATCH 01/12] empty commit to test pipeline From 2176eb280adefbf9ab247662b6be93acb0e95917 Mon Sep 17 00:00:00 2001 From: pvdevs Date: Fri, 15 Nov 2024 00:33:28 -0300 Subject: [PATCH 02/12] empty commit to test pipeline From 43a725173f7528d0b5dff95dd95a52ed05516c8a Mon Sep 17 00:00:00 2001 From: pvdevs Date: Fri, 15 Nov 2024 00:33:46 -0300 Subject: [PATCH 03/12] empty commit to test pipeline From 5ce18d1a196884c9ef7c8ce8139a83a1526728be Mon Sep 17 00:00:00 2001 From: pvdevs Date: Fri, 15 Nov 2024 00:35:09 -0300 Subject: [PATCH 04/12] fix `python-app.yml` file --- .github/workflows/python-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index fae60a4..9417514 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -24,7 +24,7 @@ jobs: uses: actions/setup-python@v3 with: python-version: "3.12" - - name: Install dependencies + - name: Install dependencies run: | python -m pip install --upgrade pip pip install flake8 pytest From eb8e95bb9788dd004ceac41ee13624a87b383de2 Mon Sep 17 00:00:00 2001 From: pvdevs Date: Fri, 15 Nov 2024 00:39:59 -0300 Subject: [PATCH 05/12] fix `python-app.yml` file --- .github/workflows/python-app.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 9417514..bc03579 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -1,7 +1,6 @@ # This workflow will install Python dependencies, run tests and lint with a single version of Python # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python - name: Python application on: @@ -27,7 +26,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install flake8 pytest + pip install flake8 pytest black if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Format with Black From deeb8807a2e6b9d6dc6ef2d6d288f0134294f9c1 Mon Sep 17 00:00:00 2001 From: pvdevs Date: Fri, 15 Nov 2024 00:42:53 -0300 Subject: [PATCH 06/12] fix `python-app.yml` file --- .github/workflows/python-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index bc03579..131b83b 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -26,7 +26,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install flake8 pytest black + pip install flake8 pytest black pytest-cov if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Format with Black From f1b8175fb1ea981551a453d1a2d608690aea5008 Mon Sep 17 00:00:00 2001 From: pvdevs Date: Fri, 15 Nov 2024 00:48:26 -0300 Subject: [PATCH 07/12] fix `python-app.yml` file --- .github/workflows/python-app.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 131b83b..41e2393 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -32,6 +32,18 @@ jobs: - name: Format with Black run: black . + - name: Set environment variables (just for testing) + run: | + export DB_DRIVER=postgresql + export DB_USERNAME=test_user + export DB_PASSWORD=test_password + export DB_HOST=localhost + export DB_PORT=5432 + export DB_DATABASE=test_db + export JWT_SECRETE_KEY=test_secret_key + export PASSWORD_HASH_ALGORITHM=HS256 + export JWT_EXPIRE_MINUTES=30 + - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names From a82ff6e3471b8cd644b098de943b3c1bed169aad Mon Sep 17 00:00:00 2001 From: pvdevs Date: Fri, 15 Nov 2024 00:51:31 -0300 Subject: [PATCH 08/12] fix `python-app.yml` file --- .github/workflows/python-app.yml | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 41e2393..7676b05 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -32,18 +32,6 @@ jobs: - name: Format with Black run: black . - - name: Set environment variables (just for testing) - run: | - export DB_DRIVER=postgresql - export DB_USERNAME=test_user - export DB_PASSWORD=test_password - export DB_HOST=localhost - export DB_PORT=5432 - export DB_DATABASE=test_db - export JWT_SECRETE_KEY=test_secret_key - export PASSWORD_HASH_ALGORITHM=HS256 - export JWT_EXPIRE_MINUTES=30 - - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names @@ -51,6 +39,6 @@ jobs: # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: Test with pytest and coverage - run: | - pytest --cov=app --cov-report=term --cov-fail-under=100 \ No newline at end of file +# - name: Test with pytest and coverage +# run: | +# pytest --cov=app --cov-report=term --cov-fail-under=100 \ No newline at end of file From 9159ed500a4601f182f65f249c9e2c42349e5278 Mon Sep 17 00:00:00 2001 From: pvdevs Date: Fri, 15 Nov 2024 00:59:27 -0300 Subject: [PATCH 09/12] add `deploy-hmg.yml` pipeline file --- .github/workflows/deploy-hmg.yml | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/deploy-hmg.yml diff --git a/.github/workflows/deploy-hmg.yml b/.github/workflows/deploy-hmg.yml new file mode 100644 index 0000000..8d7f7b6 --- /dev/null +++ b/.github/workflows/deploy-hmg.yml @@ -0,0 +1,36 @@ +name: Deploy to Homologation + +on: + push: + branches: + - hmg + pull_request: + branches: + - hmg + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Configure AWS credentials for Homologation + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + + - name: Build, Tag, and Push the Image to Amazon ECR for Homologation + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: stars-api-hmg + IMAGE_TAG: latest + run: | + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \ No newline at end of file From 9d134c1d668c4d7a4a60bbc5e7891f3f5dce10af Mon Sep 17 00:00:00 2001 From: pvdevs Date: Fri, 15 Nov 2024 16:47:23 -0300 Subject: [PATCH 10/12] fix `python-app.yml` develop pipeline to have environment variables --- .github/workflows/python-app.yml | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 7676b05..b7b8a16 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -14,31 +14,36 @@ permissions: jobs: build: - runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Set up Python 3.12 uses: actions/setup-python@v3 with: python-version: "3.12" + - name: Install dependencies run: | python -m pip install --upgrade pip pip install flake8 pytest black pytest-cov if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Format with Black - run: black . - - - name: Lint with flake8 + - name: Set Environment Variables for Testing + run: | + echo "PORT=8000" >> $GITHUB_ENV + echo "DEBUG=1" >> $GITHUB_ENV + echo "DB_DRIVER=mysql+mysqlconnector" >> $GITHUB_ENV + echo "DB_USERNAME=mysql" >> $GITHUB_ENV + echo "DB_PASSWORD=mysql" >> $GITHUB_ENV + echo "DB_HOST=mysql_database" >> $GITHUB_ENV + echo "DB_PORT=3306" >> $GITHUB_ENV + echo "DB_DATABASE=db" >> $GITHUB_ENV + echo "JWT_SECRETE_KEY=testestestestetsteste" >> $GITHUB_ENV + echo "PASSWORD_HASH_ALGORITHM=HS256" >> $GITHUB_ENV + echo "JWT_EXPIRE_MINUTES=30" >> $GITHUB_ENV + + - name: Test with pytest and coverage run: | - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - -# - name: Test with pytest and coverage -# run: | -# pytest --cov=app --cov-report=term --cov-fail-under=100 \ No newline at end of file + pytest --cov=app --cov-report=term --cov-fail-under=100 \ No newline at end of file From 6618ba0724d0f6c2ed38b19bafecd088e0929392 Mon Sep 17 00:00:00 2001 From: pvdevs Date: Mon, 25 Nov 2024 21:55:12 -0300 Subject: [PATCH 11/12] add python pipeline, update main to master --- .github/workflows/deploy-hmg.yml | 36 ----------- .github/workflows/deployment_cicd.yaml | 86 ++++++++++++++++++++++++++ .github/workflows/python-app.yml | 49 --------------- 3 files changed, 86 insertions(+), 85 deletions(-) delete mode 100644 .github/workflows/deploy-hmg.yml create mode 100644 .github/workflows/deployment_cicd.yaml delete mode 100644 .github/workflows/python-app.yml diff --git a/.github/workflows/deploy-hmg.yml b/.github/workflows/deploy-hmg.yml deleted file mode 100644 index 8d7f7b6..0000000 --- a/.github/workflows/deploy-hmg.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: Deploy to Homologation - -on: - push: - branches: - - hmg - pull_request: - branches: - - hmg - -jobs: - deploy: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Configure AWS credentials for Homologation - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: us-east-1 - - - name: Login to Amazon ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v1 - - - name: Build, Tag, and Push the Image to Amazon ECR for Homologation - env: - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - ECR_REPOSITORY: stars-api-hmg - IMAGE_TAG: latest - run: | - docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . - docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \ No newline at end of file diff --git a/.github/workflows/deployment_cicd.yaml b/.github/workflows/deployment_cicd.yaml new file mode 100644 index 0000000..e7799c4 --- /dev/null +++ b/.github/workflows/deployment_cicd.yaml @@ -0,0 +1,86 @@ +name: Test Python and Deploy to ECR +on: + push: + branches: + - master + - develop + pull_request: + branches: + - master + - develop + workflow_dispatch: + +permissions: + contents: read + +jobs: + test: + if: github.ref_name == 'develop' + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python 3.12 + uses: actions/setup-python@v3 + with: + python-version: "3.12" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest black pytest-cov + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + + - name: Set Environment Variables for Testing + run: | + echo "PORT=8000" >> $GITHUB_ENV + echo "DEBUG=1" >> $GITHUB_ENV + echo "DB_DRIVER=mysql+mysqlconnector" >> $GITHUB_ENV + echo "DB_USERNAME=mysql" >> $GITHUB_ENV + echo "DB_PASSWORD=mysql" >> $GITHUB_ENV + echo "DB_HOST=mysql_database" >> $GITHUB_ENV + echo "DB_PORT=3306" >> $GITHUB_ENV + echo "DB_DATABASE=db" >> $GITHUB_ENV + echo "JWT_SECRETE_KEY=testestestestetsteste" >> $GITHUB_ENV + echo "PASSWORD_HASH_ALGORITHM=HS256" >> $GITHUB_ENV + echo "JWT_EXPIRE_MINUTES=30" >> $GITHUB_ENV + + - name: Test with pytest and coverage + run: | + pytest --cov=app --cov-report=term --cov-fail-under=100 + + deploy: + if: github.ref_name == 'master' + runs-on: ubuntu-latest + steps: + - name: Checkout on project + uses: actions/checkout@v4 + + - name: Authentication on AWS + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + + - name: Build, Tag, and Push the Image to Amazon ECR for Production + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: star-api + IMAGE_TAG: ${{ github.sha }} + + run: | + set -e + + echo "Building Docker image with tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . + + echo "Pushing Docker image to ECR with tag $IMAGE_TAG" + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + + echo "Docker image pushed successfully!" \ No newline at end of file diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml deleted file mode 100644 index b7b8a16..0000000 --- a/.github/workflows/python-app.yml +++ /dev/null @@ -1,49 +0,0 @@ -# This workflow will install Python dependencies, run tests and lint with a single version of Python -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python - -name: Python application - -on: - push: - branches: [ "develop" ] - pull_request: - branches: [ "develop" ] - -permissions: - contents: read - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - name: Set up Python 3.12 - uses: actions/setup-python@v3 - with: - python-version: "3.12" - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install flake8 pytest black pytest-cov - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - - name: Set Environment Variables for Testing - run: | - echo "PORT=8000" >> $GITHUB_ENV - echo "DEBUG=1" >> $GITHUB_ENV - echo "DB_DRIVER=mysql+mysqlconnector" >> $GITHUB_ENV - echo "DB_USERNAME=mysql" >> $GITHUB_ENV - echo "DB_PASSWORD=mysql" >> $GITHUB_ENV - echo "DB_HOST=mysql_database" >> $GITHUB_ENV - echo "DB_PORT=3306" >> $GITHUB_ENV - echo "DB_DATABASE=db" >> $GITHUB_ENV - echo "JWT_SECRETE_KEY=testestestestetsteste" >> $GITHUB_ENV - echo "PASSWORD_HASH_ALGORITHM=HS256" >> $GITHUB_ENV - echo "JWT_EXPIRE_MINUTES=30" >> $GITHUB_ENV - - - name: Test with pytest and coverage - run: | - pytest --cov=app --cov-report=term --cov-fail-under=100 \ No newline at end of file From 2f231a36cab549f7dfd965bb29c778a403df80db Mon Sep 17 00:00:00 2001 From: pvdevs Date: Tue, 26 Nov 2024 21:32:44 -0300 Subject: [PATCH 12/12] WIP: remove master deploy --- .github/workflows/deployment_cicd.yaml | 39 +------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/.github/workflows/deployment_cicd.yaml b/.github/workflows/deployment_cicd.yaml index e7799c4..c6205ee 100644 --- a/.github/workflows/deployment_cicd.yaml +++ b/.github/workflows/deployment_cicd.yaml @@ -2,11 +2,9 @@ name: Test Python and Deploy to ECR on: push: branches: - - master - develop pull_request: branches: - - master - develop workflow_dispatch: @@ -48,39 +46,4 @@ jobs: - name: Test with pytest and coverage run: | - pytest --cov=app --cov-report=term --cov-fail-under=100 - - deploy: - if: github.ref_name == 'master' - runs-on: ubuntu-latest - steps: - - name: Checkout on project - uses: actions/checkout@v4 - - - name: Authentication on AWS - uses: aws-actions/configure-aws-credentials@v4 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: us-east-1 - - - name: Login to Amazon ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v1 - - - name: Build, Tag, and Push the Image to Amazon ECR for Production - env: - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - ECR_REPOSITORY: star-api - IMAGE_TAG: ${{ github.sha }} - - run: | - set -e - - echo "Building Docker image with tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" - docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . - - echo "Pushing Docker image to ECR with tag $IMAGE_TAG" - docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG - - echo "Docker image pushed successfully!" \ No newline at end of file + pytest --cov=app --cov-report=term --cov-fail-under=100 \ No newline at end of file