Skip to content

Commit

Permalink
fix: actions에 C++을 위한 gyp를 캐싱하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Fixtar committed Jan 5, 2025
1 parent bc3dc05 commit c315058
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 16 deletions.
28 changes: 20 additions & 8 deletions .github/workflows/back-media-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ jobs:
- name: 🔄 캐시 복원
uses: actions/cache@v3
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-pnpm-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-
path: |
~/.pnpm-store
~/.cache/node-gyp
~/.cache/node-gyp-binary
key: ${{ runner.os }}-pnpm-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-
- name: ⬇️ 의존성 설치
run: pnpm install --frozen-lockfile
Expand All @@ -56,9 +59,12 @@ jobs:
with:
fetch-depth: 2

- name: jq 설치
run: sudo apt-get install jq -y

- name: .env 파일 생성
run: |
jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS_CONTEXT" > .env
echo "$SECRETS_CONTEXT" | jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' > .env
mv .env apps/media/.env
env:
SECRETS_CONTEXT: ${{ toJson(secrets) }}
Expand All @@ -70,11 +76,17 @@ jobs:
# username: ${{secrets.DOCKER_REGISTRY_ACCESS_KEY}}
# password: ${{secrets.DOCKER_REGISTRY_SECRET_KEY}}

- name: 🐳 Docker Buildx 설정
uses: docker/setup-buildx-action@v3

- name: 🐳 Docker 빌드 및 푸시
run: |
echo "Starting Docker build..."
DOCKER_BUILDKIT=1 docker buildx build --progress=plain --build-arg PNPM_CACHE_DIR=/root/.pnpm-store -f apps/media/Dockerfile . -t my-media-app
docker buildx build \
--progress=plain \
--build-arg PNPM_CACHE_DIR=/root/.pnpm-store \
-f apps/media/Dockerfile \
. \
-t my-media-app
echo "Docker build completed."
- name: 🐳 Docker 실행
Expand Down
32 changes: 24 additions & 8 deletions apps/media/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,29 @@ RUN npm install -g pnpm
ENV PNPM_HOME="/root/.local/share/pnpm"
ENV PATH="${PATH}:${PNPM_HOME}"

# 캐시 디렉토리 경로 설정
ENV PNPM_STORE_PATH="/pnpm/store"
ENV NODE_GYP_CACHE="/node-gyp-cache"

# 2. Builder 단계
FROM base AS builder

# Turbo CLI 설치
RUN pnpm install -g turbo@^2.2.3

# PNPM 및 node-gyp 캐시를 Docker 캐시 디렉토리에 연결
ARG PNPM_STORE_PATH=/pnpm/store
ARG NODE_GYP_CACHE=/node-gyp-cache
ENV NODE_GYP_CACHE=${NODE_GYP_CACHE}

# 캐시 디렉토리 생성
RUN mkdir -p ${PNPM_STORE_PATH} ${NODE_GYP_CACHE}

# 의존성 파일만 우선 복사하여 캐시 활용
COPY package.json pnpm-lock.yaml ./

# PNPM 캐시 디렉토리 전달
ARG PNPM_CACHE_DIR=/pnpm/store
RUN pnpm install --frozen-lockfile --store=${PNPM_CACHE_DIR}

# PNPM 및 node-gyp 캐시를 사용하여 의존성 설치
RUN pnpm install --frozen-lockfile --store=${PNPM_STORE_PATH} --cache=${NODE_GYP_CACHE}

# 소스 파일 전체 복사
COPY . .
Expand All @@ -38,14 +48,20 @@ FROM base AS runner
# 작업 디렉토리 설정
WORKDIR /app

# PNPM 및 node-gyp 캐시를 Docker 캐시 디렉토리에 연결
ARG PNPM_STORE_PATH=/pnpm/store
ARG NODE_GYP_CACHE=/node-gyp-cache
ENV NODE_GYP_CACHE=${NODE_GYP_CACHE}

# 캐시 디렉토리 생성
RUN mkdir -p ${PNPM_STORE_PATH} ${NODE_GYP_CACHE}

# Turbo Prune 결과 복사
COPY --from=builder /app/out/json/ .
COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml


# PNPM 캐시 디렉토리 전달
ARG PNPM_CACHE_DIR=/pnpm/store
RUN pnpm install --frozen-lockfile --store=${PNPM_CACHE_DIR}
# PNPM 및 node-gyp 캐시를 사용하여 의존성 설치
RUN pnpm install --frozen-lockfile --store=${PNPM_STORE_PATH} --cache=${NODE_GYP_CACHE}

# 전체 소스 복사 및 빌드
COPY --from=builder /app/out/full/ .
Expand Down

0 comments on commit c315058

Please sign in to comment.