Skip to content

update .gitignore

update .gitignore #27

name: Backend Deploy v2
on:
push:
branches: [main, prod]
paths:
- "backend/**"
- ".github/workflows/backend-deploy.yml"
pull_request:
branches: [main]
paths:
- "backend/**"
env:
BACKEND_DIR: backend
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- name: Set up environment variables
id: env
run: |
if [[ ${{ github.ref }} == 'refs/heads/prod' ]]; then
echo "ENVIRONMENT=production" >> $GITHUB_ENV
else
echo "ENVIRONMENT=development" >> $GITHUB_ENV
fi
echo "GCP_PROJECT=${{ secrets.GCP_DEV_PROJECT_ID }}" >> $GITHUB_ENV
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
cache: "pip"
cache-dependency-path: ${{ env.BACKEND_DIR }}/requirements.txt
- name: Install Dependencies
working-directory: ${{ env.BACKEND_DIR }}
run: pip install -r requirements.txt
- name: Google Auth
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.GCP_SA_EMAIL }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
- name: Prepare deployment files
working-directory: ${{ env.BACKEND_DIR }}
run: |
# Create Dockerfile for Python/FastAPI backend
cat > Dockerfile << 'EOL'
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
ENV PORT=8080
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]
EOL
# Create .gcloudignore
cat > .gcloudignore << 'EOL'
.git
.gitignore
__pycache__
*.pyc
.env*
.vscode
.github
venv/
README.md
!requirements.txt
!main.py
!gemini_helper.py
!docs_helper.py
!Dockerfile
EOL
# Verify files
echo "Checking for required files:"
ls -la Dockerfile
- name: Deploy to Cloud Run
id: deploy
run: |
echo "Starting deployment process..."
cd ${{ env.BACKEND_DIR }}
gcloud run deploy backend \
--source . \
--platform managed \
--region me-west1 \
--project ${{ env.GCP_PROJECT }} \
--allow-unauthenticated \
--port=8080 \
--min-instances=0 \
--max-instances=4 \
--memory=512Mi \
--timeout=300 \
--service-account=${{ secrets.GCP_SA_EMAIL }} \
--set-env-vars="ENVIRONMENT=${{ env.ENVIRONMENT }},\
GEMINI_API_KEY=${{ secrets.GEMINI_API_KEY }},\
EMAIL_ADDRESS=${{ secrets.EMAIL_ADDRESS }},\
EMAIL_PASSWORD=${{ secrets.EMAIL_PASSWORD }},\
YOUR_EMAIL=${{ secrets.YOUR_EMAIL }}" \
--labels="managed-by=github-actions,commit-sha=${{ github.sha }}" \
--quiet
- name: Install Beta Components
run: gcloud components install beta --quiet
- name: Map Custom Domain
if: github.ref == 'refs/heads/prod' || github.ref == 'refs/heads/main'
run: |
DOMAIN="${{ github.ref == 'refs/heads/prod' && secrets.PROD_DOMAIN || secrets.DEV_DOMAIN }}"
gcloud beta run domain-mappings create \
--service backend \
--domain api.$DOMAIN \
--region me-west1 \
--quiet || echo "Domain mapping failed but continuing deployment"