Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

환경설정: aws-ci 변경 #209

Merged
merged 49 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
e182ae3
chore: .env 수정
bottlewook Feb 23, 2024
8b836d2
chore: env 수정
bottlewook Feb 23, 2024
80aec88
chore: yml 수정
bottlewook Feb 23, 2024
21a6955
chore: yml 수정
bottlewook Feb 23, 2024
3d3aca6
chore: yml 수정
bottlewook Feb 23, 2024
3a1ed8c
chore: yml 수정
bottlewook Feb 23, 2024
7ccf0e5
chore: yml 수정
bottlewook Feb 23, 2024
1210c3c
chore: yml 수정
bottlewook Feb 23, 2024
ae1ee31
chore: yml 수정
bottlewook Feb 23, 2024
1ffa492
chore: yml 수정
bottlewook Feb 23, 2024
48f6489
chore: yml 수정
bottlewook Feb 23, 2024
2671899
chore: yml 수정
bottlewook Feb 23, 2024
cf5fe9e
chore: yml 수정
bottlewook Feb 23, 2024
846f451
chore: yml 수정
bottlewook Feb 26, 2024
9a61b3a
chore: yml 수정
bottlewook Feb 26, 2024
bce172e
chore: yml 수정
bottlewook Feb 26, 2024
38a2079
chore: yml 수정
bottlewook Feb 26, 2024
68f1bd2
chore: yml 수정
bottlewook Feb 26, 2024
ec8210d
chore: yml 수정
bottlewook Feb 26, 2024
6d47979
chore: yml 수정
bottlewook Feb 26, 2024
01776d9
chore: yml 수정
bottlewook Feb 26, 2024
3d33ea6
chore: yml 수정
bottlewook Feb 26, 2024
432f857
chore: yml 수정
bottlewook Feb 26, 2024
7480b9b
chore: dockerfile 수정
bottlewook Feb 26, 2024
e2ecf1a
chore: dockerfile 수정
bottlewook Feb 26, 2024
c44a569
chore: yml 수정
bottlewook Feb 26, 2024
9eda5d3
chore: yml 수정
bottlewook Feb 26, 2024
bddcf56
chore: yml 수정
bottlewook Feb 26, 2024
35f11de
chore: yml 수정
bottlewook Feb 26, 2024
b3b7c50
chore: yml 수정
bottlewook Feb 26, 2024
e32d9c2
chore: yml 수정
bottlewook Feb 26, 2024
4d9e6e5
chore: yml 수정
bottlewook Feb 26, 2024
362df18
chore: yml 수정
bottlewook Feb 26, 2024
bd26189
chore: yml 수정
bottlewook Feb 26, 2024
bad2c55
chore: yml 수정
bottlewook Feb 26, 2024
c7de161
chore: yml 수정
bottlewook Feb 26, 2024
7846084
chore: yml 수정
bottlewook Feb 26, 2024
057e706
chore: yml 수정
bottlewook Feb 26, 2024
afd9ff0
chore: yml 수정
bottlewook Feb 26, 2024
8b19f3f
chore: yml 수정
bottlewook Feb 26, 2024
6b5479c
chore: yml 수정
bottlewook Feb 26, 2024
0082db8
chore: yml 수정
bottlewook Feb 26, 2024
6d34478
chore: yml 수정
bottlewook Feb 26, 2024
52fc86b
chore: yml 수정
bottlewook Feb 26, 2024
7f91d75
chore: yml 수정
bottlewook Feb 26, 2024
bfd18ee
chore: yml 수정
bottlewook Feb 26, 2024
c2b75fd
chore: yml 수정
bottlewook Feb 26, 2024
334122a
chore: yml 수정
bottlewook Feb 26, 2024
07d490a
chore: yml 수정
bottlewook Feb 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions .github/workflows/cd-aws.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Node.js environment
uses: actions/setup-node@v2
with:
node-version: '18'

- run: |
jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS_CONTEXT" > .env.local
env:
SECRETS_CONTEXT: ${{ toJson(secrets) }}

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
Expand All @@ -34,17 +24,24 @@ jobs:
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Create .env file
run: |
touch .env.local
echo "${{ secrets.ENV_PRODUCTION }}" > .env.production

- name: Build, tag, and push docker image to Amazon ECR
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: washfit-client
IMAGE_TAG: latest
run: |
docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG .
docker build --no-cache -t $REGISTRY/$REPOSITORY:$IMAGE_TAG .
docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG

- name: Application Run
uses: appleboy/[email protected]
env:
PORT: 8000
with:
host: ${{ secrets.AWS_EC2_HOST }}
username: ${{ secrets.AWS_USERNAME }}
Expand Down
58 changes: 32 additions & 26 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,50 +1,56 @@
FROM node:18-alpine AS base

FROM base AS deps
# Multi-stage build

# 1단계: 환경 설정 및 dependancy 설치
FROM node:18-alpine AS deps
RUN apk add --no-cache libc6-compat

# 명령어를 실행할 디렉터리 지정
WORKDIR /app

COPY package.json yarn.lock* ./
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi
# Dependancy install을 위해 package.json, package-lock.json, yarn.lock 복사
COPY package.json yarn.lock ./

# Dependancy 설치 (새로운 lock 파일 수정 또는 생성 방지)
RUN yarn --frozen-lockfile

FROM base AS builder
###########################################################

# 2단계: next.js 빌드 단계
FROM node:18-alpine AS builder

# 명령어를 실행할 디렉터리 지정
WORKDIR /app

# node_modules 등의 dependancy를 복사함.
COPY --from=deps /app/node_modules ./node_modules
COPY . .

RUN \
if [ -f yarn.lock ]; then yarn run build; \
else echo "Lockfile not found." && exit 1; \
fi
RUN yarn build

FROM base AS runner
WORKDIR /app
###########################################################

ENV NODE_ENV production
# 3단계: next.js 실행 단계
FROM node:18-alpine AS runner

# 명령어를 실행할 디렉터리 지정
WORKDIR /app

# container 환경에 시스템 사용자를 추가함
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

# next.config.js에서 output을 standalone으로 설정하면
# 빌드에 필요한 최소한의 파일만 ./next/standalone로 출력이 된다.
# standalone 결과물에는 public 폴더와 static 폴더 내용은 포함되지 않으므로, 따로 복사를 해준다.
COPY --from=builder /app/public ./public

RUN mkdir .next
RUN chown nextjs:nodejs .next

COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

# 컨테이너의 수신 대기 포트를 3000으로 설정
EXPOSE 3000

ENV PORT 3000

ENV HOSTNAME "0.0.0.0"
# node로 애플리케이션 실행
CMD ["node", "server.js"]

CMD ["node", "server.js"]
# standalone으로 나온 결과값은 node 자체적으로만 실행 가능
# CMD ["npm", "start"]
Loading