fix: mediasoup을 actions에서 빌드하고 캐싱하도록 변경 #52
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
name: 백엔드 @app/media CD | |
on: | |
push: | |
branches: [main, release, fix/#347/media-build] | |
jobs: | |
ci: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: [18.x] | |
steps: | |
- name: ✅ 체크아웃 | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 2 | |
- name: ☑️ pnpm 버전 설정 | |
uses: pnpm/action-setup@v3 | |
with: | |
version: 9 | |
- name: ☑️ 노드 버전 설정 | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node-version }} | |
cache: 'pnpm' | |
- name: 🔄 pnpm 캐시 복원 | |
uses: actions/cache@v3 | |
with: | |
path: ~/.pnpm-store | |
key: ${{ runner.os }}-pnpm-${{ hashFiles('pnpm-lock.yaml') }} | |
restore-keys: | | |
${{ runner.os }}-pnpm- | |
- name: 🔄 mediasoup 빌드 결과 캐시 복원 | |
uses: actions/cache@v3 | |
with: | |
path: /app/apps/media/node_modules/.pnpm/mediasoup@*/node_modules/mediasoup | |
key: ${{ runner.os }}-mediasoup-${{ hashFiles('pnpm-lock.yaml') }} | |
restore-keys: | | |
${{ runner.os }}-mediasoup- | |
- name: ⬇️ 의존성 설치 | |
run: | | |
pnpm install --frozen-lockfile | |
- name: 📦 프로젝트 빌드 | |
run: pnpm build:media | |
- name: 🔄 mediasoup 빌드 결과 캐시 저장 | |
uses: actions/cache@v3 | |
with: | |
path: /app/apps/media/node_modules/.pnpm/mediasoup@*/node_modules/mediasoup | |
key: ${{ runner.os }}-mediasoup-${{ hashFiles('pnpm-lock.yaml') }} | |
build: | |
runs-on: ubuntu-latest | |
needs: ci | |
steps: | |
- name: ✅ 체크아웃 | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 2 | |
- name: .env 파일 생성 | |
run: | | |
jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS_CONTEXT" > .env | |
mv .env apps/media/.env | |
env: | |
SECRETS_CONTEXT: ${{ toJson(secrets) }} | |
- name: 🐳 Docker 빌드 및 푸시 | |
run: | | |
echo "Starting Docker build..." | |
DOCKER_BUILDKIT=1 docker buildx build --progress=plain \ | |
--build-arg PNPM_CACHE_DIR=/root/.pnpm-store \ | |
--build-arg MEDIASOUP_CACHE_DIR=/app/apps/media/node_modules/.pnpm/mediasoup@*/node_modules/mediasoup \ | |
-f apps/media/Dockerfile . -t my-media-app | |
echo "Docker build completed." | |
- name: 🐳 Docker 실행 | |
run: | | |
echo "Starting Docker container..." | |
docker run -d -p 3002:3002 --name media-app my-media-app | |
echo "Docker container started." | |
- name: 🐳 Docker 상태 확인 | |
run: | | |
sleep 10 # 컨테이너가 시작될 시간을 주기 위한 대기 시간 | |
docker ps -a | |
docker logs media-app # 로그 확인 |