From cddd90d9cecce9abe37bc74fde27bc9864b0a486 Mon Sep 17 00:00:00 2001 From: Harsha <106158714+harshbaz@users.noreply.github.com> Date: Tue, 13 Feb 2024 13:41:49 +0530 Subject: [PATCH] Remove use of cf pages (#2110) * Update * Update test deployment * Up * Update names * Fix names * Up names * Revert "Up names" This reverts commit c95b9743fca7497062bc9d2018da922891e83b47. * Up names * Rem --- .github/workflows/experiments-deploy.yml | 23 +++------- .github/workflows/experiments-test.yml | 44 ++++++------------- .github/workflows/webclient-deploy.yml | 32 +++++++++----- .github/workflows/webclient-setup/action.yml | 33 -------------- .github/workflows/webclient-test.yml | 26 +++++------ ...le.dockerignore => Dockerfile.dockerignore | 0 ex.Dockerfile | 43 ++++++++++++++++++ ex.prod.fly.toml | 24 ++++++++++ ex.staging.fly.toml | 24 ++++++++++ package.json | 1 + packages/experiments/package.json | 1 + .../web-client/src/lib/helpers/backend.ts | 2 + .../src/routes/(feed)/menu/+page.svelte | 3 +- .../src/routes/refer-earn/+page.svelte | 3 +- wc.prod.fly.toml | 2 +- wc.staging.fly.toml | 2 +- 16 files changed, 153 insertions(+), 110 deletions(-) delete mode 100644 .github/workflows/webclient-setup/action.yml rename wc.Dockerfile.dockerignore => Dockerfile.dockerignore (100%) create mode 100644 ex.Dockerfile create mode 100644 ex.prod.fly.toml create mode 100644 ex.staging.fly.toml diff --git a/.github/workflows/experiments-deploy.yml b/.github/workflows/experiments-deploy.yml index 59cec7152..2ac5490a7 100644 --- a/.github/workflows/experiments-deploy.yml +++ b/.github/workflows/experiments-deploy.yml @@ -1,4 +1,4 @@ -name: Deploy Experiment app +name: ex:deploy on: push: branches: @@ -12,30 +12,19 @@ concurrency: cancel-in-progress: true jobs: - experiments-deploy-production: + fly-production: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 with: node-version: 20 cache: "npm" - - name: Install dependencies - shell: bash - run: npm install - - - run: npm run ex:build - env: - SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} - GA_TRACKING_ID: "G-PPE5XD2VKV" + - run: npm install + - uses: superfly/flyctl-actions/setup-flyctl@master - name: Deploy production build - uses: cloudflare/wrangler-action@v3 - with: - apiToken: ${{ secrets.CLOUDFLARE_WORKERS_DEPLOY_API_TOKEN }} - workingDirectory: "packages/experiments/" - command: pages deploy ".svelte-kit/cloudflare" --branch=${{ github.head_ref }} --project-name=hot-or-not-experiments --commit-dirty=true + run: flyctl deploy --config ./ex.prod.fly.toml env: - CLOUDFLARE_ACCOUNT_ID: "a209c523d2d9646cc56227dbe6ce3ede" + FLY_API_TOKEN: ${{ secrets.FLYIO_KIT_DEPLOY_GH_ACTION }} diff --git a/.github/workflows/experiments-test.yml b/.github/workflows/experiments-test.yml index b9d99808f..413b7fca6 100644 --- a/.github/workflows/experiments-test.yml +++ b/.github/workflows/experiments-test.yml @@ -1,4 +1,4 @@ -name: Test experiments app +name: ex:tests on: pull_request: branches: @@ -12,7 +12,7 @@ concurrency: cancel-in-progress: true jobs: - experiments-test: + svelte-check: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -35,8 +35,11 @@ jobs: SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} GA_TRACKING_ID: "G-PPE5XD2VKV" - experiments-deploy-staging: - needs: ["experiments-test"] + deploy-fly-staging: + needs: ["svelte-check"] + environment: + name: pr-${{ github.event.number }}-experiments + url: ${{ steps.deploy.outputs.url }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -46,33 +49,14 @@ jobs: node-version: 20 cache: "npm" - - name: Install dependencies - shell: bash - run: npm install + - run: npm install - - name: Creating static build - run: npm run ex:build:static - env: - GA_TRACKING_ID: "G-PPE5XD2VKV" - - - name: Deploying build + - name: Deploy staging build id: deploy - uses: cloudflare/wrangler-action@v3 - with: - apiToken: ${{ secrets.CLOUDFLARE_WORKERS_DEPLOY_API_TOKEN }} - workingDirectory: "packages/experiments/" - command: pages deploy "./build" --branch=${{ github.head_ref }} --project-name=hot-or-not-experiments --commit-dirty=true + uses: superfly/fly-pr-review-apps@1.2.0 env: - CLOUDFLARE_ACCOUNT_ID: "a209c523d2d9646cc56227dbe6ce3ede" - - - name: Comment preview link on PR - if: github.actor != 'dependabot[bot]' - uses: actions/github-script@v7 + FLY_API_TOKEN: ${{ secrets.FLYIO_KIT_DEPLOY_GH_ACTION }} + FLY_ORG: gobazzinga-inc-584 with: - script: | - github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: 'Experiments preview build: ${{ steps.deploy.outputs.previewUrl }}' - }) + name: pr-${{ github.event.number }}-experiments + config: "ex.staging.fly.toml" diff --git a/.github/workflows/webclient-deploy.yml b/.github/workflows/webclient-deploy.yml index 2d9e4e8ec..12969984b 100644 --- a/.github/workflows/webclient-deploy.yml +++ b/.github/workflows/webclient-deploy.yml @@ -1,4 +1,4 @@ -name: Deploy Web-Client +name: wc:deploy on: push: branches: @@ -6,19 +6,21 @@ on: paths: - "packages/web-client/**" - ".github/workflows/webclient-deploy.yml" - - ".github/workflows/webclient-setup/action.yml" concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: - web-client-deploy-ic-production: + ic-production: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Set-up env - uses: ./.github/workflows/webclient-setup + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: "npm" + - run: npm install - run: npm run wc:build:static:prod # Build without sentry - run: | @@ -33,15 +35,23 @@ jobs: dfx identity use actions - run: dfx deploy webclient --network ic --no-wallet -y - web-client-deploy-fly-production: + fly-production: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Set-up env - uses: ./.github/workflows/webclient-setup - - run: npm run wc:build:prod - env: - SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: "npm" + - run: npm install + + - name: Touch .env + shell: bash + working-directory: "packages/web-client/" + run: | + touch .env + echo "SENTRY_AUTH_TOKEN=\"${{ secrets.SENTRY_AUTH_TOKEN }}\"" >> .env + - uses: superfly/flyctl-actions/setup-flyctl@master - name: Deploy production build run: flyctl deploy --config ./wc.prod.fly.toml diff --git a/.github/workflows/webclient-setup/action.yml b/.github/workflows/webclient-setup/action.yml deleted file mode 100644 index fb6e02750..000000000 --- a/.github/workflows/webclient-setup/action.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Setup Web-Client Env -description: Set up node environment and install dependencies - -inputs: - working-dir: - description: "NPM registry" - default: "packages/web-client/" - required: false - -runs: - using: composite - steps: - - uses: actions/setup-node@v4 - with: - node-version: 20 - cache: "npm" - - - name: Install dependencies - shell: bash - run: npm install - - - name: Setup environment - shell: bash - run: | - touch .env - echo "VITE_GA_TRACKING_ID=\"$GA_TRACKING_ID\"" >> .env - echo "VITE_CLOUDFLARE_WORKERS_API_HOST=\"$CLOUDFLARE_WORKERS_API_HOST\"" >> .env - echo "VITE_WEBCLIENT_CANISTER_ID=\"$WEBCLIENT_CANISTER_ID\"" >> .env - working-directory: ${{ inputs.working-dir }} - env: - GA_TRACKING_ID: "G-S9P26021F9" - CLOUDFLARE_WORKERS_API_HOST: "https://hot-or-not-upload-api-main.go-bazzinga.workers.dev" - WEBCLIENT_CANISTER_ID: "vyatz-hqaaa-aaaam-qauea-cai" diff --git a/.github/workflows/webclient-test.yml b/.github/workflows/webclient-test.yml index 02391241f..7a5276ca3 100644 --- a/.github/workflows/webclient-test.yml +++ b/.github/workflows/webclient-test.yml @@ -1,4 +1,4 @@ -name: Web-client tests +name: wc:tests on: pull_request: branches: @@ -6,7 +6,6 @@ on: paths: - "packages/web-client/**" - ".github/workflows/webclient-deploy.yml" - - ".github/workflows/webclient-setup/action.yml" - ".github/workflows/webclient-test.yml" - ".github/workflows/webclient-test-deploy.yml" @@ -34,19 +33,21 @@ jobs: - name: Run svelte-check run: npm run wc:check - web-client-deploy-fly-staging: + deploy-fly-staging: needs: ["svelte-check"] environment: - name: pr-${{ github.event.number }} + name: pr-${{ github.event.number }}-web-client url: ${{ steps.deploy.outputs.url }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Set-up env - uses: ./.github/workflows/webclient-setup + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: "npm" - - run: npm run wc:build:prod + - run: npm install - name: Deploy staging build id: deploy @@ -55,9 +56,10 @@ jobs: FLY_API_TOKEN: ${{ secrets.FLYIO_KIT_DEPLOY_GH_ACTION }} FLY_ORG: gobazzinga-inc-584 with: + name: pr-${{ github.event.number }}-web-client config: "wc.staging.fly.toml" - tests-lighthouse-reports: + lighthouse-cypress-vitest: needs: ["svelte-check"] if: github.event.pull_request.draft == false timeout-minutes: 40 @@ -73,10 +75,7 @@ jobs: cache: "npm" - name: Install dependencies - run: npm i - - - name: Echo expression - run: echo ${{ (github.actor != 'dependabot[bot]' && 'wc:test:record') || 'wc:test' }} + run: npm install - name: Add Rust wasm target run: rustup target add wasm32-unknown-unknown @@ -124,9 +123,6 @@ jobs: # set -euxo pipefail # npm run wc:test:vi - - name: Set-up env - uses: ./.github/workflows/webclient-setup - - name: Run Cypress tests uses: cypress-io/github-action@v5 with: diff --git a/wc.Dockerfile.dockerignore b/Dockerfile.dockerignore similarity index 100% rename from wc.Dockerfile.dockerignore rename to Dockerfile.dockerignore diff --git a/ex.Dockerfile b/ex.Dockerfile new file mode 100644 index 000000000..c99499a88 --- /dev/null +++ b/ex.Dockerfile @@ -0,0 +1,43 @@ +# syntax = docker/dockerfile:1 + +# Adjust NODE_VERSION as desired +ARG NODE_VERSION=18.16.1 +FROM node:${NODE_VERSION}-slim as base + +LABEL fly_launch_runtime="Node.js" + +# Node.js app lives here +WORKDIR /app + +# Set production environment +ENV NODE_ENV="production" + + +# Throw-away build stage to reduce size of final image +FROM base as build + +# Install packages needed to build node modules +RUN apt-get update -qq && \ + apt-get install --no-install-recommends -y build-essential node-gyp pkg-config python-is-python3 + +# Copy application code +COPY --link . . + +# Install node modules +RUN npm install --include=dev + +# Build application +RUN npm run ex:build + +# Remove development dependencies +RUN npm prune --omit=dev + +# Final stage for app image +FROM base + +# Copy built application +COPY --from=build /app /app + +# Start the server by default, this can be overwritten at runtime +EXPOSE 3000 +CMD [ "npm", "run", "ex:start" ] diff --git a/ex.prod.fly.toml b/ex.prod.fly.toml new file mode 100644 index 000000000..7d36d6ef0 --- /dev/null +++ b/ex.prod.fly.toml @@ -0,0 +1,24 @@ +# fly.toml app configuration file generated for hot-or-not-kit on 2024-01-04T16:13:20+05:30 +# +# See https://fly.io/docs/reference/configuration/ for information about how to use this file. +# + +app = "experiments-kit" +primary_region = "bos" + +[build] + dockerfile = "ex.Dockerfile" + ignorefile = "Dockerfile.dockerignore" + +[http_service] + internal_port = 3000 + force_https = true + auto_stop_machines = true + auto_start_machines = true + min_machines_running = 0 + processes = ["app"] + +[[vm]] + cpu_kind = "shared" + cpus = 1 + memory_mb = 1024 diff --git a/ex.staging.fly.toml b/ex.staging.fly.toml new file mode 100644 index 000000000..d196df4da --- /dev/null +++ b/ex.staging.fly.toml @@ -0,0 +1,24 @@ +# fly.toml app configuration file generated for hot-or-not-kit on 2024-01-04T16:13:20+05:30 +# +# See https://fly.io/docs/reference/configuration/ for information about how to use this file. +# + +app = "experiments-kit-staging" +primary_region = "bos" + +[build] + dockerfile = "ex.Dockerfile" + ignorefile = "Dockerfile.dockerignore" + +[http_service] + internal_port = 3000 + force_https = true + auto_stop_machines = true + auto_start_machines = true + min_machines_running = 0 + processes = ["app"] + +[[vm]] + cpu_kind = "shared" + cpus = 1 + memory_mb = 1024 diff --git a/package.json b/package.json index 4211291ed..44158cd87 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "ex:build:static": "npm run build:static --w @hnn/experiments", "ex:dev": "npm run dev --w @hnn/experiments", "ex:preview": "npm run preview --w @hnn/experiments", + "ex:start": "npm run start --w @hnn/experiments", "ex:sync": "npm run sync --w @hnn/experiments", "serve:lhci": "npm run wc:preview", "wc:check": "npm run wc:sync && npm run check --w @hnn/web-client", diff --git a/packages/experiments/package.json b/packages/experiments/package.json index bcefdc1e7..80e17fb38 100644 --- a/packages/experiments/package.json +++ b/packages/experiments/package.json @@ -12,6 +12,7 @@ "check": "svelte-check --tsconfig ./tsconfig.json --ignore .svelte-kit,build,tests --threshold warning --diagnostic-sources \"js,ts,svelte\"", "check:watch": "svelte-check --tsconfig ./tsconfig.json --watch", "tsc": "tsc -b", + "start": "node build", "sync": "svelte-kit sync", "lint": "prettier --check --plugin-search-dir=. . && eslint .", "format": "prettier --write --plugin-search-dir=. ." diff --git a/packages/web-client/src/lib/helpers/backend.ts b/packages/web-client/src/lib/helpers/backend.ts index dbeece6da..278840516 100644 --- a/packages/web-client/src/lib/helpers/backend.ts +++ b/packages/web-client/src/lib/helpers/backend.ts @@ -27,6 +27,8 @@ export const host = ? 'http://localhost:4943' : 'https://ic0.app' +export const WEBCLIENT_CANISTER_ID = process.env.WEBCLIENT_CANISTER_ID + export type UserIndexActor = ActorSubclass<_USER_INDEX_SERVICE> export type IndividualUserActor = ActorSubclass<_INDIVIDUAL_USER_SERVICE> export type PostCacheActor = ActorSubclass<_POST_CACHE_SERVICE> diff --git a/packages/web-client/src/routes/(feed)/menu/+page.svelte b/packages/web-client/src/routes/(feed)/menu/+page.svelte index 653091c5e..91237535a 100644 --- a/packages/web-client/src/routes/(feed)/menu/+page.svelte +++ b/packages/web-client/src/routes/(feed)/menu/+page.svelte @@ -9,6 +9,7 @@ import { handleParams } from '$lib/utils/params' import type { IconName } from '@hnn/components/icon/icon.type' import Icon from '@hnn/components/icon/Icon.svelte' import Switch from '@hnn/components/switch/Switch.svelte' +import { WEBCLIENT_CANISTER_ID } from '$lib/helpers/backend' let links: { icon: IconName @@ -170,7 +171,7 @@ onMount(() => { {#if !$page.url.host.includes('ic0.app')} diff --git a/packages/web-client/src/routes/refer-earn/+page.svelte b/packages/web-client/src/routes/refer-earn/+page.svelte index d6a561d60..0b51e09ca 100644 --- a/packages/web-client/src/routes/refer-earn/+page.svelte +++ b/packages/web-client/src/routes/refer-earn/+page.svelte @@ -17,6 +17,7 @@ import { authState, loadingAuthStatus } from '$lib/stores/auth' import { navigateBack } from '$lib/stores/navigation' import { userProfile } from '$lib/stores/app' import { onMount } from 'svelte' +import { WEBCLIENT_CANISTER_ID } from '$lib/helpers/backend' let selectedTab = 0 let endOfList = false @@ -97,7 +98,7 @@ $: loggedIn = $authState.isLoggedIn && !$loadingAuthStatus $: link = !loggedIn ? '' : $page.url.host.includes('ic0.app') - ? `https://vyatz-hqaaa-aaaam-qauea-cai.raw.ic0.app/profile/${$userProfile.principal_id}?refId=${$userProfile.principal_id}&login=true` + ? `https://${WEBCLIENT_CANISTER_ID}.raw.ic0.app/profile/${$userProfile.principal_id}?refId=${$userProfile.principal_id}&login=true` : `https://${$page.url.host}/profile/${$userProfile.principal_id}?refId=${$userProfile.principal_id}&login=true` diff --git a/wc.prod.fly.toml b/wc.prod.fly.toml index fd50ee347..d4c6c9b9d 100644 --- a/wc.prod.fly.toml +++ b/wc.prod.fly.toml @@ -8,7 +8,7 @@ primary_region = "bos" [build] dockerfile = "wc.Dockerfile" - ignorefile = "wc.Dockerfile.dockerignore" + ignorefile = "Dockerfile.dockerignore" [http_service] internal_port = 3000 diff --git a/wc.staging.fly.toml b/wc.staging.fly.toml index 942b03580..17f6233bb 100644 --- a/wc.staging.fly.toml +++ b/wc.staging.fly.toml @@ -8,7 +8,7 @@ primary_region = "bos" [build] dockerfile = "wc.Dockerfile" - ignorefile = "wc.Dockerfile.dockerignore" + ignorefile = "Dockerfile.dockerignore" [http_service] internal_port = 3000