From 5fc996e3ef50517ce3280cfb4dd6233be893b39c Mon Sep 17 00:00:00 2001 From: Septianata Rizky Pratama Date: Tue, 23 Jul 2024 11:11:53 +0700 Subject: [PATCH] feat: setup deployment using vercel --- .env.example | 1 + .github/workflows/deploy.yml | 133 +++++++++++++++++++++++++++++++++++ src/database/schema.prisma | 5 +- vercel.json | 6 ++ 4 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/deploy.yml create mode 100644 vercel.json diff --git a/.env.example b/.env.example index 20d8556..1a86aba 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,7 @@ NODE_ENV=development DB_URL=postgresql://root@localhost:5432/push_notification_nextjs_firebase +DB_URL_NON_POOLING= # optional FIREBASE_ADMIN_TYPE= FIREBASE_ADMIN_PROJECT_ID= diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..bd88755 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,133 @@ +# https://dev.to/chuddyjoachim/nextjs-ci-cd-on-vercel-with-github-actions-7g7 +name: Deploy to Vercel + +on: + push: + branches: + - "main" + +jobs: + vercel: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: dkershner6/vercel-set-env-action@v3.0.3 + with: + token: ${{ secrets.VERCEL_TOKEN }} + teamId: ${{ secrets.VERCEL_TEAM_ID }} # optional, without will use personal + projectName: push-notification-nextjs-firebase # project name in Vercel + envVariableKeys: >- + DB_URL, + DB_URL_NON_POOLING, + FIREBASE_ADMIN_TYPE, + FIREBASE_ADMIN_PROJECT_ID, + FIREBASE_ADMIN_PRIVATE_KEY_ID, + FIREBASE_ADMIN_PRIVATE_KEY, + FIREBASE_ADMIN_CLIENT_EMAIL, + FIREBASE_ADMIN_CLIENT_ID, + FIREBASE_ADMIN_AUTH_URI, + FIREBASE_ADMIN_TOKEN_URI, + FIREBASE_ADMIN_AUTH_PROVIDER_X509_CERT_URL, + FIREBASE_ADMIN_CLIENT_X509_CERT_URL, + FIREBASE_ADMIN_UNIVERSE_DOMAIN, + NEXT_PUBLIC_FIREBASE_API_KEY, + NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN, + NEXT_PUBLIC_FIREBASE_PROJECT_ID, + NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET, + NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID, + NEXT_PUBLIC_FIREBASE_APP_ID, + NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID, + NEXT_PUBLIC_FIREBASE_FCM_VAPID_KEY + env: + DB_URL: ${{ secrets.DB_URL }} + TARGET_DB_URL: preview,development,production # comma delimited, one of [production, preview, development] + TYPE_DB_URL: encrypted # one of [plain, encrypted] + + DB_URL_NON_POOLING: ${{ secrets.DB_URL_NON_POOLING }} + TARGET_DB_URL_NON_POOLING: preview,development,production + TYPE_DB_URL_NON_POOLING: encrypted + + FIREBASE_ADMIN_TYPE: ${{ secrets.FIREBASE_ADMIN_TYPE }} + TARGET_FIREBASE_ADMIN_TYPE: preview,development,production + TYPE_FIREBASE_ADMIN_TYPE: encrypted + + FIREBASE_ADMIN_PROJECT_ID: ${{ secrets.FIREBASE_ADMIN_PROJECT_ID }} + TARGET_FIREBASE_ADMIN_PROJECT_ID: preview,development,production + TYPE_FIREBASE_ADMIN_PROJECT_ID: encrypted + + FIREBASE_ADMIN_PRIVATE_KEY_ID: ${{ secrets.FIREBASE_ADMIN_PRIVATE_KEY_ID }} + TARGET_FIREBASE_ADMIN_PRIVATE_KEY_ID: preview,development,production + TYPE_FIREBASE_ADMIN_PRIVATE_KEY_ID: encrypted + + FIREBASE_ADMIN_PRIVATE_KEY: ${{ secrets.FIREBASE_ADMIN_PRIVATE_KEY }} + TARGET_FIREBASE_ADMIN_PRIVATE_KEY: preview,development,production + TYPE_FIREBASE_ADMIN_PRIVATE_KEY: encrypted + + FIREBASE_ADMIN_CLIENT_EMAIL: ${{ secrets.FIREBASE_ADMIN_CLIENT_EMAIL }} + TARGET_FIREBASE_ADMIN_CLIENT_EMAIL: preview,development,production + TYPE_FIREBASE_ADMIN_CLIENT_EMAIL: encrypted + + FIREBASE_ADMIN_CLIENT_ID: ${{ secrets.FIREBASE_ADMIN_CLIENT_ID }} + TARGET_FIREBASE_ADMIN_CLIENT_ID: preview,development,production + TYPE_FIREBASE_ADMIN_CLIENT_ID: encrypted + + FIREBASE_ADMIN_AUTH_URI: ${{ secrets.FIREBASE_ADMIN_AUTH_URI }} + TARGET_FIREBASE_ADMIN_AUTH_URI: preview,development,production + TYPE_FIREBASE_ADMIN_AUTH_URI: encrypted + + FIREBASE_ADMIN_TOKEN_URI: ${{ secrets.FIREBASE_ADMIN_TOKEN_URI }} + TARGET_FIREBASE_ADMIN_TOKEN_URI: preview,development,production + TYPE_FIREBASE_ADMIN_TOKEN_URI: encrypted + + FIREBASE_ADMIN_AUTH_PROVIDER_X509_CERT_URL: ${{ secrets.FIREBASE_ADMIN_AUTH_PROVIDER_X509_CERT_URL }} + TARGET_FIREBASE_ADMIN_AUTH_PROVIDER_X509_CERT_URL: preview,development,production + TYPE_FIREBASE_ADMIN_AUTH_PROVIDER_X509_CERT_URL: encrypted + + FIREBASE_ADMIN_CLIENT_X509_CERT_URL: ${{ secrets.FIREBASE_ADMIN_CLIENT_X509_CERT_URL }} + TARGET_FIREBASE_ADMIN_CLIENT_X509_CERT_URL: preview,development,production + TYPE_FIREBASE_ADMIN_CLIENT_X509_CERT_URL: encrypted + + FIREBASE_ADMIN_UNIVERSE_DOMAIN: ${{ secrets.FIREBASE_ADMIN_UNIVERSE_DOMAIN }} + TARGET_FIREBASE_ADMIN_UNIVERSE_DOMAIN: preview,development,production + TYPE_FIREBASE_ADMIN_UNIVERSE_DOMAIN: encrypted + + NEXT_PUBLIC_FIREBASE_API_KEY: ${{ secrets.NEXT_PUBLIC_FIREBASE_API_KEY }} + TARGET_NEXT_PUBLIC_FIREBASE_API_KEY: preview,development,production + TYPE_NEXT_PUBLIC_FIREBASE_API_KEY: encrypted + + NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN: ${{ secrets.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN }} + TARGET_NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN: preview,development,production + TYPE_NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN: encrypted + + NEXT_PUBLIC_FIREBASE_PROJECT_ID: ${{ secrets.NEXT_PUBLIC_FIREBASE_PROJECT_ID }} + TARGET_NEXT_PUBLIC_FIREBASE_PROJECT_ID: preview,development,production + TYPE_NEXT_PUBLIC_FIREBASE_PROJECT_ID: encrypted + + NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET: ${{ secrets.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET }} + TARGET_NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET: preview,development,production + TYPE_NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET: encrypted + + NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID: ${{ secrets.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID }} + TARGET_NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID: preview,development,production + TYPE_NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID: encrypted + + NEXT_PUBLIC_FIREBASE_APP_ID: ${{ secrets.NEXT_PUBLIC_FIREBASE_APP_ID }} + TARGET_NEXT_PUBLIC_FIREBASE_APP_ID: preview,development,production + TYPE_NEXT_PUBLIC_FIREBASE_APP_ID: encrypted + + NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID: ${{ secrets.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID }} + TARGET_NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID: preview,development,production + TYPE_NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID: encrypted + + NEXT_PUBLIC_FIREBASE_FCM_VAPID_KEY: ${{ secrets.NEXT_PUBLIC_FIREBASE_FCM_VAPID_KEY }} + TARGET_NEXT_PUBLIC_FIREBASE_FCM_VAPID_KEY: preview,development,production + TYPE_NEXT_PUBLIC_FIREBASE_FCM_VAPID_KEY: encrypted + + - uses: amondnet/vercel-action@v25.2.0 + with: + vercel-token: ${{ secrets.VERCEL_TOKEN }} # Required + github-token: ${{ secrets.GITHUB_TOKEN }} # Optional + vercel-args: "--prod" # Optional + vercel-org-id: ${{ secrets.VERCEL_ORG_ID}} # Required + vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID}} # Required diff --git a/src/database/schema.prisma b/src/database/schema.prisma index 0096891..9e38ef9 100644 --- a/src/database/schema.prisma +++ b/src/database/schema.prisma @@ -6,8 +6,9 @@ generator client { } datasource db { - provider = "postgresql" - url = env("DB_URL") + provider = "postgresql" + url = env("DB_URL") + directUrl = env("DB_URL_NON_POOLING") } model Subscription { diff --git a/vercel.json b/vercel.json new file mode 100644 index 0000000..a892b5d --- /dev/null +++ b/vercel.json @@ -0,0 +1,6 @@ +{ + "version": 2, + "github": { + "enabled": false + } +}