diff --git a/.github/workflows/deploy_web.yaml b/.github/workflows/deploy_web.yaml index 761427a40f..7592015218 100644 --- a/.github/workflows/deploy_web.yaml +++ b/.github/workflows/deploy_web.yaml @@ -1,15 +1,28 @@ name: Deploy on: - push: - branches: - - build/test workflow_dispatch: inputs: environment: description: 'Environment' required: true default: 'test' + port: + description: 'Docker Port' + required: true + default: '30012' + api_base_url: + description: 'API Base URL' + required: true + default: 'https://test.appflowy.cloud' + api_gotrue_url: + description: 'GoTrue API URL' + required: true + default: 'https://test.appflowy.cloud/gotrue' + ws_url: + description: 'Websocket URL' + required: true + default: 'wss://test.appflowy.cloud/ws/v1' env: NODE_VERSION: "18.16.0" PNPM_VERSION: "8.5.0" @@ -40,16 +53,12 @@ jobs: working-directory: frontend/appflowy_web_app run: | pnpm install - - name: generate env file (Test) - if: github.event.inputs.environment == 'test' || github.ref == 'refs/heads/build/test' + - name: generate env file working-directory: frontend/appflowy_web_app run: | - cp test.env .env - - name: generate env file (Prod) - if: github.event.inputs.environment == 'prod' - working-directory: frontend/appflowy_web_app - run: | - cp beta.env .env + echo "AF_BASE_URL=${{ github.event.inputs.api_base_url }}" >> .env + echo "AF_GOTRUE_URL=${{ github.event.inputs.api_gotrue_url }}" >> .env + echo "AF_WS_URL=${{ github.event.inputs.ws_url }}" >> .env - name: test and lint working-directory: frontend/appflowy_web_app run: | @@ -61,22 +70,22 @@ jobs: - name: Archive build output working-directory: frontend/appflowy_web_app run: | - tar -czf build-output.tar.gz dist server.cjs start.sh Dockerfile nginx.conf .env supervisord.conf + tar -czf build-output.tar.gz dist deploy/server.cjs deploy/start.sh deploy/Dockerfile deploy/nginx.conf .env deploy/supervisord.conf - name: Deploy to EC2 (Test) - if: github.event.inputs.environment == 'test' || github.ref == 'refs/heads/build/test' + if: github.event.inputs.environment == 'test' uses: easingthemes/ssh-deploy@main with: SSH_PRIVATE_KEY: ${{ secrets.WEB_TEST_SSH_PRIVATE_KEY }} ARGS: "-rlgoDzvc -i" - SOURCE: frontend/appflowy_web_app/build-output.tar.gz frontend/appflowy_web_app/deploy.sh + SOURCE: frontend/appflowy_web_app/build-output.tar.gz frontend/appflowy_web_app/deploy/deploy.sh TARGET: /home/${{ secrets.WEB_TEST_REMOTE_USER }}/appflowy-web-app REMOTE_HOST: ${{ secrets.WEB_TEST_REMOTE_HOST }} REMOTE_USER: ${{ secrets.WEB_TEST_REMOTE_USER }} SCRIPT_AFTER: | cd appflowy-web-app chmod +x deploy.sh - sh deploy.sh + sh deploy.sh ${{ github.event.inputs.port }} - name: Deploy to EC2 (Prod) if: github.event.inputs.environment == 'prod' uses: easingthemes/ssh-deploy@main @@ -84,10 +93,10 @@ jobs: SSH_PRIVATE_KEY: ${{ secrets.WEB_PROD_SSH_PRIVATE_KEY }} ARGS: "-rlgoDzvc -i" TARGET: /home/${{ secrets.WEB_PROD_REMOTE_USER }}/appflowy-web-app - SOURCE: frontend/appflowy_web_app/build-output.tar.gz frontend/appflowy_web_app/deploy.sh + SOURCE: frontend/appflowy_web_app/build-output.tar.gz frontend/appflowy_web_app/deploy/deploy.sh REMOTE_HOST: ${{ secrets.WEB_PROD_REMOTE_HOST }} REMOTE_USER: ${{ secrets.WEB_PROD_REMOTE_USER }} SCRIPT_AFTER: | cd appflowy-web-app chmod +x deploy.sh - sh deploy.sh \ No newline at end of file + sh deploy.sh ${{ github.event.inputs.port }} \ No newline at end of file diff --git a/frontend/appflowy_web_app/README.md b/frontend/appflowy_web_app/README.md index c5c8ebf51f..991e745046 100644 --- a/frontend/appflowy_web_app/README.md +++ b/frontend/appflowy_web_app/README.md @@ -43,6 +43,16 @@ Before you begin, ensure you have the following installed: pnpm install ``` +- Modify the environment file in `frontend/appflowy_web_app/.env` to add or modify environment variables + +```bash +# Example +AF_BASE_URL=https://test.appflowy.cloud +AF_GOTRUE_URL=https://test.appflowy.cloud/gotrue +AF_WS_URL=wss://test.appflowy.cloud/ws/v1 + +``` + #### 🖥️ Desktop Application (Tauri) (Optional) > **Note**: if you want to run the web app in the browser, skip this step @@ -148,10 +158,6 @@ Don't modify the theme file in `frontend/appflowy_web_app/src/styles/variables` pnpm run css:variables ``` -#### How to add or modify the environment variables - -- Modify the environment file in `frontend/appflowy_web_app/.env` to add or modify environment variables - #### How to create symlink for the @appflowyinc/client-api-wasm in local development - Run the following command to create a symlink for the @appflowyinc/client-api-wasm diff --git a/frontend/appflowy_web_app/beta.env b/frontend/appflowy_web_app/beta.env deleted file mode 100644 index ab31b57db7..0000000000 --- a/frontend/appflowy_web_app/beta.env +++ /dev/null @@ -1,3 +0,0 @@ -AF_WS_URL=wss://beta.appflowy.cloud/ws/v1 -AF_BASE_URL=https://beta.appflowy.cloud -AF_GOTRUE_URL=https://beta.appflowy.cloud/gotrue \ No newline at end of file diff --git a/frontend/appflowy_web_app/deploy.sh b/frontend/appflowy_web_app/deploy.sh deleted file mode 100644 index 3f4cda1837..0000000000 --- a/frontend/appflowy_web_app/deploy.sh +++ /dev/null @@ -1,13 +0,0 @@ -rm -rf dist - -tar -xzf build-output.tar.gz - -rm -rf build-output.tar.gz - -docker system prune -f - -docker build -t appflowy-web-app . - -docker rm -f appflowy-web-app || true - -docker run -d --env-file .env -p 30012:80 --restart always --name appflowy-web-app appflowy-web-app \ No newline at end of file diff --git a/frontend/appflowy_web_app/Dockerfile b/frontend/appflowy_web_app/deploy/Dockerfile similarity index 92% rename from frontend/appflowy_web_app/Dockerfile rename to frontend/appflowy_web_app/deploy/Dockerfile index 12908f95c3..556f78b33f 100644 --- a/frontend/appflowy_web_app/Dockerfile +++ b/frontend/appflowy_web_app/deploy/Dockerfile @@ -7,7 +7,7 @@ RUN apt-get update && \ RUN bun install cheerio pino pino-pretty -COPY . . +COPY .. . COPY supervisord.conf /app/supervisord.conf @@ -17,7 +17,7 @@ RUN addgroup --system nginx && \ RUN apt-get clean && rm -rf /var/lib/apt/lists/* -COPY dist/ /usr/share/nginx/html/ +COPY ../dist /usr/share/nginx/html/ COPY nginx.conf /etc/nginx/nginx.conf diff --git a/frontend/appflowy_web_app/deploy/deploy.sh b/frontend/appflowy_web_app/deploy/deploy.sh new file mode 100644 index 0000000000..18a66c10db --- /dev/null +++ b/frontend/appflowy_web_app/deploy/deploy.sh @@ -0,0 +1,22 @@ +if [ -z "$1" ]; then + echo "No port number provided" + exit 1 +fi + +PORT=$1 + +echo "Starting deployment on port $PORT" + +rm -rf dist + +tar -xzf build-output.tar.gz + +rm -rf build-output.tar.gz + +docker system prune -f + +docker build -t appflowy-web-app-"$PORT" . + +docker rm -f appflowy-web-app-"$PORT" || true + +docker run -d --env-file .env -p "$PORT":80 --restart always --name appflowy-web-app-"$PORT" appflowy-web-app-"$PORT" \ No newline at end of file diff --git a/frontend/appflowy_web_app/nginx.conf b/frontend/appflowy_web_app/deploy/nginx.conf similarity index 100% rename from frontend/appflowy_web_app/nginx.conf rename to frontend/appflowy_web_app/deploy/nginx.conf diff --git a/frontend/appflowy_web_app/server.cjs b/frontend/appflowy_web_app/deploy/server.cjs similarity index 94% rename from frontend/appflowy_web_app/server.cjs rename to frontend/appflowy_web_app/deploy/server.cjs index 450f161038..a8bc3e6da7 100644 --- a/frontend/appflowy_web_app/server.cjs +++ b/frontend/appflowy_web_app/deploy/server.cjs @@ -6,7 +6,7 @@ const { fetch } = require('bun'); const distDir = path.join(__dirname, 'dist'); const indexPath = path.join(distDir, 'index.html'); - +const baseURL = process.env.AF_BASE_URL; const setOrUpdateMetaTag = ($, selector, attribute, content) => { if ($(selector).length === 0) { $('head').append(``); @@ -86,10 +86,6 @@ const createServer = async (req) => { let metaData; try { - const isBeta = hostname.startsWith('beta'); - const isTest = hostname.startsWith('test'); - const defaultUrl = 'https://beta.appflowy.cloud'; - const baseUrl = isBeta ? 'https://beta.appflowy.cloud' : isTest ? 'https://test.appflowy.cloud' : defaultUrl; metaData = await fetchMetaData(`${baseUrl}/api/workspace/published/${namespace}/${publishName}`); } catch (error) { logger.error(`Error fetching meta data: ${error}`); @@ -162,6 +158,7 @@ const start = () => { }, }); logger.info(`Server is running on port 3000`); + logger.info(`Base URL: ${baseURL}`); } catch (err) { logger.error(err); process.exit(1); diff --git a/frontend/appflowy_web_app/start.sh b/frontend/appflowy_web_app/deploy/start.sh similarity index 100% rename from frontend/appflowy_web_app/start.sh rename to frontend/appflowy_web_app/deploy/start.sh diff --git a/frontend/appflowy_web_app/supervisord.conf b/frontend/appflowy_web_app/deploy/supervisord.conf similarity index 100% rename from frontend/appflowy_web_app/supervisord.conf rename to frontend/appflowy_web_app/deploy/supervisord.conf diff --git a/frontend/appflowy_web_app/src/components/app/AppConfig.tsx b/frontend/appflowy_web_app/src/components/app/AppConfig.tsx index 16f70dba1b..cf1c24d466 100644 --- a/frontend/appflowy_web_app/src/components/app/AppConfig.tsx +++ b/frontend/appflowy_web_app/src/components/app/AppConfig.tsx @@ -4,25 +4,15 @@ import React, { createContext, useEffect, useState } from 'react'; import { AFService, AFServiceConfig } from '@/application/services/services.type'; import { getService } from '@/application/services'; -const hostName = window.location.hostname; -const isProd = !hostName.includes('localhost'); -const isBeta = isProd && hostName.includes('beta'); -const isTest = isProd && hostName.includes('test'); -const baseAPIHost = isProd - ? isBeta - ? 'beta.appflowy.cloud' - : isTest - ? 'test.appflowy.cloud' - : 'beta.appflowy.cloud' - : 'test.appflowy.cloud'; -const baseURL = `https://${baseAPIHost}`; -const gotrueURL = `${baseURL}/gotrue`; +const baseURL = import.meta.env.AF_BASE_URL; +const gotrueURL = import.meta.env.AF_GOTRUE_URL; +const wsURL = import.meta.env.AF_WS_URL; const defaultConfig: AFServiceConfig = { cloudConfig: { baseURL, gotrueURL, - wsURL: `wss://${baseAPIHost}/ws/v1`, + wsURL, }, }; diff --git a/frontend/appflowy_web_app/test.env b/frontend/appflowy_web_app/test.env deleted file mode 100644 index 89e2936fab..0000000000 --- a/frontend/appflowy_web_app/test.env +++ /dev/null @@ -1,3 +0,0 @@ -AF_WS_URL=wss://test.appflowy.cloud/ws/v1 -AF_BASE_URL=https://test.appflowy.cloud -AF_GOTRUE_URL=https://test.appflowy.cloud/gotrue \ No newline at end of file