-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
name: Media Server CI/CD | ||
on: | ||
push: | ||
branches: | ||
- develop | ||
- Chore/89 | ||
paths: | ||
- 'apps/media/**' | ||
|
||
jobs: | ||
build-and-push: | ||
runs-on: ubuntu-latest | ||
|
||
env: | ||
IMAGE_NAME: media-camon | ||
MEDIA_PORT: 3001 | ||
# REDIS_HOST: ${{ secrets.REDIS_HOST }} | ||
# REDIS_PORT: ${{ secrets.REDIS_PORT }} | ||
DB_HOST: ${{ secrets.DB_HOST }} | ||
DB_PORT: ${{ secrets.DB_PORT }} | ||
DB_USERNAME: ${{ secrets.DB_USERNAME }} | ||
DB_PASSWORD: ${{ secrets.DB_PASSWORD }} | ||
DB_NAME: ${{ secrets.DB_NAME }} | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Log in to Ncloud Container Registry | ||
env: | ||
USERNAME: ${{ secrets.NCLOUD_ACCESS_KEY }} | ||
PASSWORD: ${{ secrets.NCLOUD_SECRET_KEY }} | ||
REGISTRY_URL: ${{ secrets.NCLOUD_REGISTRY_URL }} | ||
run: | | ||
echo "$PASSWORD" | docker login -u "$USERNAME" "$REGISTRY_URL" --password-stdin | ||
- name: Build Docker image | ||
run: | | ||
docker build -f ./apps/media/Dockerfile -t ${{ secrets.NCLOUD_REGISTRY_URL }}/$IMAGE_NAME:latest \ | ||
--build-arg MEDIA_PORT=$MEDIA_PORT \ | ||
--build-arg REDIS_HOST=$REDIS_HOST \ | ||
--build-arg REDIS_PORT=$REDIS_PORT \ | ||
--build-arg DB_HOST=$DB_HOST \ | ||
--build-arg DB_PORT=$DB_PORT \ | ||
--build-arg DB_USERNAME=$DB_USERNAME \ | ||
--build-arg DB_PASSWORD=$DB_PASSWORD \ | ||
--build-arg DB_NAME=$DB_NAME \ | ||
. | ||
- name: Push to Ncloud Container Registry | ||
run: | | ||
docker push ${{ secrets.NCLOUD_REGISTRY_URL }}/$IMAGE_NAME:latest | ||
deploy-and-run: | ||
runs-on: ubuntu-latest | ||
needs: build-and-push | ||
steps: | ||
- name: SSH and deploy | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.SERVER_IP }} | ||
username: ${{ secrets.SERVER_USER }} | ||
key: ${{ secrets.SSH_SERVER_KEY }} | ||
port: 22 | ||
script: | | ||
sudo docker login -u ${{secrets.NCLOUD_ACCESS_KEY}} -p ${{ secrets.NCLOUD_SECRET_KEY }} ${{ secrets.NCLOUD_REGISTRY_URL }} | ||
sudo docker stop media-camon || true | ||
sudo docker rm media-camon || true | ||
sudo docker rmi ${{ secrets.NCLOUD_REGISTRY_URL }}/media-camon:latest || true | ||
sudo docker pull ${{ secrets.NCLOUD_REGISTRY_URL }}/media-camon:latest | ||
sudo docker run -d --name media-camon \ | ||
-p 3001:3001 \ | ||
--network=host \ | ||
${{ secrets.NCLOUD_REGISTRY_URL }}/media-camon:latest | ||
sudo docker image prune -f | ||
- name: Check container status | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.SERVER_IP }} | ||
username: ${{ secrets.SERVER_USER }} | ||
key: ${{ secrets.SSH_SERVER_KEY }} | ||
port: 22 | ||
script: | | ||
sudo docker ps -f name=media-camon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Node.js 기본 이미지 사용 | ||
FROM node:22-alpine AS base | ||
|
||
# pnpm 환경 설정 | ||
ENV PNPM_HOME="/pnpm" | ||
ENV PATH="$PNPM_HOME:$PATH" | ||
RUN corepack enable | ||
|
||
# 작업 디렉토리 설정 | ||
WORKDIR /app | ||
|
||
# @nestjs/cli 글로벌 설치 | ||
RUN npm install -g @nestjs/cli | ||
|
||
# 환경 변수 설정 | ||
ARG MEDIA_PORT | ||
# ARG REDIS_HOST | ||
# ARG REDIS_PORT | ||
ARG DB_HOST | ||
ARG DB_PORT | ||
ARG DB_USERNAME | ||
ARG DB_PASSWORD | ||
ARG DB_NAME | ||
|
||
ENV MEDIA_PORT=$MEDIA_PORT | ||
# ENV REDIS_HOST=$REDIS_HOST | ||
# ENV REDIS_PORT=$REDIS_PORT | ||
ENV DB_HOST=$DB_HOST | ||
ENV DB_PORT=$DB_PORT | ||
ENV DB_USERNAME=$DB_USERNAME | ||
ENV DB_PASSWORD=$DB_PASSWORD | ||
ENV DB_NAME=$DB_NAME | ||
|
||
# 모노레포 루트의 의존성 파일 복사 | ||
COPY pnpm-lock.yaml package.json pnpm-workspace.yaml ./ | ||
|
||
# Media 앱의 package.json 파일 복사 | ||
COPY apps/media/package.json apps/media/ | ||
|
||
# 의존성 설치 (devDependencies 포함) | ||
RUN pnpm install --filter=./apps/media --prod=false | ||
|
||
# Media 서버의 코드 복사 | ||
COPY apps/media ./apps/media | ||
|
||
# Media 서버 빌드 | ||
RUN pnpm --filter=./apps/media exec nest build | ||
|
||
# 포트 노출 | ||
EXPOSE $MEDIA_PORT | ||
|
||
# 애플리케이션 실행 | ||
CMD ["node", "apps/media/dist/main"] |