From a7577d1eee919c368c3f5b7c06855a34c05024d9 Mon Sep 17 00:00:00 2001 From: Taron Date: Tue, 23 Jul 2024 20:16:18 +0400 Subject: [PATCH 01/10] test backend build workflow --- .../actions/setup-wrangler-toml/action.yml | 56 ++++++++++++++++ .github/workflows/backend-preview.yml | 67 +++++++++++++++++++ .github/workflows/backend.yml | 12 +++- server/package.json | 14 ++-- server/src/index.ts | 2 + 5 files changed, 141 insertions(+), 10 deletions(-) create mode 100644 .github/actions/setup-wrangler-toml/action.yml create mode 100644 .github/workflows/backend-preview.yml diff --git a/.github/actions/setup-wrangler-toml/action.yml b/.github/actions/setup-wrangler-toml/action.yml new file mode 100644 index 000000000..881547daa --- /dev/null +++ b/.github/actions/setup-wrangler-toml/action.yml @@ -0,0 +1,56 @@ +name: 'Generate Wrangler TOML' +description: 'Generates the wrangler.toml file for Cloudflare Workers' +runs: + using: 'composite' + steps: + - name: Generate wrangler.toml + run: | + echo 'name = "packrat-api-staging"' > ${{ github.workspace }}/server/wrangler.toml + echo 'main = "src/index.ts"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'compatibility_date = "2024-03-14"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'node_compat = true' >> ${{ github.workspace }}/server/wrangler.toml + echo '[ai]' >> ${{ github.workspace }}/server/wrangler.toml + echo 'binding = "AI"' >> ${{ github.workspace }}/server/wrangler.toml + echo '[[vectorize]]' >> ${{ github.workspace }}/server/wrangler.toml + echo 'binding = "VECTOR_INDEX"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'index_name = "vector-index"' >> ${{ github.workspace }}/server/wrangler.toml + echo '[env.preview]' >> ${{ github.workspace }}/server/wrangler.toml + echo '[[env.preview.d1_databases]]' >> ${{ github.workspace }}/server/wrangler.toml + echo 'binding = "DB"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'database_name = "preview"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'database_id = "${{ secrets.PREVIEW_DB_ID }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo '[env.preview.vars]' >> ${{ github.workspace }}/server/wrangler.toml + echo 'NODE_ENV = "preview"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'GOOGLE_CLIENT_ID = "${{ secrets.GOOGLE_CLIENT_ID }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'GOOGLE_CLIENT_SECRET = "${{ secrets.GOOGLE_CLIENT_SECRET }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'STMP_EMAIL = "${{ secrets.STMP_EMAIL }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'STMP_PASSWORD = "${{ secrets.STMP_PASSWORD }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'JWT_SECRET = "${{ secrets.JWT_SECRET }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'SEND_GRID_API_KEY = "${{ secrets.SEND_GRID_API_KEY }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'MAPBOX_ACCESS_TOKEN = "${{ secrets.MAPBOX_ACCESS_TOKEN }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'OSM_URI = "https://overpass-api.de/api/interpreter"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'WEATHER_URL = "https://api.openweathermap.org/data/2.5/forecast"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'OPENWEATHER_KEY = "${{ secrets.OPENWEATHER_KEY }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'VECTORIZE_API_KEY = "${{ secrets.VECTORIZE_API_KEY }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'CLOUDFLARE_ACCOUNT_ID = "${{ secrets.CLOUDFLARE_ACCOUNT_ID }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'OPENAI_API_KEY = "${{ secrets.OPENAI_API_KEY }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo '[env.production]' >> ${{ github.workspace }}/server/wrangler.toml + echo '[[env.production.d1_databases]]' >> ${{ github.workspace }}/server/wrangler.toml + echo 'binding = "DB"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'database_name = "production"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'database_id = "${{ secrets.PRODUCTION_DB_ID }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo '[env.production.vars]' >> ${{ github.workspace }}/server/wrangler.toml + echo 'NODE_ENV = "production"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'GOOGLE_CLIENT_ID = "${{ secrets.GOOGLE_CLIENT_ID }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'GOOGLE_CLIENT_SECRET = "${{ secrets.GOOGLE_CLIENT_SECRET }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'STMP_EMAIL = "${{ secrets.STMP_EMAIL }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'STMP_PASSWORD = "${{ secrets.STMP_PASSWORD }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'JWT_SECRET = "${{ secrets.JWT_SECRET }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'SEND_GRID_API_KEY = "${{ secrets.SEND_GRID_API_KEY }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'MAPBOX_ACCESS_TOKEN = "${{ secrets.MAPBOX_ACCESS_TOKEN }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'OSM_URI = "https://overpass-api.de/api/interpreter"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'WEATHER_URL = "https://api.openweathermap.org/data/2.5/forecast"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'OPENWEATHER_KEY = "${{ secrets.OPENWEATHER_KEY }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'VECTORIZE_API_KEY = "${{ secrets.VECTORIZE_API_KEY }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'CLOUDFLARE_ACCOUNT_ID = "${{ secrets.CLOUDFLARE_ACCOUNT_ID }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'OPENAI_API_KEY = "${{ secrets.OPENAI_API_KEY }}"' >> ${{ github.workspace }}/server/wrangler.toml diff --git a/.github/workflows/backend-preview.yml b/.github/workflows/backend-preview.yml new file mode 100644 index 000000000..54718776b --- /dev/null +++ b/.github/workflows/backend-preview.yml @@ -0,0 +1,67 @@ +name: 'Backend Preview Deployment' + +on: + workflow_dispatch: + pull_request: + branches: + - feat/preview-version-of-api + types: [closed] + push: + branches: + - feat/preview-version-of-api + paths: + - 'packages/validations/**' + - 'packages/shared-types/**' + - 'server/**' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + deploy: + name: Deploy to Cloudflare Workers + runs-on: ubuntu-latest + timeout-minutes: 10 + + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + fetch-depth: 1 + + - name: Setup JS Runtime environment + uses: ./.github/actions/setup-js-runtime + + - name: Install dependencies + uses: ./.github/actions/install-deps + + - name: Generate wrangler.toml + uses: ./.github/actions/setup-wrangler-toml + + - name: Migrate database + # run: cd packages/api && bun run migrate + run: cd server && yarn run migrate:preview + env: + NO_D1_WARNING: true + CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }} + + - name: Deploy + uses: cloudflare/wrangler-action@v3.3.2 + with: + wranglerVersion: '3.15.0' + apiToken: ${{ secrets.CF_API_TOKEN }} + # workingDirectory: packages/api + workingDirectory: server + command: yarn run deploy:preview + # packageManager: bun + packageManager: yarn + secrets: | + APP_URL + JWT_VERIFICATION_KEY + CI + env: + APP_URL: ${{ secrets.VITE_PUBLIC_APP_URL }} + JWT_VERIFICATION_KEY: ${{ secrets.JWT_SECRET }} + CI: true + NO_D1_WARNING: true diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 78a13d507..0cb462d85 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -2,19 +2,23 @@ name: 'Backend Deployment' on: workflow_dispatch: + pull_request: + branches: + - master + types: [closed] push: branches: - master - andrew_testing paths: - - 'packages/api/**' + - 'packages/validations/**' + - 'packages/shared-types/**' - 'server/**' concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true - jobs: deploy: name: Deploy to Cloudflare Workers @@ -33,6 +37,9 @@ jobs: - name: Install dependencies uses: ./.github/actions/install-deps + - name: Generate wrangler.toml + uses: ./.github/actions/setup-wrangler-toml + - name: Migrate database # run: cd packages/api && bun run migrate run: cd server && yarn run migrate:prod @@ -45,7 +52,6 @@ jobs: with: wranglerVersion: '3.15.0' apiToken: ${{ secrets.CF_API_TOKEN }} - # workingDirectory: packages/api workingDirectory: server command: yarn run deploy:prod # packageManager: bun diff --git a/server/package.json b/server/package.json index d4dd26cb2..bb005149c 100644 --- a/server/package.json +++ b/server/package.json @@ -9,19 +9,19 @@ "clean": "rm -rf node_modules", "debug": "cross-env NODE_OPTIONS='--inspect-brk' nodemon", "deploy:minify": "wrangler deploy --minify src/index.ts", - "deploy:prod": "yarn deploy", - "deploy": "wrangler deploy src/index.ts", + "deploy:preview": "wrangler deploy src/index.ts --env preview", + "deploy:prod": "wrangler deploy src/index.ts --env production", "dev": "nodemon", "generate": "drizzle-kit generate:sqlite --schema=./src/db/schema.ts --out=./migrations", "lint": "eslint . --fix --ext .ts", "migrate:down:local": "drizzle-kit drop", "migrate:down": "yarn run migrate:down:local", - "migrate:local": "wrangler d1 migrations apply production --local", - "migrate:prod": "wrangler d1 migrations apply production --remote", + "migrate:local": "wrangler d1 migrations apply preview --local --env preview", + "migrate:prod": "wrangler d1 migrations apply production --remote --env production", "migrate": "yarn run migrate:local", "postinstall": "yarn generate", - "seed:local": "wrangler d1 execute production --local --file=./seed/seed.sql", - "seed": "wrangler d1 execute production --file=./seed/seed.sql", + "seed:local": "wrangler d1 execute preview --local --file=./seed/seed.sql --env preview", + "seed": "wrangler d1 execute production --file=./seed/seed.sql --env production", "setup:local": "yarn generate && yarn migrate:local && yarn seed:local", "setup": "echo \"No setup needed\"", "start:pm2": "pm2 start dist/index.js --name server", @@ -32,7 +32,7 @@ "test:expect": "mocha 'generated/test/**/*.spec.js'", "test:generate": "npx openapi-generator url http://localhost:3000/swagger.json -d ./generated -t javascript", "test": "vitest spec", - "wrangler:dev": "npx wrangler dev --port 8787 --local", + "wrangler:dev": "npx wrangler dev --port 8787 --local --env preview", "wrangler:dev2": "npx wrangler pages dev --proxy 3001 --local --persist-to=./db.sqlite --d1=DB -- npm run dev" }, "author": "Andrew Bierman", diff --git a/server/src/index.ts b/server/src/index.ts index 27832296f..8bbe78c92 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -53,6 +53,8 @@ app.use('*', async (c, next) => { allowHeaders: ['Content-Type', 'Authorization'], allowMethods: CORS_METHODS, }); + // change for testing the workflow + console.log('CORS middleware setup'); return corsMiddleware(c, next); }); From 6f02250b44c0e4e41affac466fe2a17d47d9ab66 Mon Sep 17 00:00:00 2001 From: Taron Date: Tue, 23 Jul 2024 21:07:41 +0400 Subject: [PATCH 02/10] fix generate wrangler toml action --- .github/actions/setup-wrangler-toml/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/setup-wrangler-toml/action.yml b/.github/actions/setup-wrangler-toml/action.yml index 881547daa..5ac94e01d 100644 --- a/.github/actions/setup-wrangler-toml/action.yml +++ b/.github/actions/setup-wrangler-toml/action.yml @@ -4,6 +4,7 @@ runs: using: 'composite' steps: - name: Generate wrangler.toml + shell: bash run: | echo 'name = "packrat-api-staging"' > ${{ github.workspace }}/server/wrangler.toml echo 'main = "src/index.ts"' >> ${{ github.workspace }}/server/wrangler.toml From 80df7f88958f816b0e9df699748aa21f76bd5d73 Mon Sep 17 00:00:00 2001 From: Taron Date: Wed, 24 Jul 2024 01:36:40 +0400 Subject: [PATCH 03/10] fix wrangler generation action inputs --- .../actions/setup-wrangler-toml/action.yml | 121 ++++++++++++++---- .github/workflows/backend-preview.yml | 25 ++++ .github/workflows/backend.yml | 25 ++++ 3 files changed, 147 insertions(+), 24 deletions(-) diff --git a/.github/actions/setup-wrangler-toml/action.yml b/.github/actions/setup-wrangler-toml/action.yml index 5ac94e01d..117464d96 100644 --- a/.github/actions/setup-wrangler-toml/action.yml +++ b/.github/actions/setup-wrangler-toml/action.yml @@ -1,5 +1,78 @@ name: 'Generate Wrangler TOML' description: 'Generates the wrangler.toml file for Cloudflare Workers' +inputs: + GOOGLE_CLIENT_ID: + description: 'Google Client ID' + required: true + GOOGLE_CLIENT_SECRET: + description: 'Google Client Secret' + required: true + STMP_EMAIL: + description: 'SMTP Email' + required: true + STMP_PASSWORD: + description: 'SMTP Password' + required: true + JWT_SECRET: + description: 'JWT Secret' + required: true + SEND_GRID_API_KEY: + description: 'Send Grid API Key' + required: true + MAPBOX_ACCESS_TOKEN: + description: 'Mapbox Access Token' + required: true + OPENWEATHER_KEY: + description: 'OpenWeather Key' + required: true + VECTORIZE_API_KEY: + description: 'Vectorize API Key' + required: true + CLOUDFLARE_ACCOUNT_ID: + description: 'Cloudflare Account ID' + required: true + OPENAI_API_KEY: + description: 'OpenAI API Key' + required: true + PREVIEW_DB_ID: + description: 'Preview DB ID' + required: true + PRODUCTION_DB_ID: + description: 'Production DB ID' + required: true + PREVIEW_GOOGLE_CLIENT_ID: + description: 'Preview Google Client ID' + required: true + PREVIEW_GOOGLE_CLIENT_SECRET: + description: 'Preview Google Client Secret' + required: true + PREVIEW_STMP_EMAIL: + description: 'Preview SMTP Email' + required: true + PREVIEW_STMP_PASSWORD: + description: 'Preview SMTP Password' + required: true + PREVIEW_JWT_SECRET: + description: 'Preview JWT Secret' + required: true + PREVIEW_SEND_GRID_API_KEY: + description: 'Preview Send Grid API Key' + required: true + PREVIEW_MAPBOX_ACCESS_TOKEN: + description: 'Preview Mapbox Access Token' + required: true + PREVIEW_OPENWEATHER_KEY: + description: 'Preview OpenWeather Key' + required: true + PREVIEW_VECTORIZE_API_KEY: + description: 'Preview Vectorize API Key' + required: true + PREVIEW_CLOUDFLARE_ACCOUNT_ID: + description: 'Preview Cloudflare Account ID' + required: true + PREVIEW_OPENAI_API_KEY: + description: 'Preview OpenAI API Key' + required: true runs: using: 'composite' steps: @@ -19,39 +92,39 @@ runs: echo '[[env.preview.d1_databases]]' >> ${{ github.workspace }}/server/wrangler.toml echo 'binding = "DB"' >> ${{ github.workspace }}/server/wrangler.toml echo 'database_name = "preview"' >> ${{ github.workspace }}/server/wrangler.toml - echo 'database_id = "${{ secrets.PREVIEW_DB_ID }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'database_id = "${{ inputs.PREVIEW_DB_ID }}"' >> ${{ github.workspace }}/server/wrangler.toml echo '[env.preview.vars]' >> ${{ github.workspace }}/server/wrangler.toml echo 'NODE_ENV = "preview"' >> ${{ github.workspace }}/server/wrangler.toml - echo 'GOOGLE_CLIENT_ID = "${{ secrets.GOOGLE_CLIENT_ID }}"' >> ${{ github.workspace }}/server/wrangler.toml - echo 'GOOGLE_CLIENT_SECRET = "${{ secrets.GOOGLE_CLIENT_SECRET }}"' >> ${{ github.workspace }}/server/wrangler.toml - echo 'STMP_EMAIL = "${{ secrets.STMP_EMAIL }}"' >> ${{ github.workspace }}/server/wrangler.toml - echo 'STMP_PASSWORD = "${{ secrets.STMP_PASSWORD }}"' >> ${{ github.workspace }}/server/wrangler.toml - echo 'JWT_SECRET = "${{ secrets.JWT_SECRET }}"' >> ${{ github.workspace }}/server/wrangler.toml - echo 'SEND_GRID_API_KEY = "${{ secrets.SEND_GRID_API_KEY }}"' >> ${{ github.workspace }}/server/wrangler.toml - echo 'MAPBOX_ACCESS_TOKEN = "${{ secrets.MAPBOX_ACCESS_TOKEN }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'GOOGLE_CLIENT_ID = "${{ inputs.GOOGLE_CLIENT_ID }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'GOOGLE_CLIENT_SECRET = "${{ inputs.GOOGLE_CLIENT_SECRET }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'STMP_EMAIL = "${{ inputs.STMP_EMAIL }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'STMP_PASSWORD = "${{ inputs.STMP_PASSWORD }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'JWT_SECRET = "${{ inputs.JWT_SECRET }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'SEND_GRID_API_KEY = "${{ inputs.SEND_GRID_API_KEY }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'MAPBOX_ACCESS_TOKEN = "${{ inputs.MAPBOX_ACCESS_TOKEN }}"' >> ${{ github.workspace }}/server/wrangler.toml echo 'OSM_URI = "https://overpass-api.de/api/interpreter"' >> ${{ github.workspace }}/server/wrangler.toml echo 'WEATHER_URL = "https://api.openweathermap.org/data/2.5/forecast"' >> ${{ github.workspace }}/server/wrangler.toml - echo 'OPENWEATHER_KEY = "${{ secrets.OPENWEATHER_KEY }}"' >> ${{ github.workspace }}/server/wrangler.toml - echo 'VECTORIZE_API_KEY = "${{ secrets.VECTORIZE_API_KEY }}"' >> ${{ github.workspace }}/server/wrangler.toml - echo 'CLOUDFLARE_ACCOUNT_ID = "${{ secrets.CLOUDFLARE_ACCOUNT_ID }}"' >> ${{ github.workspace }}/server/wrangler.toml - echo 'OPENAI_API_KEY = "${{ secrets.OPENAI_API_KEY }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'OPENWEATHER_KEY = "${{ inputs.OPENWEATHER_KEY }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'VECTORIZE_API_KEY = "${{ inputs.VECTORIZE_API_KEY }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'CLOUDFLARE_ACCOUNT_ID = "${{ inputs.CLOUDFLARE_ACCOUNT_ID }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'OPENAI_API_KEY = "${{ inputs.OPENAI_API_KEY }}"' >> ${{ github.workspace }}/server/wrangler.toml echo '[env.production]' >> ${{ github.workspace }}/server/wrangler.toml echo '[[env.production.d1_databases]]' >> ${{ github.workspace }}/server/wrangler.toml echo 'binding = "DB"' >> ${{ github.workspace }}/server/wrangler.toml echo 'database_name = "production"' >> ${{ github.workspace }}/server/wrangler.toml - echo 'database_id = "${{ secrets.PRODUCTION_DB_ID }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'database_id = "${{ inputs.PRODUCTION_DB_ID }}"' >> ${{ github.workspace }}/server/wrangler.toml echo '[env.production.vars]' >> ${{ github.workspace }}/server/wrangler.toml echo 'NODE_ENV = "production"' >> ${{ github.workspace }}/server/wrangler.toml - echo 'GOOGLE_CLIENT_ID = "${{ secrets.GOOGLE_CLIENT_ID }}"' >> ${{ github.workspace }}/server/wrangler.toml - echo 'GOOGLE_CLIENT_SECRET = "${{ secrets.GOOGLE_CLIENT_SECRET }}"' >> ${{ github.workspace }}/server/wrangler.toml - echo 'STMP_EMAIL = "${{ secrets.STMP_EMAIL }}"' >> ${{ github.workspace }}/server/wrangler.toml - echo 'STMP_PASSWORD = "${{ secrets.STMP_PASSWORD }}"' >> ${{ github.workspace }}/server/wrangler.toml - echo 'JWT_SECRET = "${{ secrets.JWT_SECRET }}"' >> ${{ github.workspace }}/server/wrangler.toml - echo 'SEND_GRID_API_KEY = "${{ secrets.SEND_GRID_API_KEY }}"' >> ${{ github.workspace }}/server/wrangler.toml - echo 'MAPBOX_ACCESS_TOKEN = "${{ secrets.MAPBOX_ACCESS_TOKEN }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'GOOGLE_CLIENT_ID = "${{ inputs.GOOGLE_CLIENT_ID }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'GOOGLE_CLIENT_SECRET = "${{ inputs.GOOGLE_CLIENT_SECRET }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'STMP_EMAIL = "${{ inputs.STMP_EMAIL }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'STMP_PASSWORD = "${{ inputs.STMP_PASSWORD }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'JWT_SECRET = "${{ inputs.JWT_SECRET }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'SEND_GRID_API_KEY = "${{ inputs.SEND_GRID_API_KEY }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'MAPBOX_ACCESS_TOKEN = "${{ inputs.MAPBOX_ACCESS_TOKEN }}"' >> ${{ github.workspace }}/server/wrangler.toml echo 'OSM_URI = "https://overpass-api.de/api/interpreter"' >> ${{ github.workspace }}/server/wrangler.toml echo 'WEATHER_URL = "https://api.openweathermap.org/data/2.5/forecast"' >> ${{ github.workspace }}/server/wrangler.toml - echo 'OPENWEATHER_KEY = "${{ secrets.OPENWEATHER_KEY }}"' >> ${{ github.workspace }}/server/wrangler.toml - echo 'VECTORIZE_API_KEY = "${{ secrets.VECTORIZE_API_KEY }}"' >> ${{ github.workspace }}/server/wrangler.toml - echo 'CLOUDFLARE_ACCOUNT_ID = "${{ secrets.CLOUDFLARE_ACCOUNT_ID }}"' >> ${{ github.workspace }}/server/wrangler.toml - echo 'OPENAI_API_KEY = "${{ secrets.OPENAI_API_KEY }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'OPENWEATHER_KEY = "${{ inputs.OPENWEATHER_KEY }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'VECTORIZE_API_KEY = "${{ inputs.VECTORIZE_API_KEY }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'CLOUDFLARE_ACCOUNT_ID = "${{ inputs.CLOUDFLARE_ACCOUNT_ID }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'OPENAI_API_KEY = "${{ inputs.OPENAI_API_KEY }}"' >> ${{ github.workspace }}/server/wrangler.toml diff --git a/.github/workflows/backend-preview.yml b/.github/workflows/backend-preview.yml index 54718776b..918e3206f 100644 --- a/.github/workflows/backend-preview.yml +++ b/.github/workflows/backend-preview.yml @@ -38,6 +38,31 @@ jobs: - name: Generate wrangler.toml uses: ./.github/actions/setup-wrangler-toml + with: + GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }} + GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }} + STMP_EMAIL: ${{ secrets.STMP_EMAIL }} + STMP_PASSWORD: ${{ secrets.STMP_PASSWORD }} + JWT_SECRET: ${{ secrets.JWT_SECRET }} + SEND_GRID_API_KEY: ${{ secrets.SEND_GRID_API_KEY }} + MAPBOX_ACCESS_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN }} + OPENWEATHER_KEY: ${{ secrets.OPENWEATHER_KEY }} + VECTORIZE_API_KEY: ${{ secrets.VECTORIZE_API_KEY }} + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + PREVIEW_DB_ID: ${{ secrets.PREVIEW_DB_ID }} + PRODUCTION_DB_ID: ${{ secrets.PRODUCTION_DB_ID }} + PREVIEW_GOOGLE_CLIENT_ID: ${{ secrets.PREVIEW_GOOGLE_CLIENT_ID }} + PREVIEW_GOOGLE_CLIENT_SECRET: ${{ secrets.PREVIEW_GOOGLE_CLIENT_SECRET }} + PREVIEW_STMP_EMAIL: ${{ secrets.PREVIEW_STMP_EMAIL }} + PREVIEW_STMP_PASSWORD: ${{ secrets.PREVIEW_STMP_PASSWORD }} + PREVIEW_JWT_SECRET: ${{ secrets.PREVIEW_JWT_SECRET }} + PREVIEW_SEND_GRID_API_KEY: ${{ secrets.PREVIEW_SEND_GRID_API_KEY }} + PREVIEW_MAPBOX_ACCESS_TOKEN: ${{ secrets.PREVIEW_MAPBOX_ACCESS_TOKEN }} + PREVIEW_OPENWEATHER_KEY: ${{ secrets.PREVIEW_OPENWEATHER_KEY }} + PREVIEW_VECTORIZE_API_KEY: ${{ secrets.PREVIEW_VECTORIZE_API_KEY }} + PREVIEW_CLOUDFLARE_ACCOUNT_ID: ${{ secrets.PREVIEW_CLOUDFLARE_ACCOUNT_ID }} + PREVIEW_OPENAI_API_KEY: ${{ secrets.PREVIEW_OPENAI_API_KEY }} - name: Migrate database # run: cd packages/api && bun run migrate diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 0cb462d85..a2506761f 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -39,6 +39,31 @@ jobs: - name: Generate wrangler.toml uses: ./.github/actions/setup-wrangler-toml + with: + GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }} + GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }} + STMP_EMAIL: ${{ secrets.STMP_EMAIL }} + STMP_PASSWORD: ${{ secrets.STMP_PASSWORD }} + JWT_SECRET: ${{ secrets.JWT_SECRET }} + SEND_GRID_API_KEY: ${{ secrets.SEND_GRID_API_KEY }} + MAPBOX_ACCESS_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN }} + OPENWEATHER_KEY: ${{ secrets.OPENWEATHER_KEY }} + VECTORIZE_API_KEY: ${{ secrets.VECTORIZE_API_KEY }} + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + PREVIEW_DB_ID: ${{ secrets.PREVIEW_DB_ID }} + PRODUCTION_DB_ID: ${{ secrets.PRODUCTION_DB_ID }} + PREVIEW_GOOGLE_CLIENT_ID: ${{ secrets.PREVIEW_GOOGLE_CLIENT_ID }} + PREVIEW_GOOGLE_CLIENT_SECRET: ${{ secrets.PREVIEW_GOOGLE_CLIENT_SECRET }} + PREVIEW_STMP_EMAIL: ${{ secrets.PREVIEW_STMP_EMAIL }} + PREVIEW_STMP_PASSWORD: ${{ secrets.PREVIEW_STMP_PASSWORD }} + PREVIEW_JWT_SECRET: ${{ secrets.PREVIEW_JWT_SECRET }} + PREVIEW_SEND_GRID_API_KEY: ${{ secrets.PREVIEW_SEND_GRID_API_KEY }} + PREVIEW_MAPBOX_ACCESS_TOKEN: ${{ secrets.PREVIEW_MAPBOX_ACCESS_TOKEN }} + PREVIEW_OPENWEATHER_KEY: ${{ secrets.PREVIEW_OPENWEATHER_KEY }} + PREVIEW_VECTORIZE_API_KEY: ${{ secrets.PREVIEW_VECTORIZE_API_KEY }} + PREVIEW_CLOUDFLARE_ACCOUNT_ID: ${{ secrets.PREVIEW_CLOUDFLARE_ACCOUNT_ID }} + PREVIEW_OPENAI_API_KEY: ${{ secrets.PREVIEW_OPENAI_API_KEY }} - name: Migrate database # run: cd packages/api && bun run migrate From b0c8b83a0bb055cf69ca1f5a7460c0b7e522b0a9 Mon Sep 17 00:00:00 2001 From: Taron Date: Wed, 24 Jul 2024 01:55:36 +0400 Subject: [PATCH 04/10] change to run the workflow --- server/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/index.ts b/server/src/index.ts index 8bbe78c92..dc39f65ea 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -54,7 +54,7 @@ app.use('*', async (c, next) => { allowMethods: CORS_METHODS, }); // change for testing the workflow - console.log('CORS middleware setup'); + console.log('CORS middleware setup!'); return corsMiddleware(c, next); }); From f1dbd42450546fa2ee9f2c96705e10707d74b18e Mon Sep 17 00:00:00 2001 From: Taron Date: Wed, 24 Jul 2024 02:03:20 +0400 Subject: [PATCH 05/10] add migrate preview script --- server/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/server/package.json b/server/package.json index bb005149c..459790726 100644 --- a/server/package.json +++ b/server/package.json @@ -17,6 +17,7 @@ "migrate:down:local": "drizzle-kit drop", "migrate:down": "yarn run migrate:down:local", "migrate:local": "wrangler d1 migrations apply preview --local --env preview", + "migrate:preview": "wrangler d1 migrations apply preview --remote --env preview", "migrate:prod": "wrangler d1 migrations apply production --remote --env production", "migrate": "yarn run migrate:local", "postinstall": "yarn generate", From 7f0cce06a24ff91ca86eeea59618ccc355a42a63 Mon Sep 17 00:00:00 2001 From: Taron Date: Wed, 24 Jul 2024 02:56:14 +0400 Subject: [PATCH 06/10] fix global wrangler toml config --- .github/actions/setup-wrangler-toml/action.yml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/actions/setup-wrangler-toml/action.yml b/.github/actions/setup-wrangler-toml/action.yml index 117464d96..e93854f83 100644 --- a/.github/actions/setup-wrangler-toml/action.yml +++ b/.github/actions/setup-wrangler-toml/action.yml @@ -79,20 +79,20 @@ runs: - name: Generate wrangler.toml shell: bash run: | - echo 'name = "packrat-api-staging"' > ${{ github.workspace }}/server/wrangler.toml + echo 'name = "packrat-api"' > ${{ github.workspace }}/server/wrangler.toml echo 'main = "src/index.ts"' >> ${{ github.workspace }}/server/wrangler.toml echo 'compatibility_date = "2024-03-14"' >> ${{ github.workspace }}/server/wrangler.toml echo 'node_compat = true' >> ${{ github.workspace }}/server/wrangler.toml - echo '[ai]' >> ${{ github.workspace }}/server/wrangler.toml - echo 'binding = "AI"' >> ${{ github.workspace }}/server/wrangler.toml - echo '[[vectorize]]' >> ${{ github.workspace }}/server/wrangler.toml - echo 'binding = "VECTOR_INDEX"' >> ${{ github.workspace }}/server/wrangler.toml - echo 'index_name = "vector-index"' >> ${{ github.workspace }}/server/wrangler.toml echo '[env.preview]' >> ${{ github.workspace }}/server/wrangler.toml echo '[[env.preview.d1_databases]]' >> ${{ github.workspace }}/server/wrangler.toml echo 'binding = "DB"' >> ${{ github.workspace }}/server/wrangler.toml echo 'database_name = "preview"' >> ${{ github.workspace }}/server/wrangler.toml echo 'database_id = "${{ inputs.PREVIEW_DB_ID }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo '[env.preview.ai]' >> ${{ github.workspace }}/server/wrangler.toml + echo 'binding = "AI"' >> ${{ github.workspace }}/server/wrangler.toml + echo '[[env.preview.vectorize]]' >> ${{ github.workspace }}/server/wrangler.toml + echo 'binding = "VECTOR_INDEX"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'index_name = "vector-index"' >> ${{ github.workspace }}/server/wrangler.toml echo '[env.preview.vars]' >> ${{ github.workspace }}/server/wrangler.toml echo 'NODE_ENV = "preview"' >> ${{ github.workspace }}/server/wrangler.toml echo 'GOOGLE_CLIENT_ID = "${{ inputs.GOOGLE_CLIENT_ID }}"' >> ${{ github.workspace }}/server/wrangler.toml @@ -113,6 +113,11 @@ runs: echo 'binding = "DB"' >> ${{ github.workspace }}/server/wrangler.toml echo 'database_name = "production"' >> ${{ github.workspace }}/server/wrangler.toml echo 'database_id = "${{ inputs.PRODUCTION_DB_ID }}"' >> ${{ github.workspace }}/server/wrangler.toml + echo '[env.production.ai]' >> ${{ github.workspace }}/server/wrangler.toml + echo 'binding = "AI"' >> ${{ github.workspace }}/server/wrangler.toml + echo '[[env.production.vectorize]]' >> ${{ github.workspace }}/server/wrangler.toml + echo 'binding = "VECTOR_INDEX"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'index_name = "vector-index"' >> ${{ github.workspace }}/server/wrangler.toml echo '[env.production.vars]' >> ${{ github.workspace }}/server/wrangler.toml echo 'NODE_ENV = "production"' >> ${{ github.workspace }}/server/wrangler.toml echo 'GOOGLE_CLIENT_ID = "${{ inputs.GOOGLE_CLIENT_ID }}"' >> ${{ github.workspace }}/server/wrangler.toml From 9ad7525264a22df6db9971f19919745d60bcb25d Mon Sep 17 00:00:00 2001 From: Taron Date: Wed, 24 Jul 2024 14:11:51 +0400 Subject: [PATCH 07/10] add vector preview index --- .github/actions/setup-wrangler-toml/action.yml | 2 +- server/src/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/setup-wrangler-toml/action.yml b/.github/actions/setup-wrangler-toml/action.yml index e93854f83..0412e6ce6 100644 --- a/.github/actions/setup-wrangler-toml/action.yml +++ b/.github/actions/setup-wrangler-toml/action.yml @@ -92,7 +92,7 @@ runs: echo 'binding = "AI"' >> ${{ github.workspace }}/server/wrangler.toml echo '[[env.preview.vectorize]]' >> ${{ github.workspace }}/server/wrangler.toml echo 'binding = "VECTOR_INDEX"' >> ${{ github.workspace }}/server/wrangler.toml - echo 'index_name = "vector-index"' >> ${{ github.workspace }}/server/wrangler.toml + echo 'index_name = "vector-index-preview"' >> ${{ github.workspace }}/server/wrangler.toml echo '[env.preview.vars]' >> ${{ github.workspace }}/server/wrangler.toml echo 'NODE_ENV = "preview"' >> ${{ github.workspace }}/server/wrangler.toml echo 'GOOGLE_CLIENT_ID = "${{ inputs.GOOGLE_CLIENT_ID }}"' >> ${{ github.workspace }}/server/wrangler.toml diff --git a/server/src/index.ts b/server/src/index.ts index dc39f65ea..b3ad56567 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -54,7 +54,7 @@ app.use('*', async (c, next) => { allowMethods: CORS_METHODS, }); // change for testing the workflow - console.log('CORS middleware setup!'); + console.log('CORS middleware setup!!'); return corsMiddleware(c, next); }); From fc02be9c4f5e7a1ab7e8976466a28944b14484a1 Mon Sep 17 00:00:00 2001 From: Taron Date: Wed, 24 Jul 2024 16:39:35 +0400 Subject: [PATCH 08/10] change for workflow run --- server/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/index.ts b/server/src/index.ts index b3ad56567..362170a77 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -54,7 +54,7 @@ app.use('*', async (c, next) => { allowMethods: CORS_METHODS, }); // change for testing the workflow - console.log('CORS middleware setup!!'); + console.log('CORS middleware setup!!!'); return corsMiddleware(c, next); }); From 852967e47300625b279061d80e0a890ca4c944e1 Mon Sep 17 00:00:00 2001 From: Taron Date: Thu, 25 Jul 2024 12:25:34 +0400 Subject: [PATCH 09/10] fix cloudfare_api_token in github workflow --- .github/workflows/backend-preview.yml | 4 ++-- .github/workflows/backend.yml | 4 ++-- server/src/index.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/backend-preview.yml b/.github/workflows/backend-preview.yml index 918e3206f..ad70b4b4e 100644 --- a/.github/workflows/backend-preview.yml +++ b/.github/workflows/backend-preview.yml @@ -69,13 +69,13 @@ jobs: run: cd server && yarn run migrate:preview env: NO_D1_WARNING: true - CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }} + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} - name: Deploy uses: cloudflare/wrangler-action@v3.3.2 with: wranglerVersion: '3.15.0' - apiToken: ${{ secrets.CF_API_TOKEN }} + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} # workingDirectory: packages/api workingDirectory: server command: yarn run deploy:preview diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index a2506761f..e402650e3 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -70,13 +70,13 @@ jobs: run: cd server && yarn run migrate:prod env: NO_D1_WARNING: true - CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }} + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} - name: Deploy uses: cloudflare/wrangler-action@v3.3.2 with: wranglerVersion: '3.15.0' - apiToken: ${{ secrets.CF_API_TOKEN }} + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} workingDirectory: server command: yarn run deploy:prod # packageManager: bun diff --git a/server/src/index.ts b/server/src/index.ts index 362170a77..50624c505 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -54,7 +54,7 @@ app.use('*', async (c, next) => { allowMethods: CORS_METHODS, }); // change for testing the workflow - console.log('CORS middleware setup!!!'); + console.log('CORS middleware setup!!!!'); return corsMiddleware(c, next); }); From 29a39fe02bbdd6040eb456e233bed479d7c54577 Mon Sep 17 00:00:00 2001 From: Taron Date: Thu, 25 Jul 2024 15:21:30 +0400 Subject: [PATCH 10/10] disable backend-preview workflow in short term --- .github/workflows/backend-preview.yml | 167 ++++++++++---------- .github/workflows/backend.yml | 216 +++++++++++++------------- server/src/index.ts | 1 - 3 files changed, 191 insertions(+), 193 deletions(-) diff --git a/.github/workflows/backend-preview.yml b/.github/workflows/backend-preview.yml index ad70b4b4e..cba65a6a0 100644 --- a/.github/workflows/backend-preview.yml +++ b/.github/workflows/backend-preview.yml @@ -1,92 +1,91 @@ -name: 'Backend Preview Deployment' +# name: 'Backend Preview Deployment' -on: - workflow_dispatch: - pull_request: - branches: - - feat/preview-version-of-api - types: [closed] - push: - branches: - - feat/preview-version-of-api - paths: - - 'packages/validations/**' - - 'packages/shared-types/**' - - 'server/**' +# on: +# workflow_dispatch: +# pull_request: +# branches: +# - feat/preview-version-of-api +# types: [closed] +# push: +# branches: +# - feat/preview-version-of-api +# paths: +# - 'packages/validations/**' +# - 'packages/shared-types/**' +# - 'server/**' +# concurrency: +# group: ${{ github.workflow }}-${{ github.ref }} +# cancel-in-progress: true -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true +# jobs: +# deploy: +# name: Deploy to Cloudflare Workers +# runs-on: ubuntu-latest +# timeout-minutes: 10 -jobs: - deploy: - name: Deploy to Cloudflare Workers - runs-on: ubuntu-latest - timeout-minutes: 10 +# steps: +# - name: Checkout code +# uses: actions/checkout@v3 +# with: +# fetch-depth: 1 - steps: - - name: Checkout code - uses: actions/checkout@v3 - with: - fetch-depth: 1 +# - name: Setup JS Runtime environment +# uses: ./.github/actions/setup-js-runtime - - name: Setup JS Runtime environment - uses: ./.github/actions/setup-js-runtime +# - name: Install dependencies +# uses: ./.github/actions/install-deps - - name: Install dependencies - uses: ./.github/actions/install-deps +# - name: Generate wrangler.toml +# uses: ./.github/actions/setup-wrangler-toml +# with: +# GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }} +# GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }} +# STMP_EMAIL: ${{ secrets.STMP_EMAIL }} +# STMP_PASSWORD: ${{ secrets.STMP_PASSWORD }} +# JWT_SECRET: ${{ secrets.JWT_SECRET }} +# SEND_GRID_API_KEY: ${{ secrets.SEND_GRID_API_KEY }} +# MAPBOX_ACCESS_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN }} +# OPENWEATHER_KEY: ${{ secrets.OPENWEATHER_KEY }} +# VECTORIZE_API_KEY: ${{ secrets.VECTORIZE_API_KEY }} +# CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} +# OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} +# PREVIEW_DB_ID: ${{ secrets.PREVIEW_DB_ID }} +# PRODUCTION_DB_ID: ${{ secrets.PRODUCTION_DB_ID }} +# PREVIEW_GOOGLE_CLIENT_ID: ${{ secrets.PREVIEW_GOOGLE_CLIENT_ID }} +# PREVIEW_GOOGLE_CLIENT_SECRET: ${{ secrets.PREVIEW_GOOGLE_CLIENT_SECRET }} +# PREVIEW_STMP_EMAIL: ${{ secrets.PREVIEW_STMP_EMAIL }} +# PREVIEW_STMP_PASSWORD: ${{ secrets.PREVIEW_STMP_PASSWORD }} +# PREVIEW_JWT_SECRET: ${{ secrets.PREVIEW_JWT_SECRET }} +# PREVIEW_SEND_GRID_API_KEY: ${{ secrets.PREVIEW_SEND_GRID_API_KEY }} +# PREVIEW_MAPBOX_ACCESS_TOKEN: ${{ secrets.PREVIEW_MAPBOX_ACCESS_TOKEN }} +# PREVIEW_OPENWEATHER_KEY: ${{ secrets.PREVIEW_OPENWEATHER_KEY }} +# PREVIEW_VECTORIZE_API_KEY: ${{ secrets.PREVIEW_VECTORIZE_API_KEY }} +# PREVIEW_CLOUDFLARE_ACCOUNT_ID: ${{ secrets.PREVIEW_CLOUDFLARE_ACCOUNT_ID }} +# PREVIEW_OPENAI_API_KEY: ${{ secrets.PREVIEW_OPENAI_API_KEY }} - - name: Generate wrangler.toml - uses: ./.github/actions/setup-wrangler-toml - with: - GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }} - GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }} - STMP_EMAIL: ${{ secrets.STMP_EMAIL }} - STMP_PASSWORD: ${{ secrets.STMP_PASSWORD }} - JWT_SECRET: ${{ secrets.JWT_SECRET }} - SEND_GRID_API_KEY: ${{ secrets.SEND_GRID_API_KEY }} - MAPBOX_ACCESS_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN }} - OPENWEATHER_KEY: ${{ secrets.OPENWEATHER_KEY }} - VECTORIZE_API_KEY: ${{ secrets.VECTORIZE_API_KEY }} - CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - PREVIEW_DB_ID: ${{ secrets.PREVIEW_DB_ID }} - PRODUCTION_DB_ID: ${{ secrets.PRODUCTION_DB_ID }} - PREVIEW_GOOGLE_CLIENT_ID: ${{ secrets.PREVIEW_GOOGLE_CLIENT_ID }} - PREVIEW_GOOGLE_CLIENT_SECRET: ${{ secrets.PREVIEW_GOOGLE_CLIENT_SECRET }} - PREVIEW_STMP_EMAIL: ${{ secrets.PREVIEW_STMP_EMAIL }} - PREVIEW_STMP_PASSWORD: ${{ secrets.PREVIEW_STMP_PASSWORD }} - PREVIEW_JWT_SECRET: ${{ secrets.PREVIEW_JWT_SECRET }} - PREVIEW_SEND_GRID_API_KEY: ${{ secrets.PREVIEW_SEND_GRID_API_KEY }} - PREVIEW_MAPBOX_ACCESS_TOKEN: ${{ secrets.PREVIEW_MAPBOX_ACCESS_TOKEN }} - PREVIEW_OPENWEATHER_KEY: ${{ secrets.PREVIEW_OPENWEATHER_KEY }} - PREVIEW_VECTORIZE_API_KEY: ${{ secrets.PREVIEW_VECTORIZE_API_KEY }} - PREVIEW_CLOUDFLARE_ACCOUNT_ID: ${{ secrets.PREVIEW_CLOUDFLARE_ACCOUNT_ID }} - PREVIEW_OPENAI_API_KEY: ${{ secrets.PREVIEW_OPENAI_API_KEY }} +# - name: Migrate database +# # run: cd packages/api && bun run migrate +# run: cd server && yarn run migrate:preview +# env: +# NO_D1_WARNING: true +# CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} - - name: Migrate database - # run: cd packages/api && bun run migrate - run: cd server && yarn run migrate:preview - env: - NO_D1_WARNING: true - CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} - - - name: Deploy - uses: cloudflare/wrangler-action@v3.3.2 - with: - wranglerVersion: '3.15.0' - apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} - # workingDirectory: packages/api - workingDirectory: server - command: yarn run deploy:preview - # packageManager: bun - packageManager: yarn - secrets: | - APP_URL - JWT_VERIFICATION_KEY - CI - env: - APP_URL: ${{ secrets.VITE_PUBLIC_APP_URL }} - JWT_VERIFICATION_KEY: ${{ secrets.JWT_SECRET }} - CI: true - NO_D1_WARNING: true +# - name: Deploy +# uses: cloudflare/wrangler-action@v3.3.2 +# with: +# wranglerVersion: '3.15.0' +# apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} +# # workingDirectory: packages/api +# workingDirectory: server +# command: yarn run deploy:preview +# # packageManager: bun +# packageManager: yarn +# secrets: | +# APP_URL +# JWT_VERIFICATION_KEY +# CI +# env: +# APP_URL: ${{ secrets.VITE_PUBLIC_APP_URL }} +# JWT_VERIFICATION_KEY: ${{ secrets.JWT_SECRET }} +# CI: true +# NO_D1_WARNING: true diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index e402650e3..59339c91f 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -1,117 +1,117 @@ -name: 'Backend Deployment' +# name: 'Backend Deployment' -on: - workflow_dispatch: - pull_request: - branches: - - master - types: [closed] - push: - branches: - - master - - andrew_testing - paths: - - 'packages/validations/**' - - 'packages/shared-types/**' - - 'server/**' +# on: +# workflow_dispatch: +# pull_request: +# branches: +# - master +# types: [closed] +# push: +# branches: +# - master +# - andrew_testing +# paths: +# - 'packages/validations/**' +# - 'packages/shared-types/**' +# - 'server/**' -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true +# concurrency: +# group: ${{ github.workflow }}-${{ github.ref }} +# cancel-in-progress: true -jobs: - deploy: - name: Deploy to Cloudflare Workers - runs-on: ubuntu-latest - timeout-minutes: 10 +# jobs: +# deploy: +# name: Deploy to Cloudflare Workers +# runs-on: ubuntu-latest +# timeout-minutes: 10 - steps: - - name: Checkout code - uses: actions/checkout@v3 - with: - fetch-depth: 1 +# steps: +# - name: Checkout code +# uses: actions/checkout@v3 +# with: +# fetch-depth: 1 - - name: Setup JS Runtime environment - uses: ./.github/actions/setup-js-runtime +# - name: Setup JS Runtime environment +# uses: ./.github/actions/setup-js-runtime - - name: Install dependencies - uses: ./.github/actions/install-deps +# - name: Install dependencies +# uses: ./.github/actions/install-deps - - name: Generate wrangler.toml - uses: ./.github/actions/setup-wrangler-toml - with: - GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }} - GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }} - STMP_EMAIL: ${{ secrets.STMP_EMAIL }} - STMP_PASSWORD: ${{ secrets.STMP_PASSWORD }} - JWT_SECRET: ${{ secrets.JWT_SECRET }} - SEND_GRID_API_KEY: ${{ secrets.SEND_GRID_API_KEY }} - MAPBOX_ACCESS_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN }} - OPENWEATHER_KEY: ${{ secrets.OPENWEATHER_KEY }} - VECTORIZE_API_KEY: ${{ secrets.VECTORIZE_API_KEY }} - CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - PREVIEW_DB_ID: ${{ secrets.PREVIEW_DB_ID }} - PRODUCTION_DB_ID: ${{ secrets.PRODUCTION_DB_ID }} - PREVIEW_GOOGLE_CLIENT_ID: ${{ secrets.PREVIEW_GOOGLE_CLIENT_ID }} - PREVIEW_GOOGLE_CLIENT_SECRET: ${{ secrets.PREVIEW_GOOGLE_CLIENT_SECRET }} - PREVIEW_STMP_EMAIL: ${{ secrets.PREVIEW_STMP_EMAIL }} - PREVIEW_STMP_PASSWORD: ${{ secrets.PREVIEW_STMP_PASSWORD }} - PREVIEW_JWT_SECRET: ${{ secrets.PREVIEW_JWT_SECRET }} - PREVIEW_SEND_GRID_API_KEY: ${{ secrets.PREVIEW_SEND_GRID_API_KEY }} - PREVIEW_MAPBOX_ACCESS_TOKEN: ${{ secrets.PREVIEW_MAPBOX_ACCESS_TOKEN }} - PREVIEW_OPENWEATHER_KEY: ${{ secrets.PREVIEW_OPENWEATHER_KEY }} - PREVIEW_VECTORIZE_API_KEY: ${{ secrets.PREVIEW_VECTORIZE_API_KEY }} - PREVIEW_CLOUDFLARE_ACCOUNT_ID: ${{ secrets.PREVIEW_CLOUDFLARE_ACCOUNT_ID }} - PREVIEW_OPENAI_API_KEY: ${{ secrets.PREVIEW_OPENAI_API_KEY }} +# - name: Generate wrangler.toml +# uses: ./.github/actions/setup-wrangler-toml +# with: +# GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }} +# GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }} +# STMP_EMAIL: ${{ secrets.STMP_EMAIL }} +# STMP_PASSWORD: ${{ secrets.STMP_PASSWORD }} +# JWT_SECRET: ${{ secrets.JWT_SECRET }} +# SEND_GRID_API_KEY: ${{ secrets.SEND_GRID_API_KEY }} +# MAPBOX_ACCESS_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN }} +# OPENWEATHER_KEY: ${{ secrets.OPENWEATHER_KEY }} +# VECTORIZE_API_KEY: ${{ secrets.VECTORIZE_API_KEY }} +# CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} +# OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} +# PREVIEW_DB_ID: ${{ secrets.PREVIEW_DB_ID }} +# PRODUCTION_DB_ID: ${{ secrets.PRODUCTION_DB_ID }} +# PREVIEW_GOOGLE_CLIENT_ID: ${{ secrets.PREVIEW_GOOGLE_CLIENT_ID }} +# PREVIEW_GOOGLE_CLIENT_SECRET: ${{ secrets.PREVIEW_GOOGLE_CLIENT_SECRET }} +# PREVIEW_STMP_EMAIL: ${{ secrets.PREVIEW_STMP_EMAIL }} +# PREVIEW_STMP_PASSWORD: ${{ secrets.PREVIEW_STMP_PASSWORD }} +# PREVIEW_JWT_SECRET: ${{ secrets.PREVIEW_JWT_SECRET }} +# PREVIEW_SEND_GRID_API_KEY: ${{ secrets.PREVIEW_SEND_GRID_API_KEY }} +# PREVIEW_MAPBOX_ACCESS_TOKEN: ${{ secrets.PREVIEW_MAPBOX_ACCESS_TOKEN }} +# PREVIEW_OPENWEATHER_KEY: ${{ secrets.PREVIEW_OPENWEATHER_KEY }} +# PREVIEW_VECTORIZE_API_KEY: ${{ secrets.PREVIEW_VECTORIZE_API_KEY }} +# PREVIEW_CLOUDFLARE_ACCOUNT_ID: ${{ secrets.PREVIEW_CLOUDFLARE_ACCOUNT_ID }} +# PREVIEW_OPENAI_API_KEY: ${{ secrets.PREVIEW_OPENAI_API_KEY }} - - name: Migrate database - # run: cd packages/api && bun run migrate - run: cd server && yarn run migrate:prod - env: - NO_D1_WARNING: true - CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} +# - name: Migrate database +# # run: cd packages/api && bun run migrate +# run: cd server && yarn run migrate:prod +# env: +# NO_D1_WARNING: true +# CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} - - name: Deploy - uses: cloudflare/wrangler-action@v3.3.2 - with: - wranglerVersion: '3.15.0' - apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} - workingDirectory: server - command: yarn run deploy:prod - # packageManager: bun - packageManager: yarn - secrets: | - CI - GOOGLE_CLIENT_ID - GOOGLE_CLIENT_SECRET - STMP_EMAIL - STMP_PASSWORD - JWT_SECRET - SEND_GRID_API_KEY - MAPBOX_ACCESS_TOKEN - OSM_URI - WEATHER_URL - WEATHER_WEEK_URL - OPENWEATHER_KEY - VECTORIZE_API_KEY - CLOUDFLARE_ACCOUNT_ID - VITE_PUBLIC_APP_URL - env: - APP_URL: ${{ secrets.VITE_PUBLIC_APP_URL }} - JWT_VERIFICATION_KEY: ${{ secrets.JWT_SECRET }} - GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }} - GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }} - STMP_EMAIL: ${{ secrets.STMP_EMAIL }} - STMP_PASSWORD: ${{ secrets.STMP_PASSWORD }} - JWT_SECRET: ${{ secrets.JWT_SECRET }} - SEND_GRID_API_KEY: ${{ secrets.SEND_GRID_API_KEY }} - MAPBOX_ACCESS_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN }} - OSM_URI: ${{ secrets.OSM_URI }} - WEATHER_URL: ${{ secrets.WEATHER_URL }} - WEATHER_WEEK_URL: ${{ secrets.WEATHER_WEEK_URL }} - OPENWEATHER_KEY: ${{ secrets.OPENWEATHER_KEY }} - VECTORIZE_API_KEY: ${{ secrets.VECTORIZE_API_KEY }} - CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - CI: true - NO_D1_WARNING: true +# - name: Deploy +# uses: cloudflare/wrangler-action@v3.3.2 +# with: +# wranglerVersion: '3.15.0' +# apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} +# workingDirectory: server +# command: yarn run deploy:prod +# # packageManager: bun +# packageManager: yarn +# secrets: | +# CI +# GOOGLE_CLIENT_ID +# GOOGLE_CLIENT_SECRET +# STMP_EMAIL +# STMP_PASSWORD +# JWT_SECRET +# SEND_GRID_API_KEY +# MAPBOX_ACCESS_TOKEN +# OSM_URI +# WEATHER_URL +# WEATHER_WEEK_URL +# OPENWEATHER_KEY +# VECTORIZE_API_KEY +# CLOUDFLARE_ACCOUNT_ID +# VITE_PUBLIC_APP_URL +# env: +# APP_URL: ${{ secrets.VITE_PUBLIC_APP_URL }} +# JWT_VERIFICATION_KEY: ${{ secrets.JWT_SECRET }} +# GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }} +# GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }} +# STMP_EMAIL: ${{ secrets.STMP_EMAIL }} +# STMP_PASSWORD: ${{ secrets.STMP_PASSWORD }} +# JWT_SECRET: ${{ secrets.JWT_SECRET }} +# SEND_GRID_API_KEY: ${{ secrets.SEND_GRID_API_KEY }} +# MAPBOX_ACCESS_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN }} +# OSM_URI: ${{ secrets.OSM_URI }} +# WEATHER_URL: ${{ secrets.WEATHER_URL }} +# WEATHER_WEEK_URL: ${{ secrets.WEATHER_WEEK_URL }} +# OPENWEATHER_KEY: ${{ secrets.OPENWEATHER_KEY }} +# VECTORIZE_API_KEY: ${{ secrets.VECTORIZE_API_KEY }} +# CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} +# CI: true +# NO_D1_WARNING: true diff --git a/server/src/index.ts b/server/src/index.ts index 50624c505..f7844c64b 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -54,7 +54,6 @@ app.use('*', async (c, next) => { allowMethods: CORS_METHODS, }); // change for testing the workflow - console.log('CORS middleware setup!!!!'); return corsMiddleware(c, next); });