From 05cf3f75af55b2aea7c1896f8776a4306497f08c Mon Sep 17 00:00:00 2001 From: Anusha Bhattacharya Date: Sun, 3 Nov 2024 07:04:30 +0530 Subject: [PATCH] changed to cloud run --- .env.prod | 2 +- .env.uat | 2 +- .github/workflows/firebase-hosting-merge.yml | 29 ++++++++++++------- .../firebase-hosting-pull-request.yml | 12 ++++---- Dockerfile | 20 +++++++++++++ src/index.ts | 2 +- 6 files changed, 47 insertions(+), 20 deletions(-) create mode 100644 Dockerfile diff --git a/.env.prod b/.env.prod index 39837a6..8a8449c 100644 --- a/.env.prod +++ b/.env.prod @@ -1,3 +1,3 @@ -PORT=3000 +PORT=8080 DATABASE_URL=${DATABASE_URL_PROD} JWT_SECRET=${JWT_SECRET_PROD} \ No newline at end of file diff --git a/.env.uat b/.env.uat index fdab1c2..88165b4 100644 --- a/.env.uat +++ b/.env.uat @@ -1,3 +1,3 @@ -PORT=3000 +PORT=8080 DATABASE_URL=${DATABASE_URL_UAT} JWT_SECRET=${JWT_SECRET_UAT} \ No newline at end of file diff --git a/.github/workflows/firebase-hosting-merge.yml b/.github/workflows/firebase-hosting-merge.yml index f20ddff..10c6629 100644 --- a/.github/workflows/firebase-hosting-merge.yml +++ b/.github/workflows/firebase-hosting-merge.yml @@ -1,11 +1,9 @@ -# This file was auto-generated by the Firebase CLI -# https://github.com/firebase/firebase-tools - -name: Deploy to Firebase Hosting on merge +name: Deploy to Cloud Run on merge on: push: branches: - main + jobs: build_and_deploy: runs-on: ubuntu-latest @@ -17,16 +15,25 @@ jobs: uses: actions/setup-node@v3 with: node-version: "23" + - name: Install dependencies run: npm install - name: Run build run: npm run build:prod - - name: Firebase Deploy - uses: FirebaseExtended/action-hosting-deploy@v0 - with: - repoToken: ${{ secrets.GITHUB_TOKEN }} - firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_BOOKENZY_F32CD }} - channelId: live - projectId: bookenzy-f32cd + # - name: Setup Google Cloud SDK + # uses: google-github-actions/setup-gcloud@v4 + # with: + # service_account_key: ${{ secrets.GCP_SA_KEY }} + # project_id: ${{ secrets.GCP_PROJECT_ID }} + # export_default_credentials: true + + # - name: Build and Deploy to Cloud Run + # run: | + # gcloud builds submit --tag gcr.io/${{ secrets.GCP_PROJECT_ID }}/your-image-name + # gcloud run deploy your-service-name \ + # --image gcr.io/${{ secrets.GCP_PROJECT_ID }}/your-image-name \ + # --platform managed \ + # --region your-region \ + # --allow-unauthenticated diff --git a/.github/workflows/firebase-hosting-pull-request.yml b/.github/workflows/firebase-hosting-pull-request.yml index dbe9a61..572e5b4 100644 --- a/.github/workflows/firebase-hosting-pull-request.yml +++ b/.github/workflows/firebase-hosting-pull-request.yml @@ -25,9 +25,9 @@ jobs: - name: Run build run: npm run build:prod - - name: Firebase Deploy - uses: FirebaseExtended/action-hosting-deploy@v0 - with: - repoToken: ${{ secrets.GITHUB_TOKEN }} - firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_BOOKENZY_F32CD }} - projectId: bookenzy-f32cd + # - name: Firebase Deploy + # uses: FirebaseExtended/action-hosting-deploy@v0 + # with: + # repoToken: ${{ secrets.GITHUB_TOKEN }} + # firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_BOOKENZY_F32CD }} + # projectId: bookenzy-f32cd diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8a91edc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +# Use the official Node.js image from Docker Hub. +FROM node:18 + +# Set the working directory inside the container. +WORKDIR /usr/src/app + +# Copy package.json and package-lock.json to the container. +COPY package*.json ./ + +# Install application dependencies. +RUN npm install + +# Copy the rest of your application code to the container. +COPY . . + +# Expose the port that your application will run on. +EXPOSE 8080 + +# Command to run your application. +CMD [ "npm", "start" ] diff --git a/src/index.ts b/src/index.ts index 318abbd..ee38609 100644 --- a/src/index.ts +++ b/src/index.ts @@ -34,7 +34,7 @@ app.use("/v1/books", bookRoutes); app.use("/v1/logs", logRoutes); // Start the server -const PORT = process.env.PORT || 3000; +const PORT = process.env.PORT || 8080; app.listen(PORT, () => { console.log(`Server is running on port ${PORT}`); });