From 84c814a928940e21e7798c6ec1a9eb3f4a12dd55 Mon Sep 17 00:00:00 2001 From: sattwyk Date: Mon, 28 Oct 2024 18:18:20 +0530 Subject: [PATCH 1/4] fix credentials_json --- .github/workflows/deploy.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index da356c3..ab0381f 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -24,7 +24,7 @@ jobs: name: 'Authenticate to Google Cloud' uses: 'google-github-actions/auth@v2' with: - credentials_json: '${{ secrets.GCP_SA_KEY }}' + credentials_json: ${{ secrets.GCP_SA_KEY }} - name: 'Set up Cloud SDK' uses: 'google-github-actions/setup-gcloud@v2' From a512d65fbf5ca6ef04c870b08feb83dc2dac3b2f Mon Sep 17 00:00:00 2001 From: sattwyk Date: Tue, 5 Nov 2024 16:14:44 +0530 Subject: [PATCH 2/4] update Dockerfile --- bot/Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bot/Dockerfile b/bot/Dockerfile index 0320513..7464204 100644 --- a/bot/Dockerfile +++ b/bot/Dockerfile @@ -1,7 +1,7 @@ # Use the official Python image as the base image FROM python:3.10-slim-bookworm AS base -# Install uv +# Copy uv binaries COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ # Set environment variables @@ -15,17 +15,17 @@ ENV PORT=8080 # Set the working directory WORKDIR /app -# Copy only the necessary files for dependency installation +# Copy dependency files for installation COPY pyproject.toml uv.lock ./ # Install dependencies RUN --mount=type=cache,target=/root/.cache/uv \ uv pip install --system -r pyproject.toml -# Copy the rest of the application code +# Copy the main application file COPY bot.py ./ -# Compile bytecode +# Compile bytecode (this step might be redundant if UV_COMPILE_BYTECODE is set) RUN python -m compileall . # Expose the port the app runs on From 6c81dee2863183acec5efa6ab75448e17996a268 Mon Sep 17 00:00:00 2001 From: sattwyk Date: Tue, 5 Nov 2024 16:33:57 +0530 Subject: [PATCH 3/4] feat: add Cloud Build configuration --- cloudbuild.yaml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 cloudbuild.yaml diff --git a/cloudbuild.yaml b/cloudbuild.yaml new file mode 100644 index 0000000..a9331c2 --- /dev/null +++ b/cloudbuild.yaml @@ -0,0 +1,35 @@ +steps: + # Build the Docker image + - name: 'gcr.io/cloud-builders/docker' + args: + - 'build' + - '-t' + - 'gcr.io/$PROJECT_ID/discord-bot:$COMMIT_SHA' + - '-f' + - 'bot/Dockerfile' + - 'bot' + env: + - 'DOCKER_BUILDKIT=1' + + # Push the image to Container Registry + - name: 'gcr.io/cloud-builders/docker' + args: + - 'push' + - 'gcr.io/$PROJECT_ID/discord-bot:$COMMIT_SHA' + + # Deploy to Cloud Run + - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk' + entrypoint: gcloud + args: + - 'run' + - 'deploy' + - 'discord-bot' + - '--image' + - 'gcr.io/$PROJECT_ID/discord-bot:$COMMIT_SHA' + - '--region' + - 'us-central1' + - '--platform' + - 'managed' + +images: + - 'gcr.io/$PROJECT_ID/discord-bot:$COMMIT_SHA' \ No newline at end of file From 9df48b3b9914f0cc5cd100a0d1fca3ec6d30c78d Mon Sep 17 00:00:00 2001 From: sattwyk Date: Tue, 5 Nov 2024 16:36:06 +0530 Subject: [PATCH 4/4] chore: remove Cloud Run deployment workflow --- .github/workflows/deploy.yaml | 48 ----------------------------------- 1 file changed, 48 deletions(-) delete mode 100644 .github/workflows/deploy.yaml diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml deleted file mode 100644 index ab0381f..0000000 --- a/.github/workflows/deploy.yaml +++ /dev/null @@ -1,48 +0,0 @@ -name: Deploy to Cloud Run - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -env: - PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} - SERVICE_NAME: discord-bot - -jobs: - deploy: - runs-on: ubuntu-latest - permissions: - contents: 'read' - id-token: 'write' - - steps: - - uses: actions/checkout@v4 - - - id: 'auth' - name: 'Authenticate to Google Cloud' - uses: 'google-github-actions/auth@v2' - with: - credentials_json: ${{ secrets.GCP_SA_KEY }} - - - name: 'Set up Cloud SDK' - uses: 'google-github-actions/setup-gcloud@v2' - - - name: Configure Docker - run: gcloud auth configure-docker - - - name: Build and Push Docker image - run: | - echo "Building image for project: $PROJECT_ID" - docker build -t gcr.io/$PROJECT_ID/$SERVICE_NAME:${{ github.sha }} ./bot - docker push gcr.io/$PROJECT_ID/$SERVICE_NAME:${{ github.sha }} - - - name: Deploy to Cloud Run - run: | - gcloud run deploy $SERVICE_NAME \ - --image gcr.io/$PROJECT_ID/$SERVICE_NAME:${{ github.sha }} \ - --platform managed \ - --region asia-south1 \ - --allow-unauthenticated \ - --set-env-vars="DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }},RESEND_API_KEY=${{ secrets.RESEND_API_KEY }},UPSTASH_REDIS_REST_URL=${{ secrets.UPSTASH_REDIS_REST_URL }},UPSTASH_REDIS_REST_TOKEN=${{ secrets.UPSTASH_REDIS_REST_TOKEN }}" \ No newline at end of file