From ac8e44113c5da1951b202027a4d026005cd5e84b Mon Sep 17 00:00:00 2001 From: marshfellow42 <123888466+marshfellow42@users.noreply.github.com> Date: Sun, 29 Jun 2025 11:41:59 -0300 Subject: [PATCH 1/6] Mudar o setup do Firebase no Python de um json para um dotenv --- .env.example | 15 +++++++++++++++ .gitignore | 2 +- api/main.py | 23 ++++++++++++++++++++--- requirements.txt | 3 ++- 4 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..8a835e1 --- /dev/null +++ b/.env.example @@ -0,0 +1,15 @@ +# Firebase Service Account Credentials + +TYPE=service_account +PROJECT_ID=your-project-id +PRIVATE_KEY_ID=your-private-key-id +PRIVATE_KEY=-----BEGIN PRIVATE KEY-----\\nYOUR_KEY_LINE_1\\nYOUR_KEY_LINE_2\\n-----END PRIVATE KEY-----\\n +CLIENT_EMAIL=your-service-account@your-project.iam.gserviceaccount.com +CLIENT_ID=your-client-id +AUTH_URI=https://accounts.google.com/o/oauth2/auth +TOKEN_URI=https://oauth2.googleapis.com/token +AUTH_PROVIDER_CERT_URL=https://www.googleapis.com/oauth2/v1/certs +CLIENT_CERT_URL=https://www.googleapis.com/robot/v1/metadata/x509/your-service-account%40your-project.iam.gserviceaccount.com + +# Firebase Realtime Database URL +DATABASE_URL=https://your-project-id-default-rtdb.firebaseio.com/ diff --git a/.gitignore b/.gitignore index 304a0ce..83baf96 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -credentials.json .vercel +.env \ No newline at end of file diff --git a/api/main.py b/api/main.py index 81e3c76..b60cda1 100644 --- a/api/main.py +++ b/api/main.py @@ -5,9 +5,26 @@ from phonenumbers import PhoneNumberFormat import uuid from datetime import datetime - -cred = credentials.Certificate("credentials.json") -firebase_admin.initialize_app(cred, {"databaseURL": "https://if-project-3ded1-default-rtdb.firebaseio.com/"}) +import os +from dotenv import load_dotenv + +load_dotenv() + +cred_info = { + "type": os.getenv("TYPE"), + "project_id": os.getenv("PROJECT_ID"), + "private_key_id": os.getenv("PRIVATE_KEY_ID"), + "private_key": os.getenv("PRIVATE_KEY").replace("\\n", "\n"), + "client_email": os.getenv("CLIENT_EMAIL"), + "client_id": os.getenv("CLIENT_ID"), + "auth_uri": os.getenv("AUTH_URI"), + "token_uri": os.getenv("TOKEN_URI"), + "auth_provider_x509_cert_url": os.getenv("AUTH_PROVIDER_CERT_URL"), + "client_x509_cert_url": os.getenv("CLIENT_CERT_URL") +} + +cred = credentials.Certificate(cred_info) +firebase_admin.initialize_app(cred, {"databaseURL": os.getenv("DATABASE_URL")}) ref = db.reference("/") agenda_ref = ref.child('agenda') diff --git a/requirements.txt b/requirements.txt index 6af070e..4db9a8d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ fastapi[standard] firebase_admin -phonenumbers \ No newline at end of file +phonenumbers +python-dotenv \ No newline at end of file From 50d37010ace30937a361399d46ff11c7d8902926 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leandro=20C=C3=A2ndido?= <123888466+marshfellow42@users.noreply.github.com> Date: Sun, 29 Jun 2025 12:01:25 -0300 Subject: [PATCH 2/6] Update production.yml --- .github/workflows/production.yml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.github/workflows/production.yml b/.github/workflows/production.yml index f26c149..431b10d 100644 --- a/.github/workflows/production.yml +++ b/.github/workflows/production.yml @@ -17,16 +17,6 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.13.3' - - - name: Install Python dependencies - run: | - python3 -m pip install --upgrade pip - pip install -r requirements.txt - - name: Install Vercel CLI run: npm install --global vercel From 137f45086ac3a190358b614226400087d7caf463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leandro=20C=C3=A2ndido?= <123888466+marshfellow42@users.noreply.github.com> Date: Sun, 29 Jun 2025 12:01:42 -0300 Subject: [PATCH 3/6] Update preview.yml --- .github/workflows/preview.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index bffb9f9..6b478b8 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -13,7 +13,7 @@ jobs: Deploy-Preview: runs-on: ubuntu-latest steps: - + - name: Checkout repository - uses: actions/checkout@v3 - name: Install Vercel CLI @@ -26,4 +26,4 @@ jobs: run: vercel build --token=${{ secrets.VERCEL_TOKEN }} - name: Deploy Project Artifacts - run: vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }} + run: vercel deploy --prebuilt --archive=tgz --token=${{ secrets.VERCEL_TOKEN }} From e1dad1dfe92724b40e50f3d7e6fc6b5615f0d2cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leandro=20C=C3=A2ndido?= <123888466+marshfellow42@users.noreply.github.com> Date: Sun, 29 Jun 2025 12:16:43 -0300 Subject: [PATCH 4/6] Fixing preview.yml --- .github/workflows/preview.yml | 39 +++++++++++++++++------------------ 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 6b478b8..63bf7b0 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -1,29 +1,28 @@ name: Vercel Preview Deployment -env: - VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} - VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} - on: - push: - branches-ignore: - - main + push: + branches-ignore: + - main jobs: - Deploy-Preview: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - - uses: actions/checkout@v3 + Deploy-Preview: + runs-on: ubuntu-latest + env: + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + + steps: + - uses: actions/checkout@v3 - - name: Install Vercel CLI - run: npm install --global vercel + - name: Install Vercel CLI + run: npm install --global vercel - - name: Pull Vercel Environment Information - run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} + - name: Pull Vercel Environment Information + run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} - - name: Build Project Artifacts - run: vercel build --token=${{ secrets.VERCEL_TOKEN }} + - name: Build Project Artifacts + run: vercel build --token=${{ secrets.VERCEL_TOKEN }} - - name: Deploy Project Artifacts - run: vercel deploy --prebuilt --archive=tgz --token=${{ secrets.VERCEL_TOKEN }} + - name: Deploy Project Artifacts + run: vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }} From ad5e91ce8f77d3e1511ff6fbd4aecfbbd2fa2c5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leandro=20C=C3=A2ndido?= <123888466+marshfellow42@users.noreply.github.com> Date: Sun, 29 Jun 2025 12:17:05 -0300 Subject: [PATCH 5/6] Fixing production.yml --- .github/workflows/production.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/production.yml b/.github/workflows/production.yml index 431b10d..703f74c 100644 --- a/.github/workflows/production.yml +++ b/.github/workflows/production.yml @@ -1,9 +1,5 @@ name: Vercel Production Deployment -env: - VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} - VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} - on: push: branches: @@ -12,8 +8,11 @@ on: jobs: Deploy-Production: runs-on: ubuntu-latest - steps: + env: + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + steps: - name: Checkout repository uses: actions/checkout@v3 From d11a2dbf7887aa0ffc997b81aa38e6c1d4854cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leandro=20C=C3=A2ndido?= <123888466+marshfellow42@users.noreply.github.com> Date: Sun, 29 Jun 2025 12:18:38 -0300 Subject: [PATCH 6/6] damn --- .github/workflows/preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 63bf7b0..e7ab10f 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -25,4 +25,4 @@ jobs: run: vercel build --token=${{ secrets.VERCEL_TOKEN }} - name: Deploy Project Artifacts - run: vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }} + run: vercel deploy --prebuilt --archive=tgz --token=${{ secrets.VERCEL_TOKEN }}