Skip to content

Commit

Permalink
๐Ÿš€ EC2 ์ž๋™ ๋ฐฐํฌ (#132)
Browse files Browse the repository at this point in the history
* feat: deploy.yaml ์ถ”๊ฐ€

* fix: SunEditor ๊ด€๋ จ ๋นŒ๋“œ ์˜ค๋ฅ˜ ์ˆ˜์ •

* fix: add missing use client

* test: ์ž๋™ ๋ฐฐํฌ

* feat: deploy.yaml์— ssh-action ์ ์šฉ

* test: ์ž๋™ ๋ฐฐํฌ

* deploy: ๋ฐฐํฌ ๋ธŒ๋žœ์น˜ main์œผ๋กœ ๋ณ€๊ฒฝ
  • Loading branch information
yeolyi authored Feb 10, 2024
1 parent 5c5da31 commit 1e56f72
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 44 deletions.
43 changes: 33 additions & 10 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,38 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: SSH Remote Commands
uses: appleboy/[email protected]
- name: Setup Node.js environment
uses: actions/[email protected]

- name: Checkout
uses: actions/checkout@v3

- name: Log in to the Container Registry
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}

- name: Create .env file
run: |
echo "NEXT_PUBLIC_KAKAO_MAP_API_KEY=${{secrets.KAKAO_MAP_API_KEY}}" > .env.local
- name: Build and push Docker images
uses: docker/[email protected]
with:
context: '.'
push: true
tags: |
ghcr.io/wafflestudio/csereal_nextjs_image:latest
ghcr.io/wafflestudio/csereal_nextjs_image:${{github.sha}}
- name: executing remote ssh commands using password
uses: appleboy/[email protected]
with:
host: ${{secrets.SSH_HOST}}
username: ${{secrets.SSH_USER}}
key: ${{secrets.SSH_KEY}}
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
script: |
cd ~/csereal-web
git pull
npm i
npm run build
pm2 restart csereal_front
docker stop csereal_nextjs_image
docker rm csereal_nextjs_image
docker pull ghcr.io/wafflestudio/csereal_nextjs_image:latest
docker run -d -p 3000:3000 --name csereal_nextjs_image ghcr.io/wafflestudio/csereal_nextjs_image
101 changes: 88 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi

Expand All @@ -25,12 +25,14 @@ COPY . .
# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
ENV NEXT_TELEMETRY_DISABLED 1

# RUN yarn build
# ENV NEXT_TELEMETRY_DISABLED 1

# If using npm comment out above and use below instead
RUN npm run build
RUN \
if [ -f yarn.lock ]; then yarn run build; \
elif [ -f package-lock.json ]; then npm run build; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
else echo "Lockfile not found." && exit 1; \
fi

# Production image, copy all the files and run next
FROM base AS runner
Expand All @@ -40,24 +42,97 @@ ENV NODE_ENV production
# Uncomment the following line in case you want to disable telemetry during runtime.
ENV NEXT_TELEMETRY_DISABLED 1

RUN addgroup --system --gid 1001 yeolyi1310
RUN adduser --system --uid 1001 yeolyi1310

USER yeolyi1310
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public

# Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000

ENV PORT 3000
ENV HOSTNAME localhost
# set hostname to localhost
ENV HOSTNAME "0.0.0.0"

# ์‹œ๊ฐ„๋Œ€ ์„ค์ •
ENV TZ Asia/Seoul
ENV LANG ko_KR.UTF-8
ENV TIME ko_KR.UTF-8

# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
CMD ["node", "server.js"]

# FROM node:18-alpine AS base

# # Install dependencies only when needed
# FROM base AS deps
# # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
# RUN apk add --no-cache libc6-compat
# WORKDIR /app

# # Install dependencies based on the preferred package manager
# COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
# RUN \
# if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
# elif [ -f package-lock.json ]; then npm ci; \
# elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
# else echo "Lockfile not found." && exit 1; \
# fi


# # Rebuild the source code only when needed
# FROM base AS builder
# WORKDIR /app
# COPY --from=deps /app/node_modules ./node_modules
# COPY . .

# # Next.js collects completely anonymous telemetry data about general usage.
# # Learn more here: https://nextjs.org/telemetry
# # Uncomment the following line in case you want to disable telemetry during the build.
# ENV NEXT_TELEMETRY_DISABLED 1

# # RUN yarn build

# # If using npm comment out above and use below instead
# RUN npm run build

# # Production image, copy all the files and run next
# FROM base AS runner
# WORKDIR /app

# ENV NODE_ENV production
# # Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED 1

# RUN addgroup --system --gid 1001 yeolyi1310
# RUN adduser --system --uid 1001 yeolyi1310

# USER yeolyi1310

# COPY --from=builder /app/public ./public

# # Automatically leverage output traces to reduce image size
# # https://nextjs.org/docs/advanced-features/output-file-tracing
# COPY --from=builder /app/.next/standalone ./
# COPY --from=builder /app/.next/static ./.next/static

# EXPOSE 3000

# ENV PORT 3000
# ENV HOSTNAME localhost
# ENV TZ Asia/Seoul
# ENV LANG ko_KR.UTF-8
# ENV TIME ko_KR.UTF-8

# CMD ["node", "server.js"]
3 changes: 1 addition & 2 deletions app/[locale]/community/news/create/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use client';

import { useRouter } from 'next/navigation';

import { revalidateNewsTag } from '@/actions/newsActions';
import { useRouter } from '@/navigation';

import { postNews } from '@/apis/news';

Expand Down
4 changes: 4 additions & 0 deletions app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { notFound } from 'next/navigation';
import { NextIntlClientProvider } from 'next-intl';
import { unstable_setRequestLocale } from 'next-intl/server';
import { ReactNode } from 'react';
import { Toaster } from 'react-hot-toast';

Expand Down Expand Up @@ -31,6 +32,9 @@ export default async function RootLayout({
children: React.ReactNode;
params: { locale: string };
}) {
// https://next-intl-docs.vercel.app/docs/getting-started/app-router#static-rendering
unstable_setRequestLocale(params.locale);

return (
<html lang={params.locale}>
<body className="text-neutral-800 font-normal bg-white min-w-fit flex">
Expand Down
40 changes: 22 additions & 18 deletions components/editor/common/SunEditorWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
'use client';

import { MutableRefObject, Suspense, lazy } from 'react';
import { MutableRefObject, lazy } from 'react';
import { ko } from 'suneditor/src/lang/';
import SunEditorCore from 'suneditor/src/lib/core';
import plugins from 'suneditor/src/plugins';

// TODO
// ์ •๋ง ์™œ๊ทธ๋Ÿฌ๋Š”์ง€ ๋ชจ๋ฅด๊ฒ ๋Š”๋ฐ lazy + typeof window ์กฐํ•ฉ์œผ๋กœ๋งŒ ๋นŒ๋“œ๊ฐ€ ๋จ
// ๊ฑด๋“ค์ง€ ๋ง..๊ฒƒ..
const SunEditor = lazy(() => import('suneditor-react'));

import './suneditor.css';
Expand All @@ -18,7 +21,7 @@ export default function SunEditorWrapper({
initialContent?: string;
}) {
return (
<Suspense fallback={<SunEditorFallback />}>
typeof window !== 'undefined' && (
<SunEditor
getSunEditorInstance={(x) => (editorRef.current = x)}
setDefaultStyle={`padding: 1rem;`}
Expand All @@ -39,25 +42,26 @@ export default function SunEditorWrapper({
// imageUploadUrl: `${BASE_URL}/file/upload`,
}}
/>
</Suspense>
)
);
}

const SunEditorFallback = () => {
return (
<div className="animate-pulse flex flex-col mx-[3.75rem] mt-3 h-[400px]">
<div className="flex flex-col gap-2">
<div className="h-4 bg-[#ffffff] opacity-30 rounded w-2/5"></div>
<div className="h-4 bg-[#ffffff] opacity-30 rounded w-2/5"></div>
</div>
<div className="flex flex-1 flex-col gap-2 w-3/5 mt-4">
<div className="h-4 bg-[#ffffff] opacity-30 rounded"></div>
<div className="h-4 bg-[#ffffff] opacity-30 rounded"></div>
<div className="h-4 bg-[#ffffff] opacity-30 rounded"></div>
</div>
</div>
);
};
// Suspense ์“ฐ๋„๋ก ๊ณ ์น  ๋•Œ๊นŒ์ง€ ์‚ญ์ œ
// const SunEditorFallback = () => {
// return (
// <div className="animate-pulse flex flex-col mx-[3.75rem] mt-3 h-[400px]">
// <div className="flex flex-col gap-2">
// <div className="h-4 bg-[#ffffff] opacity-30 rounded w-2/5"></div>
// <div className="h-4 bg-[#ffffff] opacity-30 rounded w-2/5"></div>
// </div>
// <div className="flex flex-1 flex-col gap-2 w-3/5 mt-4">
// <div className="h-4 bg-[#ffffff] opacity-30 rounded"></div>
// <div className="h-4 bg-[#ffffff] opacity-30 rounded"></div>
// <div className="h-4 bg-[#ffffff] opacity-30 rounded"></div>
// </div>
// </div>
// );
// };

// https://github.com/JiHong88/SunEditor/issues/199
export const isContentEmpty = (editor: SunEditorCore) => {
Expand Down
1 change: 0 additions & 1 deletion components/layout/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { useTranslations } from 'next-intl';


import { BASE_URL } from '@/apis';
import { useSessionContext } from '@/contexts/SessionContext';
import { Link } from '@/navigation';
Expand Down
8 changes: 8 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ const withNextIntl = createNextIntlPlugin();
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
output: 'standalone',

// TODO: ์•„๋ž˜ ์˜ต์…˜ ์—†์ด ๋นŒ๋“œ
eslint: {
// Warning: This allows production builds to successfully complete even if
// your project has ESLint errors.
ignoreDuringBuilds: true,
},

webpack(config) {
// Grab the existing rule that handles SVG imports
Expand Down

0 comments on commit 1e56f72

Please sign in to comment.