From c835884116feceec3acbee83c4b3a8bc13065a6f Mon Sep 17 00:00:00 2001 From: minidonut Date: Sat, 12 Aug 2023 14:38:44 +0900 Subject: [PATCH] feat: prepare live deploy --- .github/workflows/deploy-dev.yaml | 3 + .github/workflows/deploy-prod.yaml | 60 +++++++++++++++++++ packages/api/src/clientFactory.ts | 2 +- packages/service-backend/package.json | 1 + .../app/deck/[id]/DeckDetail.tsx | 4 +- packages/service-frontend/package.json | 6 +- packages/service-frontend/sst.config.ts | 3 +- 7 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/deploy-prod.yaml diff --git a/.github/workflows/deploy-dev.yaml b/.github/workflows/deploy-dev.yaml index 4253e2f..3b3e2d4 100644 --- a/.github/workflows/deploy-dev.yaml +++ b/.github/workflows/deploy-dev.yaml @@ -5,6 +5,9 @@ on: branches: ['master'] env: + STAGE: 'dev' + NEXT_PUBLIC_STAGE: 'dev' + # AWS AWS_REGION: 'ap-northeast-2' AWS_HOST_ZONE: ${{ secrets.AWS_HOST_ZONE }} diff --git a/.github/workflows/deploy-prod.yaml b/.github/workflows/deploy-prod.yaml new file mode 100644 index 0000000..3d1fe83 --- /dev/null +++ b/.github/workflows/deploy-prod.yaml @@ -0,0 +1,60 @@ +name: deploy-prod + +on: + release: + types: + - created + +env: + STAGE: 'prod' + NEXT_PUBLIC_STAGE: 'prod' + + # AWS + AWS_REGION: 'ap-northeast-2' + AWS_HOST_ZONE: ${{ secrets.AWS_HOST_ZONE }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + + # DOMAIN + DOMAIN_NAME: ${{ secrets.DOMAIN_NAME }} + DOMAIN_NAME_API: api.${{ secrets.DOMAIN_NAME }} + NEXT_PUBLIC_API_HOST: api.${{ secrets.DOMAIN_NAME }} + S3_PRIVATE_BUCKET: ${{ secrets.S3_PRIVATE_BUCKET }} + + # SENTRY + WEB_SENTRY_DSN: ${{ secrets.WEB_SENTRY_DSN }} + +jobs: + deploy-dev: + name: deploy to development environment + timeout-minutes: 15 + runs-on: ubuntu-latest + # To use Remote Caching, uncomment the next lines and follow the steps below. + # env: + # TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + # TURBO_TEAM: ${{ vars.TURBO_TEAM }} + + steps: + - name: Check out code + uses: actions/checkout@v3 + with: + fetch-depth: 2 + + - uses: pnpm/action-setup@v2.0.1 + with: + version: 8.6.3 + + - name: Setup Node.js environment + uses: actions/setup-node@v3 + with: + node-version: 18 + cache: 'pnpm' + + - name: Install dependencies + run: pnpm install + + - name: Build + run: pnpm build + + - name: Deploy development + run: pnpm deploy:dev diff --git a/packages/api/src/clientFactory.ts b/packages/api/src/clientFactory.ts index c3496d6..e53f08f 100644 --- a/packages/api/src/clientFactory.ts +++ b/packages/api/src/clientFactory.ts @@ -3,7 +3,7 @@ import { authTokenRepository } from './AuthTokenRepository'; export function createApiClient({ auth }: { auth: boolean }) { const client = axios.create({ - baseURL: 'https://' + 'api.dev.ppoba.app' + '/v1', + baseURL: 'https://' + process.env.NEXT_PUBLIC_API_HOST + '/v1', }); if (auth) { diff --git a/packages/service-backend/package.json b/packages/service-backend/package.json index 407ca00..5a1f385 100644 --- a/packages/service-backend/package.json +++ b/packages/service-backend/package.json @@ -12,6 +12,7 @@ "scripts": { "build": "tsc -p tsconfig.build.json --noEmit && npx webpack", "deploy:dev": "STAGE=dev make all", + "deploy:prod": "STAGE=prod make all", "dev": "ts-node src/entry.local.ts", "dev:debug": "node --require ts-node/register --inspect-brk src/entry.local.ts", "lint": "eslint . --ext .js,.ts", diff --git a/packages/service-frontend/app/deck/[id]/DeckDetail.tsx b/packages/service-frontend/app/deck/[id]/DeckDetail.tsx index 4a77f88..53c6ddd 100644 --- a/packages/service-frontend/app/deck/[id]/DeckDetail.tsx +++ b/packages/service-frontend/app/deck/[id]/DeckDetail.tsx @@ -101,7 +101,9 @@ export default function DeckDetail({ params }: Props): JSX.Element { const result = await share({ title: 'PPOBA - 뽀바', text: '뽀바, 너만의 카드게임을 즐겨봐', - url: `https://dev.ppoba.app/deck/${params.id}`, + url: `https://${ + process.env.NEXT_PUBLIC_STAGE === 'prod' ? '' : 'dev.' + }ppoba.app/deck/${params.id}`, }) if (result === 'copiedToClipboard') { alert('링크를 클립보드에 복사했습니다.') diff --git a/packages/service-frontend/package.json b/packages/service-frontend/package.json index f89bc7b..1eb3664 100644 --- a/packages/service-frontend/package.json +++ b/packages/service-frontend/package.json @@ -4,8 +4,8 @@ "private": true, "scripts": { "build": "next build", - "deploy:dev": "sst deploy --stage dev", - "deploy:prod": "sst deploy --stage prod", + "deploy:dev": "STAGE=dev sst deploy --stage dev", + "deploy:prod": "STAGE=prod sst deploy --stage prod", "dev": "next dev", "lint": "next lint", "test": "jest", @@ -56,4 +56,4 @@ "sst": "^2.8.27", "ts-jest": "^29.1.0" } -} \ No newline at end of file +} diff --git a/packages/service-frontend/sst.config.ts b/packages/service-frontend/sst.config.ts index c6032b8..3e11412 100644 --- a/packages/service-frontend/sst.config.ts +++ b/packages/service-frontend/sst.config.ts @@ -4,7 +4,7 @@ import { NextjsSite } from 'sst/constructs' export default { config(_input) { return { - name: 'ppoba-frontend', + name: `ppoba-frontend`, region: 'ap-northeast-2', } }, @@ -17,6 +17,7 @@ export default { }, runtime: 'nodejs18.x', environment: { + NEXT_PUBLIC_STAGE: process.env.STAGE!, NEXT_PUBLIC_API_HOST: process.env.DOMAIN_NAME_API!, NEXT_PUBLIC_WEB_SENTRY_DSN: process.env.WEB_SENTRY_DSN!, },