From 6f46c0403e3447b32cfeb14c0758b7b4430db011 Mon Sep 17 00:00:00 2001 From: JoAngel8 Date: Mon, 25 Dec 2023 02:29:41 +0100 Subject: [PATCH 01/11] Workflow Prod Apply must start manually by Terraform --- .../workflows/terraform_deployments_prod_apply.yaml | 10 +--------- .../workflows/terraform_provisioning_prod_apply.yaml | 10 +--------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/.github/workflows/terraform_deployments_prod_apply.yaml b/.github/workflows/terraform_deployments_prod_apply.yaml index 4a15f85..0d776db 100644 --- a/.github/workflows/terraform_deployments_prod_apply.yaml +++ b/.github/workflows/terraform_deployments_prod_apply.yaml @@ -36,12 +36,4 @@ jobs: id: apply-run with: workspace: ${{ env.TF_WORKSPACE }} - configuration_version: ${{ steps.apply-upload.outputs.configuration_version_id }} - - - name: Apply - uses: hashicorp/tfc-workflows-github/actions/apply-run@v1.1.1 - if: fromJSON(steps.apply-run.outputs.payload).data.attributes.actions.IsConfirmable - id: apply - with: - run: ${{ steps.apply-run.outputs.run_id }} - comment: "Apply Run from GitHub Actions CI ${{ github.sha }}" \ No newline at end of file + configuration_version: ${{ steps.apply-upload.outputs.configuration_version_id }} \ No newline at end of file diff --git a/.github/workflows/terraform_provisioning_prod_apply.yaml b/.github/workflows/terraform_provisioning_prod_apply.yaml index 3b31661..5f80b86 100644 --- a/.github/workflows/terraform_provisioning_prod_apply.yaml +++ b/.github/workflows/terraform_provisioning_prod_apply.yaml @@ -36,12 +36,4 @@ jobs: id: apply-run with: workspace: ${{ env.TF_WORKSPACE }} - configuration_version: ${{ steps.apply-upload.outputs.configuration_version_id }} - - - name: Apply - uses: hashicorp/tfc-workflows-github/actions/apply-run@v1.1.1 - if: fromJSON(steps.apply-run.outputs.payload).data.attributes.actions.IsConfirmable - id: apply - with: - run: ${{ steps.apply-run.outputs.run_id }} - comment: "Apply Run from GitHub Actions CI ${{ github.sha }}" + configuration_version: ${{ steps.apply-upload.outputs.configuration_version_id }} \ No newline at end of file From ec0a1eb9d70077ecb4de8d3ac97aeb98e1cd94ac Mon Sep 17 00:00:00 2001 From: gitkvark Date: Wed, 27 Dec 2023 10:15:06 +0100 Subject: [PATCH 02/11] Specifying versions of helm packages --- terraform/deployments/preprod/releases/fastapi_app.tf | 1 + terraform/deployments/preprod/releases/postgres_cluster.tf | 1 + terraform/deployments/prod/releases/fastapi_app.tf | 1 + terraform/deployments/prod/releases/postgres_cluster.tf | 1 + terraform/deployments/releases/cert_manager.tf | 1 + terraform/deployments/releases/postgres_operator.tf | 5 +++-- 6 files changed, 8 insertions(+), 2 deletions(-) diff --git a/terraform/deployments/preprod/releases/fastapi_app.tf b/terraform/deployments/preprod/releases/fastapi_app.tf index f3b8fe1..e6bcfd3 100644 --- a/terraform/deployments/preprod/releases/fastapi_app.tf +++ b/terraform/deployments/preprod/releases/fastapi_app.tf @@ -2,6 +2,7 @@ resource "helm_release" "fastapi_app" { name = "fastapi-app" chart = "${path.module}/../../../../helm/fastapi-app" create_namespace = true + version = "0.1.6" values = [ file("${path.module}/../../../../helm/fastapi-app/values-preprod.yaml") ] diff --git a/terraform/deployments/preprod/releases/postgres_cluster.tf b/terraform/deployments/preprod/releases/postgres_cluster.tf index 0fd80f8..09a2b40 100644 --- a/terraform/deployments/preprod/releases/postgres_cluster.tf +++ b/terraform/deployments/preprod/releases/postgres_cluster.tf @@ -2,6 +2,7 @@ resource "helm_release" "postgres_cluster" { name = "postgres-cluster" chart = "${path.module}/../../../../helm/postgres-cluster" create_namespace = true + version = "0.1.12" values = [ file("${path.module}/../../../../helm/postgres-cluster/values-preprod.yaml") ] diff --git a/terraform/deployments/prod/releases/fastapi_app.tf b/terraform/deployments/prod/releases/fastapi_app.tf index 44b714b..5776d77 100644 --- a/terraform/deployments/prod/releases/fastapi_app.tf +++ b/terraform/deployments/prod/releases/fastapi_app.tf @@ -2,6 +2,7 @@ resource "helm_release" "fastapi_app" { name = "fastapi-app" chart = "${path.module}/../../../../helm/fastapi-app" create_namespace = true + version = "0.1.6" values = [ file("${path.module}/../../../../helm/fastapi-app/values-prod.yaml") ] diff --git a/terraform/deployments/prod/releases/postgres_cluster.tf b/terraform/deployments/prod/releases/postgres_cluster.tf index 41917f1..d499d0c 100644 --- a/terraform/deployments/prod/releases/postgres_cluster.tf +++ b/terraform/deployments/prod/releases/postgres_cluster.tf @@ -2,6 +2,7 @@ resource "helm_release" "postgres_cluster" { name = "postgres-cluster" chart = "${path.module}/../../../../helm/postgres-cluster" create_namespace = true + version = "0.1.12" values = [ file("${path.module}/../../../../helm/postgres-cluster/values-prod.yaml") ] diff --git a/terraform/deployments/releases/cert_manager.tf b/terraform/deployments/releases/cert_manager.tf index f2639f0..8be3c01 100644 --- a/terraform/deployments/releases/cert_manager.tf +++ b/terraform/deployments/releases/cert_manager.tf @@ -14,5 +14,6 @@ resource "helm_release" "cert_manager" { resource "helm_release" "cluster_issuer" { name = "cluster-issuer" chart = "${path.module}/../../../helm/clusterissuer" + version = "0.1.6" depends_on = [helm_release.cert_manager] } diff --git a/terraform/deployments/releases/postgres_operator.tf b/terraform/deployments/releases/postgres_operator.tf index 534174c..d30d683 100644 --- a/terraform/deployments/releases/postgres_operator.tf +++ b/terraform/deployments/releases/postgres_operator.tf @@ -10,8 +10,9 @@ resource "helm_release" "postgres_operator" { } resource "helm_release" "postgres_operator_config" { - name = "postgres-operator-config" - chart = "${path.module}/../../../helm/postgres-operator-config" + name = "postgres-operator-config" + chart = "${path.module}/../../../helm/postgres-operator-config" + version = "0.1.16" set { name = "s3_backup_aws_access_key_id" value = var.s3_backup_aws_access_key_id From 95bea5f6e5f5faf3174d1f981228a77cf43d4fc4 Mon Sep 17 00:00:00 2001 From: wlt71 <148268632+wlt71@users.noreply.github.com> Date: Wed, 27 Dec 2023 14:27:39 +0100 Subject: [PATCH 03/11] New app and modifications releases (#88) * New app with GET PUT POST and D ELETE methods * Update app new version --- app/config.py | 9 - app/db.py | 26 --- app/main.py | 195 ++++++++++++++++-- app/requirements.txt | 38 +++- helm/fastapi-app/Chart.yaml | 2 +- .../preprod/releases/fastapi_app.tf | 2 +- .../deployments/prod/releases/fastapi_app.tf | 2 +- 7 files changed, 211 insertions(+), 63 deletions(-) delete mode 100644 app/config.py delete mode 100644 app/db.py diff --git a/app/config.py b/app/config.py deleted file mode 100644 index de13bdb..0000000 --- a/app/config.py +++ /dev/null @@ -1,9 +0,0 @@ -import os - -from pydantic import BaseSettings, Field - - -class Settings(BaseSettings): - db_url: str = Field(..., env='DATABASE_URL') - -settings = Settings() diff --git a/app/db.py b/app/db.py deleted file mode 100644 index 90e7d99..0000000 --- a/app/db.py +++ /dev/null @@ -1,26 +0,0 @@ -import databases -import ormar -import sqlalchemy - -from .config import settings - -database = databases.Database(settings.db_url) -metadata = sqlalchemy.MetaData() - - -class BaseMeta(ormar.ModelMeta): - metadata = metadata - database = database - - -class User(ormar.Model): - class Meta(BaseMeta): - tablename = "users" - - id: int = ormar.Integer(primary_key=True) - email: str = ormar.String(max_length=128, unique=True, nullable=False) - active: bool = ormar.Boolean(default=True, nullable=False) - - -engine = sqlalchemy.create_engine(settings.db_url) -metadata.create_all(engine) diff --git a/app/main.py b/app/main.py index 930e5ea..7b0cb6f 100644 --- a/app/main.py +++ b/app/main.py @@ -1,29 +1,182 @@ -from fastapi import FastAPI - -from app.db import database, User +from fastapi import FastAPI, HTTPException +from fastapi.middleware.cors import CORSMiddleware +from fastapi.responses import JSONResponse +from pydantic import BaseModel, Field +from pydantic_settings import BaseSettings +from sqlalchemy import create_engine, Column, Integer, String, ForeignKey +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.orm import sessionmaker, relationship from prometheus_fastapi_instrumentator import Instrumentator -app = FastAPI(title="FastAPI, Docker, and Traefik") -instrumentator = Instrumentator().instrument(app) +# Database configuration +import os + +class Settings(BaseSettings): + db_url: str = Field(..., env='DATABASE_URL') + +settings = Settings(db_url=os.environ['DATABASE_URL']) + +#from .config import settings +#database = databases.Database(settings.db_url) +#DATABASE_URL = "postgresql://postgres:postgres123@192.168.1.30/db_app001" + +engine = create_engine(settings.db_url) +SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) + +Base = declarative_base() + +# Define User model +class User(Base): + __tablename__ = "users" + + id = Column(Integer, primary_key=True, index=True) + name = Column(String, index=True) + email = Column(String, index=True) + course_id = Column(Integer, ForeignKey("courses.id_cours")) + + course = relationship("Course", back_populates="users") + +# Define Course model +class Course(Base): + __tablename__ = "courses" + + id_cours = Column(Integer, primary_key=True, index=True) + course_name = Column(String, index=True) + + users = relationship("User", back_populates="course") + +# Create tables in the database +Base.metadata.create_all(bind=engine) + +# FastAPI app setup +app = FastAPI() + +# Prometheus monitoring setup +Instrumentator().instrument(app).expose(app) + +# CORS middleware +app.add_middleware( + CORSMiddleware, + allow_origins=["*"], + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + +# Pydantic models for request and response +class UserCreate(BaseModel): + name: str + email: str + +class CourseCreate(BaseModel): + course_name: str + +class UserResponse(UserCreate): + id: int + +class CourseResponse(CourseCreate): + id_cours: int + +# Endpoints +@app.post("/users/", response_model=UserResponse) +def create_user(user: UserCreate): + db = SessionLocal() + db_user = User(**user.dict()) + db.add(db_user) + db.commit() + db.refresh(db_user) + db.close() + return db_user + +@app.put("/users/{user_id}", response_model=UserResponse) +def update_user(user_id: int, user: UserCreate): + db = SessionLocal() + db_user = db.query(User).filter(User.id == user_id).first() + if db_user: + db_user.name = user.name + db_user.email = user.email + db.commit() + db.refresh(db_user) + db.close() + return db_user + +@app.get("/users/{user_id}", response_model=UserResponse) +def read_user(user_id: int): + db = SessionLocal() + db_user = db.query(User).filter(User.id == user_id).first() + db.close() + if db_user: + return db_user + else: + raise HTTPException(status_code=404, detail="User not found") + +@app.get("/users/", response_model=list[UserResponse]) +def read_users(skip: int = 0, limit: int = 10): + db = SessionLocal() + users = db.query(User).offset(skip).limit(limit).all() + db.close() + return users +@app.delete("/users/{user_id}", response_model=UserResponse) +def delete_user(user_id: int): + db = SessionLocal() + db_user = db.query(User).filter(User.id == user_id).first() + if db_user: + db.delete(db_user) + db.commit() + db.close() + return db_user + else: + db.close() + raise HTTPException(status_code=404, detail="User not found") -@app.get("/") -async def read_root(): - return await User.objects.all() +@app.post("/courses/", response_model=CourseResponse) +def create_course(course: CourseCreate): + db = SessionLocal() + db_course = Course(**course.dict()) + db.add(db_course) + db.commit() + db.refresh(db_course) + db.close() + return db_course +@app.put("/courses/{course_id}", response_model=CourseResponse) +def update_course(course_id: int, course: CourseCreate): + db = SessionLocal() + db_course = db.query(Course).filter(Course.id_cours == course_id).first() + if db_course: + db_course.course_name = course.course_name + db.commit() + db.refresh(db_course) + db.close() + return db_course -@app.on_event("startup") -async def startup(): - # Expose prometheus metrics using the Instrumentator - # https://github.com/trallnag/prometheus-fastapi-instrumentator - instrumentator.expose(app) - if not database.is_connected: - await database.connect() - # create a dummy entry - await User.objects.get_or_create(email="test@test.com") +@app.get("/courses/{course_id}", response_model=CourseResponse) +def read_course(course_id: int): + db = SessionLocal() + db_course = db.query(Course).filter(Course.id_cours == course_id).first() + db.close() + if db_course: + return db_course + else: + raise HTTPException(status_code=404, detail="Course not found") +@app.get("/courses/", response_model=list[CourseResponse]) +def read_courses(skip: int = 0, limit: int = 10): + db = SessionLocal() + courses = db.query(Course).offset(skip).limit(limit).all() + db.close() + return courses -@app.on_event("shutdown") -async def shutdown(): - if database.is_connected: - await database.disconnect() +@app.delete("/courses/{course_id}", response_model=CourseResponse) +def delete_course(course_id: int): + db = SessionLocal() + db_course = db.query(Course).filter(Course.id_cours == course_id).first() + if db_course: + db.delete(db_course) + db.commit() + db.close() + return db_course + else: + db.close() + raise HTTPException(status_code=404, detail="Course not found") diff --git a/app/requirements.txt b/app/requirements.txt index 01fb4ea..580586a 100644 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -1,6 +1,36 @@ -asyncpg==0.29.0 -fastapi==0.106.0 -ormar==0.12.2 +annotated-types==0.6.0 +anyio==3.7.1 +certifi==2023.11.17 +click==8.1.7 +colorama==0.4.6 +dnspython==2.4.2 +email-validator==2.1.0.post1 +fastapi==0.105.0 +greenlet==3.0.3 +h11==0.14.0 +httpcore==1.0.2 +httptools==0.6.1 +httpx==0.26.0 +idna==3.6 +itsdangerous==2.1.2 +Jinja2==3.1.2 +MarkupSafe==2.1.3 +orjson==3.9.10 +prometheus-client==0.19.0 +prometheus-fastapi-instrumentator==6.1.0 psycopg2-binary==2.9.9 +pydantic==2.5.3 +pydantic-extra-types==2.2.0 +pydantic-settings==2.1.0 +pydantic_core==2.14.6 +python-dotenv==1.0.0 +python-multipart==0.0.6 +PyYAML==6.0.1 +sniffio==1.3.0 +SQLAlchemy==2.0.23 +starlette==0.27.0 +typing_extensions==4.9.0 +ujson==5.9.0 uvicorn==0.25.0 -prometheus-fastapi-instrumentator==6.1.0 \ No newline at end of file +watchfiles==0.21.0 +websockets==12.0 diff --git a/helm/fastapi-app/Chart.yaml b/helm/fastapi-app/Chart.yaml index 85cda8d..c3061be 100644 --- a/helm/fastapi-app/Chart.yaml +++ b/helm/fastapi-app/Chart.yaml @@ -15,7 +15,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.1.6 +version: 0.1.7 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to diff --git a/terraform/deployments/preprod/releases/fastapi_app.tf b/terraform/deployments/preprod/releases/fastapi_app.tf index e6bcfd3..a54ae67 100644 --- a/terraform/deployments/preprod/releases/fastapi_app.tf +++ b/terraform/deployments/preprod/releases/fastapi_app.tf @@ -2,7 +2,7 @@ resource "helm_release" "fastapi_app" { name = "fastapi-app" chart = "${path.module}/../../../../helm/fastapi-app" create_namespace = true - version = "0.1.6" + version = "0.1.7" values = [ file("${path.module}/../../../../helm/fastapi-app/values-preprod.yaml") ] diff --git a/terraform/deployments/prod/releases/fastapi_app.tf b/terraform/deployments/prod/releases/fastapi_app.tf index 5776d77..5b7dc95 100644 --- a/terraform/deployments/prod/releases/fastapi_app.tf +++ b/terraform/deployments/prod/releases/fastapi_app.tf @@ -2,7 +2,7 @@ resource "helm_release" "fastapi_app" { name = "fastapi-app" chart = "${path.module}/../../../../helm/fastapi-app" create_namespace = true - version = "0.1.6" + version = "0.1.7" values = [ file("${path.module}/../../../../helm/fastapi-app/values-prod.yaml") ] From 3dfc5c5b6aa5d4c71dd566090ff8efe0bee7dbb9 Mon Sep 17 00:00:00 2001 From: gitkvark <146422227+gitkvark@users.noreply.github.com> Date: Wed, 27 Dec 2023 14:56:12 +0100 Subject: [PATCH 04/11] Bump the version of fastapi app --- helm/fastapi-app/Chart.yaml | 2 +- terraform/deployments/preprod/releases/fastapi_app.tf | 2 +- terraform/deployments/prod/releases/fastapi_app.tf | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/helm/fastapi-app/Chart.yaml b/helm/fastapi-app/Chart.yaml index c3061be..2b3878b 100644 --- a/helm/fastapi-app/Chart.yaml +++ b/helm/fastapi-app/Chart.yaml @@ -15,7 +15,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.1.7 +version: 0.1.8 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to diff --git a/terraform/deployments/preprod/releases/fastapi_app.tf b/terraform/deployments/preprod/releases/fastapi_app.tf index a54ae67..02c8bf3 100644 --- a/terraform/deployments/preprod/releases/fastapi_app.tf +++ b/terraform/deployments/preprod/releases/fastapi_app.tf @@ -2,7 +2,7 @@ resource "helm_release" "fastapi_app" { name = "fastapi-app" chart = "${path.module}/../../../../helm/fastapi-app" create_namespace = true - version = "0.1.7" + version = "0.1.8" values = [ file("${path.module}/../../../../helm/fastapi-app/values-preprod.yaml") ] diff --git a/terraform/deployments/prod/releases/fastapi_app.tf b/terraform/deployments/prod/releases/fastapi_app.tf index 5b7dc95..41988c8 100644 --- a/terraform/deployments/prod/releases/fastapi_app.tf +++ b/terraform/deployments/prod/releases/fastapi_app.tf @@ -2,7 +2,7 @@ resource "helm_release" "fastapi_app" { name = "fastapi-app" chart = "${path.module}/../../../../helm/fastapi-app" create_namespace = true - version = "0.1.7" + version = "0.1.8" values = [ file("${path.module}/../../../../helm/fastapi-app/values-prod.yaml") ] From 8c0c6fa3d22a5d0b4bebc226be25efd9e9025405 Mon Sep 17 00:00:00 2001 From: gitkvark Date: Wed, 27 Dec 2023 15:09:30 +0100 Subject: [PATCH 05/11] Adding recreate app --- helm/fastapi-app/Chart.yaml | 2 +- terraform/deployments/preprod/releases/fastapi_app.tf | 3 ++- terraform/deployments/prod/releases/fastapi_app.tf | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/helm/fastapi-app/Chart.yaml b/helm/fastapi-app/Chart.yaml index 2b3878b..89646f3 100644 --- a/helm/fastapi-app/Chart.yaml +++ b/helm/fastapi-app/Chart.yaml @@ -15,7 +15,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.1.8 +version: 0.1.9 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to diff --git a/terraform/deployments/preprod/releases/fastapi_app.tf b/terraform/deployments/preprod/releases/fastapi_app.tf index 02c8bf3..0f6a0d2 100644 --- a/terraform/deployments/preprod/releases/fastapi_app.tf +++ b/terraform/deployments/preprod/releases/fastapi_app.tf @@ -2,7 +2,8 @@ resource "helm_release" "fastapi_app" { name = "fastapi-app" chart = "${path.module}/../../../../helm/fastapi-app" create_namespace = true - version = "0.1.8" + version = "0.1.9" + recreate_pods = true values = [ file("${path.module}/../../../../helm/fastapi-app/values-preprod.yaml") ] diff --git a/terraform/deployments/prod/releases/fastapi_app.tf b/terraform/deployments/prod/releases/fastapi_app.tf index 41988c8..a392792 100644 --- a/terraform/deployments/prod/releases/fastapi_app.tf +++ b/terraform/deployments/prod/releases/fastapi_app.tf @@ -2,7 +2,8 @@ resource "helm_release" "fastapi_app" { name = "fastapi-app" chart = "${path.module}/../../../../helm/fastapi-app" create_namespace = true - version = "0.1.8" + version = "0.1.9" + recreate_pods = true values = [ file("${path.module}/../../../../helm/fastapi-app/values-prod.yaml") ] From 625795bb1888107768109a94059dc856df2a0b86 Mon Sep 17 00:00:00 2001 From: gitkvark <146422227+gitkvark@users.noreply.github.com> Date: Wed, 27 Dec 2023 15:44:21 +0100 Subject: [PATCH 06/11] Adding monitoring of fastapi app --- .../kube-prometheus-stack-values.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/terraform/deployments/releases/kube-prometheus-stack/kube-prometheus-stack-values.yaml b/terraform/deployments/releases/kube-prometheus-stack/kube-prometheus-stack-values.yaml index e4657fd..5dccb64 100644 --- a/terraform/deployments/releases/kube-prometheus-stack/kube-prometheus-stack-values.yaml +++ b/terraform/deployments/releases/kube-prometheus-stack/kube-prometheus-stack-values.yaml @@ -41,5 +41,15 @@ prometheus: - targetPort: 8008 interval: 15s scrapeTimeout: 10s + - name: "fastapi_app" + selector: + matchLabels: + name: fastapi-app + namespaceSelector: + any: true + podMetricsEndpoints: + - targetPort: 8000 + interval: 15s + scrapeTimeout: 10s # Full reference: # https://github.com/prometheus-community/helm-charts/blob/main/charts/kube-prometheus-stack/values.yaml From 2be1d2c3138c0df50ecaed194bfb3446e7853c97 Mon Sep 17 00:00:00 2001 From: gitkvark <146422227+gitkvark@users.noreply.github.com> Date: Wed, 27 Dec 2023 15:55:29 +0100 Subject: [PATCH 07/11] Bug fix --- .../kube-prometheus-stack/kube-prometheus-stack-values.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/deployments/releases/kube-prometheus-stack/kube-prometheus-stack-values.yaml b/terraform/deployments/releases/kube-prometheus-stack/kube-prometheus-stack-values.yaml index 5dccb64..8067e6a 100644 --- a/terraform/deployments/releases/kube-prometheus-stack/kube-prometheus-stack-values.yaml +++ b/terraform/deployments/releases/kube-prometheus-stack/kube-prometheus-stack-values.yaml @@ -41,7 +41,7 @@ prometheus: - targetPort: 8008 interval: 15s scrapeTimeout: 10s - - name: "fastapi_app" + - name: "fastapi-app" selector: matchLabels: name: fastapi-app From b72e0151372d8514a6b0703070be69b3acc24b9d Mon Sep 17 00:00:00 2001 From: gitkvark <146422227+gitkvark@users.noreply.github.com> Date: Wed, 27 Dec 2023 16:17:40 +0100 Subject: [PATCH 08/11] Bug fix --- .../kube-prometheus-stack/kube-prometheus-stack-values.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/deployments/releases/kube-prometheus-stack/kube-prometheus-stack-values.yaml b/terraform/deployments/releases/kube-prometheus-stack/kube-prometheus-stack-values.yaml index 8067e6a..e5a8d87 100644 --- a/terraform/deployments/releases/kube-prometheus-stack/kube-prometheus-stack-values.yaml +++ b/terraform/deployments/releases/kube-prometheus-stack/kube-prometheus-stack-values.yaml @@ -44,7 +44,7 @@ prometheus: - name: "fastapi-app" selector: matchLabels: - name: fastapi-app + app: fastapi-app namespaceSelector: any: true podMetricsEndpoints: From d3b316b7e6cff4145f4f4641555b2f443444bd7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Tarot=20=28=40silopolis=29?= Date: Thu, 28 Dec 2023 12:43:45 +0100 Subject: [PATCH 09/11] scripts: make scripts executable --- scripts/bootstrap.sh | 0 scripts/prestart.sh | 0 scripts/python_setup.sh | 0 3 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/bootstrap.sh mode change 100644 => 100755 scripts/prestart.sh mode change 100644 => 100755 scripts/python_setup.sh diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh old mode 100644 new mode 100755 diff --git a/scripts/prestart.sh b/scripts/prestart.sh old mode 100644 new mode 100755 diff --git a/scripts/python_setup.sh b/scripts/python_setup.sh old mode 100644 new mode 100755 From 76d7c70f651a0cd20a0620f19e3eb7f460aaf478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Tarot=20=28=40silopolis=29?= Date: Thu, 28 Dec 2023 12:53:13 +0100 Subject: [PATCH 10/11] scripts:python_setup: only source `.env` file if it exists --- scripts/python_setup.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/python_setup.sh b/scripts/python_setup.sh index e4c7b7c..62eac84 100755 --- a/scripts/python_setup.sh +++ b/scripts/python_setup.sh @@ -7,7 +7,10 @@ cwd="$(pwd)" ## Change to project directory cd "$(dirname "$0")/.." # shellcheck source="../.env" -source .env +if [ -f .env ]; then + # shellcheck source="../.env" + source .env +fi ## Only compatible with Debian and Ubuntu if [[ ! $(dpkg -s python3-venv) ]]; then @@ -23,6 +26,7 @@ fi echo "-- Python: Activate '.venv' virtual environment" # shellcheck source="../.venv/bin/activate" source .venv/bin/activate + echo "-- Upgrage Python pip and setuptools in venv" pip install --upgrade setuptools pip echo "-- Install Python requirements in venv" From a17f7aede551b289a0ae1c8419d7912d96eadefd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Tarot=20=28=40silopolis=29?= Date: Thu, 28 Dec 2023 12:54:51 +0100 Subject: [PATCH 11/11] scripts:bootstrap: only source `.env` file if it exists Also fix shellcheck warning when sourced files do not exist --- scripts/bootstrap.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index 45dc49f..2097e7e 100755 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -6,20 +6,26 @@ set -e #ux cwd="$(pwd)" ## Change to project directory cd "$(dirname "$0")/.." -# shellcheck source="../.env" -source .env +if [ -f .env ]; then + # shellcheck source="../.env" disable=SC1091 + source .env +fi ./scripts/python_setup.sh "$@" echo "-- Shell: Source profile in case it's been updated" -# shellcheck source="$HOME/.profile" +# shellcheck source="$HOME/.profile" disable=SC1091 source "$HOME/.profile" + echo "-- Activate Python virtual environment" # shellcheck source="../.venv/bin/activate" source .venv/bin/activate -echo "-- Source '.env' configuration file" -# shellcheck source="../.env" -source .env + +if [ -f .env ]; then + echo "-- Source '.env' configuration file" + # shellcheck source="../.env" disable=SC1091 + source .env +fi ## and go back cd "$cwd"