Skip to content

Commit

Permalink
Fix deploy functions 16
Browse files Browse the repository at this point in the history
  • Loading branch information
yevkim committed Nov 27, 2024
1 parent c19b58b commit 580f39d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 29 deletions.
20 changes: 14 additions & 6 deletions .github/workflows/deploy_functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ jobs:
# Step 1: Checkout the code
- uses: actions/checkout@v3

# Step 1.5: Environment variables
- name: create env file
working-directory: backend
run: |
cd functions
touch .env
echo "${{ secrets.FUNCTIONS_ENV_VARS }}" >> .env
# Step 2: Set up Python environment
- name: Set up Python
uses: actions/setup-python@v4
Expand All @@ -26,10 +34,10 @@ jobs:
node-version: 19.7.0

# Step 4: Create Service Account Key and Set Env Variables
- name: Create SA key and set env variables
run: |
echo '${{ secrets.FIREBASE_SERVICE_ACCOUNT_SCHEMESSG_V3_DEV }}' > ${{ runner.temp }}/gcloud.json
echo "GOOGLE_APPLICATION_CREDENTIALS=${{ runner.temp }}/gcloud.json" >> $GITHUB_ENV
# - name: Create SA key and set env variables
# run: |
# echo '${{ secrets.FIREBASE_SERVICE_ACCOUNT_SCHEMESSG_V3_DEV }}' > ${{ runner.temp }}/gcloud.json
# echo "GOOGLE_APPLICATION_CREDENTIALS=${{ runner.temp }}/gcloud.json" >> $GITHUB_ENV

# Step 5: Prepare the environment
- name: Prepare the environment
Expand All @@ -43,6 +51,6 @@ jobs:
# Step 6: deploy functions
- name: Deploy functions
working-directory: backend
env:
GOOGLE_APPLICATION_CREDENTIALS: ${{ runner.temp }}/gcloud.json
# env:
# GOOGLE_APPLICATION_CREDENTIALS: ${{ runner.temp }}/gcloud.json
run: npx firebase-tools deploy --only functions --debug --token "${{ secrets.FIREBASE_TOKEN_SCHEMESSG_V3_DEV }}"
46 changes: 23 additions & 23 deletions backend/functions/fb_manager/firebaseManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,29 @@ def _initialize_app(self):

if not firebase_admin._apps:
# Replace newlines in private key
# private_key = os.getenv("FB_PRIVATE_KEY").replace("\\n", "\n")
path_to_creds = os.getenv("GOOGLE_APPLICATION_CREDENTIALS")

if not path_to_creds or not os.path.exists(path_to_creds):
raise ValueError(f"Invalid certificate path: {path_to_creds}. Make sure GOOGLE_APPLICATION_CREDENTIALS is set properly.")

cred = credentials.Certificate(path_to_creds) # Adjust path as needed

# cred = credentials.Certificate(
# {
# "type": os.getenv("FB_TYPE"),
# "project_id": os.getenv("FB_PROJECT_ID"),
# "private_key_id": os.getenv("FB_PRIVATE_KEY_ID"),
# "private_key": private_key, # Use the processed private key
# "client_email": os.getenv("FB_CLIENT_EMAIL"),
# "client_id": os.getenv("FB_CLIENT_ID"),
# "auth_uri": os.getenv("FB_AUTH_URI"),
# "token_uri": os.getenv("FB_TOKEN_URI"),
# "auth_provider_x509_cert_url": os.getenv("FB_AUTH_PROVIDER_X509_CERT_URL"),
# "client_x509_cert_url": os.getenv("FB_CLIENT_X509_CERT_URL"),
# "universe_domain": os.getenv("FB_UNIVERSE_DOMAIN"),
# }
# )
private_key = os.getenv("FB_PRIVATE_KEY").replace("\\n", "\n")
# path_to_creds = os.getenv("GOOGLE_APPLICATION_CREDENTIALS")

# if not path_to_creds or not os.path.exists(path_to_creds):
# raise ValueError(f"Invalid certificate path: {path_to_creds}. Make sure GOOGLE_APPLICATION_CREDENTIALS is set properly.")

# cred = credentials.Certificate(path_to_creds) # Adjust path as needed

cred = credentials.Certificate(
{
"type": os.getenv("FB_TYPE"),
"project_id": os.getenv("FB_PROJECT_ID"),
"private_key_id": os.getenv("FB_PRIVATE_KEY_ID"),
"private_key": private_key, # Use the processed private key
"client_email": os.getenv("FB_CLIENT_EMAIL"),
"client_id": os.getenv("FB_CLIENT_ID"),
"auth_uri": os.getenv("FB_AUTH_URI"),
"token_uri": os.getenv("FB_TOKEN_URI"),
"auth_provider_x509_cert_url": os.getenv("FB_AUTH_PROVIDER_X509_CERT_URL"),
"client_x509_cert_url": os.getenv("FB_CLIENT_X509_CERT_URL"),
"universe_domain": os.getenv("FB_UNIVERSE_DOMAIN"),
}
)
initialize_app(cred)

self.firestore_client = firestore.client()

0 comments on commit 580f39d

Please sign in to comment.