From 758f63247229fa2f87d8a61033cf53c2c20eeaf0 Mon Sep 17 00:00:00 2001 From: bgn-dev <81875423+bgn-dev@users.noreply.github.com> Date: Thu, 11 Sep 2025 22:25:07 +0200 Subject: [PATCH 1/3] renamed existing workflows for client, added new workflow for server using gcloud --- ....yml => client-firebase-hosting-merge.yml} | 0 ... client-firebase-hosting-pull-request.yml} | 0 .github/workflows/gcloud-server-deploy.yml | 36 +++++++++++++++++++ .../workflows/gcloud-server-pull-request.yml | 30 ++++++++++++++++ 4 files changed, 66 insertions(+) rename .github/workflows/{firebase-hosting-merge.yml => client-firebase-hosting-merge.yml} (100%) rename .github/workflows/{firebase-hosting-pull-request.yml => client-firebase-hosting-pull-request.yml} (100%) create mode 100644 .github/workflows/gcloud-server-deploy.yml create mode 100644 .github/workflows/gcloud-server-pull-request.yml diff --git a/.github/workflows/firebase-hosting-merge.yml b/.github/workflows/client-firebase-hosting-merge.yml similarity index 100% rename from .github/workflows/firebase-hosting-merge.yml rename to .github/workflows/client-firebase-hosting-merge.yml diff --git a/.github/workflows/firebase-hosting-pull-request.yml b/.github/workflows/client-firebase-hosting-pull-request.yml similarity index 100% rename from .github/workflows/firebase-hosting-pull-request.yml rename to .github/workflows/client-firebase-hosting-pull-request.yml diff --git a/.github/workflows/gcloud-server-deploy.yml b/.github/workflows/gcloud-server-deploy.yml new file mode 100644 index 0000000..1b8a14e --- /dev/null +++ b/.github/workflows/gcloud-server-deploy.yml @@ -0,0 +1,36 @@ +name: Deploy to Cloud Run on merge +on: + push: + branches: + - main + +jobs: + build_and_deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + # Server-specific steps + - name: Setup Google Cloud SDK + uses: google-github-actions/setup-gcloud@v1 + with: + service_account_key: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }} + project_id: webnote-df968 + export_default_credentials: true + + - name: Configure Docker for GCR + run: gcloud auth configure-docker + + - name: Build and push Docker image + working-directory: ./server + run: | + gcloud builds submit --tag gcr.io/webnote-df968/webnote + + - name: Deploy to Cloud Run + run: | + gcloud run deploy webnote \ + --image gcr.io/webnote-df968/webnote \ + --region europe-west3 \ + --allow-unauthenticated \ + --set-env-vars FLASK_SECRET_KEY=${{ secrets.FLASK_SECRET_KEY }} \ + --set-env-vars FLASK_DEBUG=false \ No newline at end of file diff --git a/.github/workflows/gcloud-server-pull-request.yml b/.github/workflows/gcloud-server-pull-request.yml new file mode 100644 index 0000000..0251f5e --- /dev/null +++ b/.github/workflows/gcloud-server-pull-request.yml @@ -0,0 +1,30 @@ +name: Deploy to Cloud Run on PR +on: pull_request + +permissions: + checks: write + contents: read + pull-requests: write + +jobs: + build_and_preview: + if: ${{ github.event.pull_request.head.repo.full_name == github.repository }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + # Server-specific steps + - name: Setup Google Cloud SDK + uses: google-github-actions/setup-gcloud@v1 + with: + service_account_key: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }} + project_id: webnote-df968 + export_default_credentials: true + + - name: Configure Docker for GCR + run: gcloud auth configure-docker + + - name: Build Docker image + working-directory: ./server + run: | + gcloud builds submit --tag gcr.io/webnote-df968/webnote:pr-${{ github.event.number }} \ No newline at end of file From ce8c7ec1dca2b0e8c2aaac18cb1e19c6ba185a88 Mon Sep 17 00:00:00 2001 From: bgn-dev <81875423+bgn-dev@users.noreply.github.com> Date: Thu, 11 Sep 2025 22:25:49 +0200 Subject: [PATCH 2/3] Created a Docker setup for gcloud hosting --- server/Dockerfile | 33 +++++++++++++++++++++++++++++++++ server/requirements.txt | 7 +++++++ 2 files changed, 40 insertions(+) create mode 100644 server/Dockerfile create mode 100644 server/requirements.txt diff --git a/server/Dockerfile b/server/Dockerfile new file mode 100644 index 0000000..46d6a68 --- /dev/null +++ b/server/Dockerfile @@ -0,0 +1,33 @@ +# Use Python 3.11 slim image +FROM python:3.11-slim + +# Set working directory +WORKDIR /app + +# Install system dependencies +RUN apt-get update && apt-get install -y \ + gcc \ + && rm -rf /var/lib/apt/lists/* + +# Copy requirements first for better caching +COPY requirements.txt . + +# Install Python dependencies +RUN pip install --no-cache-dir -r requirements.txt + +# Copy application code +COPY . . + +# Create non-root user for security +RUN useradd --create-home --shell /bin/bash app && chown -R app:app /app +USER app + +# Expose port (Cloud Run uses PORT env var, defaults to 8080) +EXPOSE 8080 + +# Health check +HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ + CMD curl -f http://localhost:${PORT:-8080}/socket.io/ || exit 1 + +# Run with Gunicorn (use PORT env var from Cloud Run) +CMD gunicorn --worker-class eventlet -w 1 --bind 0.0.0.0:${PORT:-8080} signaling_server:app \ No newline at end of file diff --git a/server/requirements.txt b/server/requirements.txt new file mode 100644 index 0000000..6c5a122 --- /dev/null +++ b/server/requirements.txt @@ -0,0 +1,7 @@ +Flask==2.3.3 +Flask-SocketIO==5.3.6 +python-dotenv==1.0.0 +gunicorn==21.2.0 +eventlet==0.33.3 +python-engineio==4.7.1 +python-socketio==5.9.0 \ No newline at end of file From 5a0e86e15ba7937e5ef111a8ac3d044651b32efa Mon Sep 17 00:00:00 2001 From: bgn-dev <81875423+bgn-dev@users.noreply.github.com> Date: Thu, 11 Sep 2025 22:44:02 +0200 Subject: [PATCH 3/3] renamed file --- ...rver-deploy.yml => gcloud-server-deploy-merge.yml} | 11 ++++++----- ...uest.yml => gcloud-server-deploy-pull-request.yml} | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) rename .github/workflows/{gcloud-server-deploy.yml => gcloud-server-deploy-merge.yml} (81%) rename .github/workflows/{gcloud-server-pull-request.yml => gcloud-server-deploy-pull-request.yml} (77%) diff --git a/.github/workflows/gcloud-server-deploy.yml b/.github/workflows/gcloud-server-deploy-merge.yml similarity index 81% rename from .github/workflows/gcloud-server-deploy.yml rename to .github/workflows/gcloud-server-deploy-merge.yml index 1b8a14e..65a8633 100644 --- a/.github/workflows/gcloud-server-deploy.yml +++ b/.github/workflows/gcloud-server-deploy-merge.yml @@ -11,12 +11,13 @@ jobs: - uses: actions/checkout@v4 # Server-specific steps - - name: Setup Google Cloud SDK - uses: google-github-actions/setup-gcloud@v1 + - name: Authenticate to Google Cloud + uses: google-github-actions/auth@v1 with: - service_account_key: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }} - project_id: webnote-df968 - export_default_credentials: true + credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }} + + - name: Set up Google Cloud SDK + uses: google-github-actions/setup-gcloud@v1 - name: Configure Docker for GCR run: gcloud auth configure-docker diff --git a/.github/workflows/gcloud-server-pull-request.yml b/.github/workflows/gcloud-server-deploy-pull-request.yml similarity index 77% rename from .github/workflows/gcloud-server-pull-request.yml rename to .github/workflows/gcloud-server-deploy-pull-request.yml index 0251f5e..72e127c 100644 --- a/.github/workflows/gcloud-server-pull-request.yml +++ b/.github/workflows/gcloud-server-deploy-pull-request.yml @@ -14,12 +14,13 @@ jobs: - uses: actions/checkout@v4 # Server-specific steps - - name: Setup Google Cloud SDK - uses: google-github-actions/setup-gcloud@v1 + - name: Authenticate to Google Cloud + uses: google-github-actions/auth@v1 with: - service_account_key: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }} - project_id: webnote-df968 - export_default_credentials: true + credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }} + + - name: Set up Google Cloud SDK + uses: google-github-actions/setup-gcloud@v1 - name: Configure Docker for GCR run: gcloud auth configure-docker