diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml deleted file mode 100644 index da356c3..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 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 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