Skip to content

Conversation

@LeeCh0129
Copy link
Contributor

@LeeCh0129 LeeCh0129 commented Aug 1, 2025

📌 변경 사항 개요

Docker 이미지 빌드 시점에 환경 변수가 누락되어 발생하던 APi 경로 오류

📝 상세 내용

  • builder 스테이지에 ARG와 ENV 추가 -> 빌드 시점에 외부에서 환경 변수를 주입받을 수 있도록 변경
  • build job의 docker/build-push-action 단계에 build-args 옵션을 추가 -> 깃허브 시크릿을 빌드 인자로 전달하도록 수정

🔗 관련 이슈

🖼️ 스크린샷(선택사항)

💡 참고 사항

Summary by CodeRabbit

  • Chores
    • Docker 이미지 빌드 시 환경 변수들이 하나의 인자로 전달되어 .env.production 파일에 저장되도록 변경되었습니다. 이로 인해 배포 환경 설정이 더욱 일관되고 간편해졌습니다.

@LeeCh0129 LeeCh0129 self-assigned this Aug 1, 2025
@LeeCh0129 LeeCh0129 added the 🐞 bug 버그관련 label Aug 1, 2025
@coderabbitai
Copy link

coderabbitai bot commented Aug 1, 2025

Walkthrough

Docker 빌드 및 배포 워크플로우에서 환경 변수 주입 방식을 변경했습니다. 여러 환경 변수를 하나의 build-arg(BUILD_ENV_VARS)로 묶어 Docker 이미지 빌드시 전달하고, Dockerfile에서 이를 .env.production 파일로 저장하도록 수정했습니다. 다른 빌드 및 배포 로직에는 변화가 없습니다.

Changes

Cohort / File(s) Change Summary
GitHub Actions 워크플로우 환경변수 처리 개선
.github/workflows/deploy.yml
여러 환경변수를 하나의 BUILD_ENV_VARS build-arg로 통합하여 Docker 빌드시 전달하는 방식으로 변경
Dockerfile 빌드 인자 및 .env 파일 생성
Dockerfile
ARG BUILD_ENV_VARS 선언 및 해당 값을 .env.production 파일로 저장하는 단계 추가

Sequence Diagram(s)

sequenceDiagram
    participant GitHub Actions
    participant Docker Build
    participant Application

    GitHub Actions->>Docker Build: docker build --build-arg BUILD_ENV_VARS="..."
    Docker Build->>Dockerfile: ARG BUILD_ENV_VARS
    Dockerfile->>Dockerfile: BUILD_ENV_VARS를 .env.production에 저장
    Docker Build->>Application: .env.production 파일 포함된 이미지 생성
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Assessment against linked issues

Objective Addressed Explanation
Dockerfile, deploy.yml 내 환경변수 누락 문제 해결 (#109)

Assessment against linked issues: Out-of-scope changes

(해당 사항 없음)

Possibly related PRs

Suggested labels

🌏 Deploy

Suggested reviewers

  • BokyungCodes
  • minimo-9
  • evaain706

Poem

🐇
환경변수 한데 모아
Docker 안에 쏙—
.env.production 파일로
누락 걱정 뚝!
배포길도 순조롭게
토끼도 춤추네!
🎉

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/109

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cd81902 and d8adb99.

📒 Files selected for processing (2)
  • .github/workflows/deploy.yml (1 hunks)
  • Dockerfile (1 hunks)
🧰 Additional context used
🪛 Hadolint (2.12.0)
Dockerfile

[warning] 35-35: Set the SHELL option -o pipefail before RUN with a pipe in it. If you are using /bin/sh in an alpine image or if your shell is symlinked to busybox then consider explicitly setting your SHELL to /bin/ash, or disable this check

(DL4006)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Code Quality Check
🔇 Additional comments (2)
Dockerfile (1)

37-40: .env.production 파일이 러너(stage 3)로 복사되지 않습니다

Next.js 빌드에만 필요하다면 문제없지만, 런타임에서도 동일 파일을 참조한다면 COPY --from=builder .env.production ./ 이 누락돼 컨테이너 실행 시 환경값이 사라집니다. 요구 사항을 다시 확인해 주세요.

.github/workflows/deploy.yml (1)

77-80: BUILD_ENV_VARS 인코딩 확인 필요

여러 시크릿을 공백으로 연결해 하나의 build-arg로 넘기고 있습니다.
GitHub Actions → Docker CLI → Dockerfile 경로를 거치면서 다음 사항을 반드시 검증하세요.

  • 각 시크릿이 비어 있거나 포함되지 않을 때 전체 문자열 구성 실패 여부
  • &, $, \n 등 특수문자 이스케이프 여부
  • 빌드 로그에 시크릿 값이 노출되지 않는지

자동 검증 스크립트를 추가하거나 최소한 개발 브랜치에서 수동 테스트를 권장합니다.

Comment on lines +31 to +36
# 빌드 시점에 주입될 환경 변수 선언
ARG BUILD_ENV_VARS

# 전달받은 ARG 환경 변수를 .env.production 파일에 저장
RUN echo "$BUILD_ENV_VARS" | tr ' ' '\n' > .env.production

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

RUN echo … | tr 명령에 pipefail 옵션을 지정하세요

알파인 busybox sh에서는 파이프 왼쪽 명령이 실패해도 전체 RUN이 성공으로 간주됩니다.
빌드 시점에 .env.production 생성이 실패해도 무시될 수 있으므로 SHELL 지시어로 -o pipefail을 켜 주는 편이 안전합니다.

+# 파이프 오류 전파
+SHELL ["/bin/ash", "-eo", "pipefail", "-c"]

또는 RUN set -o pipefail && echo "$BUILD_ENV_VARS" | tr ' ' '\n' > .env.production 형태로 한 줄에 넣을 수도 있습니다.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# 빌드 시점에 주입될 환경 변수 선언
ARG BUILD_ENV_VARS
# 전달받은 ARG 환경 변수를 .env.production 파일에 저장
RUN echo "$BUILD_ENV_VARS" | tr ' ' '\n' > .env.production
# 빌드 시점에 주입될 환경 변수 선언
ARG BUILD_ENV_VARS
# 파이프 오류 전파
SHELL ["/bin/ash", "-eo", "pipefail", "-c"]
# 전달받은 ARG 환경 변수를 .env.production 파일에 저장
RUN echo "$BUILD_ENV_VARS" | tr ' ' '\n' > .env.production
🧰 Tools
🪛 Hadolint (2.12.0)

[warning] 35-35: Set the SHELL option -o pipefail before RUN with a pipe in it. If you are using /bin/sh in an alpine image or if your shell is symlinked to busybox then consider explicitly setting your SHELL to /bin/ash, or disable this check

(DL4006)

🤖 Prompt for AI Agents
In Dockerfile lines 31 to 36, the RUN command uses a pipe but does not enable
the pipefail option, so failures in the first command may be ignored. Fix this
by adding the shell option -o pipefail either by setting a SHELL directive with
this option before the RUN command or by prefixing the RUN command with 'set -o
pipefail &&' to ensure the entire pipeline failure is detected and causes the
build to fail.

ARG BUILD_ENV_VARS

# 전달받은 ARG 환경 변수를 .env.production 파일에 저장
RUN echo "$BUILD_ENV_VARS" | tr ' ' '\n' > .env.production
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

공백 분리 방식은 특수문자가 포함된 시크릿에서 깨질 수 있습니다

URL 이나 키에 공백·탭·개행이 들어갈 가능성은 낮지만, &, ?, = 등 셸 메타문자가 포함되면 YAML->Docker 전달 과정에서 예기치 않은 파싱이 일어날 수 있습니다.
안전성을 높이려면:

  1. YAML 단계에서 | 멀티라인 블록을 사용해 이미 개행으로 구분하거나
  2. --build-arg 를 변수별로 반복 전달하는 전통적인 방식을 유지

하는 방법을 검토해 주세요.

🧰 Tools
🪛 Hadolint (2.12.0)

[warning] 35-35: Set the SHELL option -o pipefail before RUN with a pipe in it. If you are using /bin/sh in an alpine image or if your shell is symlinked to busybox then consider explicitly setting your SHELL to /bin/ash, or disable this check

(DL4006)

🤖 Prompt for AI Agents
In Dockerfile at line 35, the current method of splitting BUILD_ENV_VARS by
spaces can break if secrets contain special shell characters like &, ?, or =. To
fix this, change the approach to either pass the environment variables as a
multiline string using a YAML block scalar (|) so they are already
newline-separated, or switch to passing each build argument individually with
separate --build-arg flags to avoid parsing issues during Docker build.

@LeeCh0129 LeeCh0129 merged commit 86ccfd7 into develop Aug 1, 2025
2 checks passed
@LeeCh0129 LeeCh0129 deleted the fix/109 branch August 1, 2025 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug 버그관련

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[fix] 빌드 시 환경변수 누락으로 인한 API 경로 오류

2 participants