Skip to content

Commit

Permalink
chore: modified deploy process
Browse files Browse the repository at this point in the history
  • Loading branch information
qinluhe committed Jun 29, 2024
1 parent 7ca3666 commit b458129
Show file tree
Hide file tree
Showing 12 changed files with 619 additions and 14 deletions.
84 changes: 84 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
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"

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: node_modules
key: node-modules-${{ runner.os }}
- name: install dependencies
run: |
pnpm install
- name: generate env file (Test)
if: github.event.inputs.environment == 'test' || github.ref == 'refs/heads/build/test'
run: |
echo "ENVIRONMENT=test" > .env
echo "NEXT_PUBLIC_API_KEY=${{ secrets.TEXT_NEXT_PUBLIC_API_KEY }}" >> .env
echo "NEXT_PUBLIC_GA_MEASUREMENT_ID=${{ secrets.TEXT_NEXT_PUBLIC_GA_MEASUREMENT_ID }}" >> .env
- name: generate env file (Prod)
if: github.event.inputs.environment == 'prod'
run: |
echo "ENVIRONMENT=production" > .env
echo "NEXT_PUBLIC_API_KEY=${{ secrets.PROD_NEXT_PUBLIC_API_KEY }}" >> .env
echo "NEXT_PUBLIC_GA_MEASUREMENT_ID=${{ secrets.PROD_NEXT_PUBLIC_GA_MEASUREMENT_ID }}" >> .env
- name: build
run: |
pnpm run build
- name: Archive build output
run: |
tar -czf build-output.tar.gz .next .env public Dockerfile start.sh next.config.js env.js nginx.conf
- 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.TEST_SSH_PRIVATE_KEY }}
ARGS: "-rlgoDzvc -i"
SOURCE: build-output.tar.gz deploy.sh
TARGET: /home/${{ secrets.TEST_SSH_USER }}/appflowy.io
REMOTE_HOST: ${{ secrets.TEST_SSH_HOST }}
REMOTE_USER: ${{ secrets.TEST_SSH_USER }}
SCRIPT_AFTER: |
cd appflowy.io
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.PROD_SSH_PRIVATE_KEY }}
ARGS: "-rlgoDzvc -i"
TARGET: /home/${{ secrets.PROD_SSH_USER }}/appflowy.io
SOURCE: build-output.tar.gz deploy.sh
REMOTE_HOST: ${{ secrets.PROD_SSH_HOST }}
REMOTE_USER: ${{ secrets.PROD_SSH_USER }}
SCRIPT_AFTER: |
cd appflowy.io
chmod +x deploy.sh
sh deploy.sh
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Use the official Node.js image as a base image
FROM node:18
# Create and change to the app directory
WORKDIR /app

RUN npm install -g [email protected]

RUN apt-get update && \
apt-get install -y nginx

COPY . .

RUN addgroup --system nginx && \
adduser --system --no-create-home --disabled-login --ingroup nginx nginx

RUN apt-get clean && rm -rf /var/lib/apt/lists/*

COPY nginx.conf /etc/nginx/nginx.conf
COPY .next/ /usr/share/nginx/html/.next/
COPY public/ /usr/share/nginx/html/public/

# Expose the port the app runs on
COPY start.sh /app/start.sh
COPY next.config.js /app/next.config.js
COPY .env /app/.env
COPY env.js /app/env.js

RUN chmod +x /app/start.sh

EXPOSE 80

CMD ["/app/start.sh"]
5 changes: 1 addition & 4 deletions app/invitation/expired/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ import ExpireDescription from '@/components/invitation/expired-description';
import InviteOwner from '@/components/invitation/invite-owner';
import InviteWorkspace from '@/components/invitation/invite-workspace';
import '@/styles/invitation.scss';
import { Poppins } from 'next/font/google';
import Image from 'next/image';
import Link from 'next/link';
import NextTopLoader from 'nextjs-toploader';

const poppins = Poppins({ subsets: ['latin'], weight: ['400', '500', '600', '700'] });

function Page() {
return (
<div className={`expired-page ${poppins.className}`}>
<div className={`expired-page`}>
<NextTopLoader showSpinner={false} color={'#9327FF'} />
<div className={'header'}>
<div className={'logo-wrapper'}>
Expand Down
5 changes: 1 addition & 4 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import './globals.scss';
import type { Metadata } from 'next';
import { Inter } from 'next/font/google';
import Favicon from '../public/favicon.ico';
import OpenGraph from '../public/images/og-image.png';
import App from '@/components/layout/app';
import { getModeForServer } from '@/lib/get-theme';
import { getGitData } from '@/lib/get-git';
import { getUAFromServer } from '@/lib/get-os';

const inter = Inter({ subsets: ['latin'] });

export const metadata: Metadata = {
title: 'AppFlowy.IO',
description: 'AppFlowy is an AI collaborative workspace where you achieve more without losing control of your data',
Expand Down Expand Up @@ -44,7 +41,7 @@ export default async function RootLayout({ children }: { children: React.ReactNo

return (
<html lang='en' className={mode}>
<body id={'body'} className={inter.className}>
<body id={'body'}>
<App ua={ua} gitData={gitData} mode={mode}>
{children}
</App>
Expand Down
8 changes: 3 additions & 5 deletions components/shared/over-title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ import darkIcon1 from '@/assets/images/download/dark/icon-1.png';
import darkIcon2 from '@/assets/images/download/dark/icon-2.png';
import darkIcon3 from '@/assets/images/download/dark/icon-3.png';
import { downloadPageConfig } from '@/lib/config/pages';
import { Manrope } from 'next/font/google';
import { useDarkContext } from '@/lib/hooks/use-dark-context';
import { motion, useMotionValue, useSpring } from 'framer-motion';

const manrope = Manrope({ subsets: ['latin'] });

function OverTitle({ title }: { title: string }) {
const dark = useDarkContext();
const ref = useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -56,7 +53,7 @@ function OverTitle({ title }: { title: string }) {
const currentScrollTop = document.documentElement.scrollTop;

const scrollDistance = -(currentScrollTop - diff) * delta;

if (Math.abs(scrollDistance) > scrollWidth / 2) {
return;
}
Expand Down Expand Up @@ -99,9 +96,10 @@ function OverTitle({ title }: { title: string }) {
<motion.div
style={{
x,
fontFamily: 'Manrope',
}}
ref={ref}
className={`translate-z-0 over-title transform ${manrope.className}`}
className={`translate-z-0 over-title transform`}
>
<div className={`title-text`}>{title}</div>
<div className={'icons'}>
Expand Down
14 changes: 14 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

rm -rf .next .env public start.sh Dockerfile next.config.js env.js nginx.conf

tar -xzf build-output.tar.gz

docker system prune -f

docker rm -f official-website-app || true

#
#docker build -t official-website-app .
#
#docker run -d --env-file .env -p 3001:80 official-website-app
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const nextConfig = {
},

// Use the CDN in production and localhost for development.
assetPrefix: isProd ? `https://d3uafhn8yrvdfn.cloudfront.net/website/${environment}` : undefined,
// assetPrefix: isProd ? `https://d3uafhn8yrvdfn.cloudfront.net/website/${environment}` : undefined,
rewrites,
images: {
remotePatterns: [
Expand Down
79 changes: 79 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# nginx.conf
user nginx;
worker_processes auto;

error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

gzip on;

gzip_static on;

gzip_http_version 1.0;

gzip_comp_level 5;

gzip_vary on;

gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript application/wasm;

# Existing server block for HTTP
server {
listen 80;
server_name localhost;

location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}

location /_next/static/ {
alias /usr/share/nginx/html/.next/static/;
expires 30d;
access_log off;
}

location /html/ {
alias /usr/share/nginx/html/public/html/;
expires 30d;
access_log off;
}

location /images/ {
alias /usr/share/nginx/html/public/images/;
expires 30d;
access_log off;
}
location /favicon.ico {
alias /usr/share/nginx/html/public/favicon.ico;
expires 30d;
access_log off;
}

}


}
9 changes: 9 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

# Start the nginx server
service nginx start

# Start the frontend server
next start

tail -f /dev/null
5 changes: 5 additions & 0 deletions styles/app.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
@import "font.scss";

body {
font-family: "Inter", sans-serif;
}

.appflowy-app {
@apply flex flex-col w-full overflow-x-hidden;
Expand Down
Loading

0 comments on commit b458129

Please sign in to comment.