Skip to content

Commit

Permalink
Merge pull request #19 from fastcampus-711/develop
Browse files Browse the repository at this point in the history
PR_1
  • Loading branch information
alreadyme24 authored May 27, 2024
2 parents 4334af1 + 9ec8701 commit 4826e3a
Show file tree
Hide file tree
Showing 96 changed files with 6,182 additions and 233 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Next.js Docker Build 🍃

# triggers ci cd when you push code to any branch
on:
push:
branches: [ "main" ]
workflow_dispatch:

jobs:
build-and-test:
runs-on: ubuntu-latest
environment: dev
env:
image_name: ${{ secrets.DOCKER_REPO }}/docker/711-front
image_tag: ${{ github.sha }}

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Building Docker Image
run: |
docker login ${{ secrets.DOCKER_REPO }} -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t ${{ env.image_name }}:${{ env.image_tag }} -t ${{ env.image_name }}:latest .
docker push ${{ env.image_name }}:${{ env.image_tag }}
docker push ${{ env.image_name }}:latest
deployment:
name: Argo Deployment
runs-on: ubuntu-22.04
environment: dev
env:
branch_name: helm
image_tag: ${{ github.sha }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ env.branch_name }}
submodules: 'recursive' # Actions -> General -> Workflow permissions (add write)
token: ${{ secrets.GITHUB_TOKEN }} # Ensure the token is being used

- name: Change values.yaml
run: |
sed -i "s/tag: \".*\"/tag: \"${{ env.image_tag }}\"/g" values.yaml
- name: Git Push
run: |
git config --global user.email "GitHub Actions [email protected]"
git config --global user.name "GitHub Actions Bot"
git add values.yaml
git commit -m "change image tag: ${{ env.image_tag }}"
git -c http.extraHeader="AUTHORIZATION: bearer ${{ secrets.GITHUB_TOKEN }}" pull --rebase origin ${{ env.branch_name }}
git -c http.extraHeader="AUTHORIZATION: bearer ${{ secrets.GITHUB_TOKEN }}" push origin ${{ env.branch_name }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts

# testdata
db.json
41 changes: 41 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM node:18-alpine AS base

# Install dependencies only when needed
FROM base AS deps
RUN apk add --no-cache libc6-compat python3 build-base
WORKDIR /app
COPY package.json ./
RUN yarn install --frozen-lockfile
RUN rm -rf ./.next/cache

# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY . .
COPY --from=deps /app/node_modules ./node_modules
RUN yarn build
RUN yarn install --frozen-lockfile --production
RUN rm -rf ./.next/cache

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

ENV NODE_ENV=production
ENV SHOULD_PROFILE=true
ENV SHOULD_TRACE=true

RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001

COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/next.config.js ./next.config.js

USER nextjs

EXPOSE 3000

CMD ["yarn", "start"]
26 changes: 26 additions & 0 deletions app/api/community/[category]/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { NextRequest } from "next/server"

export const GET = async (
request: NextRequest,
context: { params: { category: string; id: string } }
) => {
const { category, id } = context.params

try {
const response = await fetch(
// `http://localhost:3001/${category}/${id}`,
`https://711.ha-ving.store/boards/${category}/${id}`,
{
cache: "no-store"
}
)
if (response.ok) {
const responseData = await response.json()
return Response.json(responseData)
} else {
console.error("게시물 불러오기를 실패했습니다.")
}
} catch (error) {
console.error("에러 발생:", error)
}
}
35 changes: 35 additions & 0 deletions app/api/community/[category]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type { NextRequest } from "next/server"

export const GET = async (
request: NextRequest,
context: { params: { category: string } }
) => {
const { category } = context.params
const { searchParams } = request.nextUrl
// let url = `http://localhost:3001/${category}`
let url = `https://711.ha-ving.store/boards/${category}`

// searchParams가 비어있지 않고, title이 존재하면서 값이 "undefined"가 아닌 경우에만 title을 URL에 추가합니다.
if (
searchParams &&
searchParams.get("keyowrd") !== undefined &&
searchParams.get("keyword") !== "undefined"
) {
url += `?keyword=${searchParams.get("keyword")}`
}

try {
const response = await fetch(url, {
cache: "no-store"
})
if (response.ok) {
console.log(url)
const responseData = await response.json()
return Response.json(responseData)
} else {
console.error("게시물 불러오기를 실패했습니다.")
}
} catch (error) {
console.error("에러 발생:", error)
}
}
7 changes: 7 additions & 0 deletions app/api/frontmenu/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { NextRequest } from "next/server"

export const GET = async (request: NextRequest) => {
const res = await fetch("https://711.ha-ving.store/menu/front")
const menus = await res.json()
return Response.json(menus)
}
30 changes: 30 additions & 0 deletions app/community/[category]/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import FreeBoardDetail from "@/components/FreeBoardDetail"
import QnaDetail from "@/components/QnaDetail"
import ShareMarketDetail from "@/components/ShareMarketDetail"

export default async function Page({
params
}: {
params: { category: string; id: string }
}) {
const { category, id } = params

const res = await fetch(
`${process.env.NEXT_PUBLIC_CLIENT_URL}/api/community/${category}/${id}`
)
const responseData = await res.json()
let componentProps = { responseData }
let contentComponent

if (category === "qnas") {
contentComponent = <QnaDetail {...componentProps} />
} else if (category === "markets") {
contentComponent = <ShareMarketDetail {...componentProps} />
} else if (category === "frees") {
contentComponent = <FreeBoardDetail {...componentProps} />
} else {
contentComponent = null
}

return <div className="max-w-[1200px] m-auto">{contentComponent}</div>
}
59 changes: 59 additions & 0 deletions app/community/[category]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import FreeBoardContent from "@/components/FreeBoardContent"
import ShareMarketContent from "@/components/ShareMarketContent"
import QnaContent from "@/components/QnaContent"
import CommunitySearch from "@/components/CommunitySearch"
import Link from "next/link"
import BoardSubMenuBar from "@/components/submenu/SubMenuBar"
import SetCategory from "@/components/SetCategory"

export default async function Page({
params,
searchParams
}: {
params: { category: string }
searchParams: { title: string }
}) {
const { category } = params
const { title } = searchParams

const res = await fetch(
`${process.env.NEXT_PUBLIC_CLIENT_URL}/api/community/${category}?keyword=${title}`
)
const responseData = await res.json()
let componentProps = { responseData, category }
let contentComponent

if (category === "qnas") {
contentComponent = <QnaContent {...componentProps} />
} else if (category === "markets") {
contentComponent = <ShareMarketContent {...componentProps} />
} else if (category === "frees") {
contentComponent = <FreeBoardContent {...componentProps} />
} else {
contentComponent = null
}
return (
<div className="max-w-[1200px] m-auto mb-40">
<SetCategory category={category} />
<div className="py-8">
<p className="text-grey_900 text-[32px] font-semibold">소통공간</p>
</div>
{/* <Link href={"/community/freeboard"}>자유게시판</Link>
<Link href={"/community/sharemarket"}>나눔장터</Link>
<Link href={"/community/qna"}>QnA</Link>
<CommunitySearch category={category} /> */}
<div className="flex justify-between">
<BoardSubMenuBar
option="community"
category={category}
/>
<CommunitySearch
category={category}
placeholder="게시판 내 재검색"
className="flex-1 max-w-[480px]"
/>
</div>
{contentComponent}
</div>
)
}
11 changes: 11 additions & 0 deletions app/complaints/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import BoardSubMenuBar from "@/components/submenu/SubMenuBar"

export default function Board() {
return (
<div className="max-w-[1200px] m-auto mb-40">
<div className="py-8">
<p className="text-grey_900 text-[32px] font-semibold">민원게시판</p>
</div>
</div>
)
}
9 changes: 9 additions & 0 deletions app/disclosure/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function Disclosure() {
return (
<div className="max-w-[1200px] m-auto mb-40">
<div className="py-8">
<p className="text-grey_900 text-[32px] font-semibold">의무공개</p>
</div>
</div>
)
}
Loading

0 comments on commit 4826e3a

Please sign in to comment.