From 655b0735bb8e662f713feb5e40f883a9be723ec8 Mon Sep 17 00:00:00 2001 From: Kilu Date: Sun, 30 Jun 2024 15:31:16 +0800 Subject: [PATCH] fix: deploy --- .github/workflows/deploy_test_web.yaml | 4 +- .github/workflows/deploy_web.yaml | 93 +++++++++++++++++++ frontend/appflowy_web_app/deploy.sh | 13 +++ .../src/components/publish/PublishView.tsx | 2 +- 4 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/deploy_web.yaml create mode 100644 frontend/appflowy_web_app/deploy.sh diff --git a/.github/workflows/deploy_test_web.yaml b/.github/workflows/deploy_test_web.yaml index 779e974482..dc9b30044c 100644 --- a/.github/workflows/deploy_test_web.yaml +++ b/.github/workflows/deploy_test_web.yaml @@ -3,7 +3,7 @@ name: Deploy Web (Test) on: push: branches: - - build/test + - build/old-test env: NODE_VERSION: "18.16.0" PNPM_VERSION: "8.5.0" @@ -72,4 +72,4 @@ jobs: docker system prune -f docker build -t appflowy-web-app . docker rm -f appflowy-web-app || true - docker run -d -p 3000:80 --env-file .env --name appflowy-web-app appflowy-web-app + docker run -d -p 30012:80 --env-file .env --name appflowy-web-app appflowy-web-app diff --git a/.github/workflows/deploy_web.yaml b/.github/workflows/deploy_web.yaml new file mode 100644 index 0000000000..9070c7d33d --- /dev/null +++ b/.github/workflows/deploy_web.yaml @@ -0,0 +1,93 @@ +name: Deploy + +on: + push: + branches: + - build/test + workflow_dispatch: + inputs: + environment: + description: 'Environment' + required: true + default: 'test' +env: + NODE_VERSION: "18.16.0" + PNPM_VERSION: "8.5.0" + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: setup node + uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODE_VERSION }} + - name: setup pnpm + uses: pnpm/action-setup@v2 + with: + version: ${{ env.PNPM_VERSION }} + - name: Node_modules cache + uses: actions/cache@v2 + with: + path: frontend/appflowy_web_app/node_modules + key: node-modules-${{ runner.os }} + - name: install frontend dependencies + 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' + 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 + - name: test and lint + working-directory: frontend/appflowy_web_app + run: | + pnpm run lint + - name: build + working-directory: frontend/appflowy_web_app + run: | + pnpm run build + - name: Archive build output + working-directory: frontend/appflowy_web_app + run: | + tar -czf build-output.tar.gz frontend/appflowy_web_app/dist frontend/appflowy_web_app/server.cjs frontend/appflowy_web_app/start.sh frontend/appflowy_web_app/Dockerfile frontend/appflowy_web_app/nginx.conf frontend/appflowy_web_app/.env + + - name: Deploy to EC2 (Test) + if: github.event.inputs.environment == 'test' || github.ref == 'refs/heads/build/test' + uses: easingthemes/ssh-deploy@main + with: + SSH_PRIVATE_KEY: ${{ secrets.WEB_TEST_SSH_PRIVATE_KEY }} + ARGS: "-rlgoDzvc -i" + SOURCE: build-output.tar.gz 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 + - name: Deploy to EC2 (Prod) + if: github.event.inputs.environment == 'prod' + uses: easingthemes/ssh-deploy@main + with: + SSH_PRIVATE_KEY: ${{ secrets.WEB_PROD_SSH_PRIVATE_KEY }} + ARGS: "-rlgoDzvc -i" + TARGET: /home/${{ secrets.WEB_PROD_REMOTE_USER }}/appflowy-web-app + SOURCE: build-output.tar.gz 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 diff --git a/frontend/appflowy_web_app/deploy.sh b/frontend/appflowy_web_app/deploy.sh new file mode 100644 index 0000000000..3f4cda1837 --- /dev/null +++ b/frontend/appflowy_web_app/deploy.sh @@ -0,0 +1,13 @@ +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/src/components/publish/PublishView.tsx b/frontend/appflowy_web_app/src/components/publish/PublishView.tsx index 3b603cc417..7e2d5edb97 100644 --- a/frontend/appflowy_web_app/src/components/publish/PublishView.tsx +++ b/frontend/appflowy_web_app/src/components/publish/PublishView.tsx @@ -80,10 +80,10 @@ export function PublishView({ namespace, publishName }: PublishViewProps) { }} openDrawer={open} /> - {open && setOpen(false)} />} + {open && setOpen(false)} />} );