Skip to content

Conversation

@LeeCh0129
Copy link
Contributor

@LeeCh0129 LeeCh0129 commented Jul 27, 2025

📌 변경 사항 개요

GitHub Secrets를 활용하여, Git 저장소에 노출하지 않고 서버에 안전하게 환경변수를 적용함.

📝 상세 내용

deploy.yml : 배포 스크립트에 깃허브 시크릿의 값을 읽어와 서버에 .env 파일을 자동으로 생성하는 로직을 추가했습니다.
docker-compose.yml: .env 파일을 도커 컨테이너가 읽어와 환경 변수를 주입할 수 있도록 변경했습니다.

🔗 관련 이슈

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

💡 참고 사항

  • NEXT_PUBLIC_API_URL, NEXT_PUBLIC_TEAM_ID, NEXT_PUBLIC_KAKAO_APP_JS_KEY, NEXT_PUBLIC_API_SERVER_URL 를 환경 변수로 등록해놨습니다.

Summary by CodeRabbit

  • Chores
    • 배포 스크립트가 최신 코드를 가져오기 전에 GitHub secrets에서 환경 변수들을 동적으로 .env 파일로 생성하도록 개선되었습니다.
    • docker-compose 설정에서 nextjs 서비스가 .env 파일을 사용해 환경 변수를 불러오도록 변경되었습니다.

@LeeCh0129 LeeCh0129 self-assigned this Jul 27, 2025
@LeeCh0129 LeeCh0129 added the 🌏 Deploy 배포 label Jul 27, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jul 27, 2025

"""

Walkthrough

배포 워크플로우가 업데이트되어, 배포 스크립트가 최신 코드를 가져오기 전에 GitHub Secrets에서 환경변수를 읽어 .env 파일을 동적으로 생성하도록 변경되었습니다. 또한, docker-compose.ymlnextjs 서비스에 .env 파일을 참조하는 env_file 옵션이 추가되었습니다.

Changes

파일 Cohort 변경 요약
배포 워크플로우 수정
.github/workflows/deploy.yml
배포 스크립트에서 기존 .env 파일을 삭제 후, GitHub Secrets로부터 환경변수를 읽어 새로운 .env 파일을 생성하는 단계 추가
Docker Compose 환경변수 설정
docker-compose.yml
nextjs 서비스에 .env 파일을 불러오는 env_file 옵션 추가

Sequence Diagram(s)

sequenceDiagram
    participant GitHub Actions
    participant OCI Server
    participant Docker Compose

    GitHub Actions->>OCI Server: SSH 접속 및 프로젝트 디렉토리 이동
    OCI Server->>OCI Server: 기존 .env 파일 삭제
    OCI Server->>OCI Server: GitHub Secrets에서 환경변수로 .env 파일 생성
    OCI Server->>OCI Server: git pull로 최신 코드 가져오기
    OCI Server->>Docker Compose: docker-compose up 실행 (.env 파일 사용)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Assessment against linked issues

Objective Addressed Explanation
깃허브 시크릿 환경변수 등록 및 배포 스크립트 수정 (#79)

Assessment against linked issues: Out-of-scope changes

(해당 없음)

Possibly related PRs

Suggested reviewers

  • minimo-9
  • evaain706
  • BokyungCodes

Poem

토끼가 깡총, 배포를 준비해
비밀 변수 담아 .env를 새로이
깃허브 시크릿, 안전하게 전달
Docker도 신나서 환경을 불러
배포의 들판에 바람이 분다
🐇✨
"""

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 deploy/79

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 8651d64 and 2c11077.

📒 Files selected for processing (2)
  • .github/workflows/deploy.yml (1 hunks)
  • docker-compose.yml (1 hunks)

Comment on lines 107 to 116
# .env 파일 생성
echo "📝 Creating .env file from secrets..."
# 기존 .env 파일이 있다면 삭제하여 최신 상태 유지
rm -f .env
touch .env
echo "NEXT_PUBLIC_API_URL=${{ secrets.NEXT_PUBLIC_API_URL }}" >> .env
echo "NEXT_PUBLIC_TEAM_ID=${{ secrets.NEXT_PUBLIC_TEAM_ID }}" >> .env
echo "NEXT_PUBLIC_KAKAO_APP_JS_KEY=${{ secrets.NEXT_PUBLIC_KAKAO_APP_JS_KEY }}" >> .env
echo "NEXT_PUBLIC_API_SERVER_URL=${{ secrets.NEXT_PUBLIC_API_SERVER_URL }}" >> .env
Copy link

@coderabbitai coderabbitai bot Jul 27, 2025

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

환경 변수 값이 로그에 노출될 위험이 있습니다

echo 명령으로 .env 파일을 작성하면 각 변수 값이 STDOUT 으로 출력되어 GitHub Actions 로그 및 원격 SSH 세션 로그에 그대로 남을 수 있습니다. Secrets 마스킹이 실패하거나 로그가 외부에 노출될 경우, 민감-정보가 유출될 가능성이 있습니다.
cat <<EOF > .env 패턴을 사용하면 값이 출력되지 않아 위험을 줄일 수 있습니다.

-            rm -f .env
-            touch .env
-            echo "NEXT_PUBLIC_API_URL=${{ secrets.NEXT_PUBLIC_API_URL }}" >> .env
-            echo "NEXT_PUBLIC_TEAM_ID=${{ secrets.NEXT_PUBLIC_TEAM_ID }}" >> .env
-            echo "NEXT_PUBLIC_KAKAO_APP_JS_KEY=${{ secrets.NEXT_PUBLIC_KAKAO_APP_JS_KEY }}" >> .env
-            echo "NEXT_PUBLIC_API_SERVER_URL=${{ secrets.NEXT_PUBLIC_API_SERVER_URL }}" >> .env
+            rm -f .env
+            # 값이 로그에 찍히지 않도록 cat-heredoc 사용
+            cat > .env <<EOF
+NEXT_PUBLIC_API_URL=${{ secrets.NEXT_PUBLIC_API_URL }}
+NEXT_PUBLIC_TEAM_ID=${{ secrets.NEXT_PUBLIC_TEAM_ID }}
+NEXT_PUBLIC_KAKAO_APP_JS_KEY=${{ secrets.NEXT_PUBLIC_KAKAO_APP_JS_KEY }}
+NEXT_PUBLIC_API_SERVER_URL=${{ secrets.NEXT_PUBLIC_API_SERVER_URL }}
+EOF
📝 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
# .env 파일 생성
echo "📝 Creating .env file from secrets..."
# 기존 .env 파일이 있다면 삭제하여 최신 상태 유지
rm -f .env
touch .env
echo "NEXT_PUBLIC_API_URL=${{ secrets.NEXT_PUBLIC_API_URL }}" >> .env
echo "NEXT_PUBLIC_TEAM_ID=${{ secrets.NEXT_PUBLIC_TEAM_ID }}" >> .env
echo "NEXT_PUBLIC_KAKAO_APP_JS_KEY=${{ secrets.NEXT_PUBLIC_KAKAO_APP_JS_KEY }}" >> .env
echo "NEXT_PUBLIC_API_SERVER_URL=${{ secrets.NEXT_PUBLIC_API_SERVER_URL }}" >> .env
# .env 파일 생성
echo "📝 Creating .env file from secrets..."
# 기존 .env 파일이 있다면 삭제하여 최신 상태 유지
rm -f .env
# 값이 로그에 찍히지 않도록 cat-heredoc 사용
cat > .env <<EOF
NEXT_PUBLIC_API_URL=${{ secrets.NEXT_PUBLIC_API_URL }}
NEXT_PUBLIC_TEAM_ID=${{ secrets.NEXT_PUBLIC_TEAM_ID }}
NEXT_PUBLIC_KAKAO_APP_JS_KEY=${{ secrets.NEXT_PUBLIC_KAKAO_APP_JS_KEY }}
NEXT_PUBLIC_API_SERVER_URL=${{ secrets.NEXT_PUBLIC_API_SERVER_URL }}
EOF
🤖 Prompt for AI Agents
In .github/workflows/deploy.yml around lines 107 to 116, the current use of echo
commands to write environment variables to the .env file risks exposing secret
values in the GitHub Actions logs. To fix this, replace the multiple echo
commands with a single here-document (cat <<EOF > .env) block that writes all
variables at once without printing their values to STDOUT, thereby preventing
secret leakage in logs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

로그에 노출되는 부분의 문제에 관해서 궁금한게 하나 있는데 GitHub Actions에서 이 문제를 해결하기 위해서 자동으로 Secrets를 마스킹이였나? 하는 기능이 내장되어 있는거 아닌가? 찾아보니 워크플로우 로그에 Secrets 값이 출력 되려고 하면 깃허브에서 이 값을 다른값이였었나 별표였었나 아무튼 다른값으로 대체해주는 걸로 알고 있는데 잘못 알고있는건가 궁금해서 말이야.

Copy link

Choose a reason for hiding this comment

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

@LeeCh0129 맞습니다! GitHub Actions에는 자동 시크릿 마스킹 기능이 내장되어 있어서, 워크플로우 로그에 등록된 secrets 값이 출력되려고 하면 ***로 자동 대체됩니다.

하지만 몇 가지 마스킹이 실패할 수 있는 경우들이 있어서 제가 heredoc 방식을 제안했습니다:

마스킹이 동작하는 경우

- name: Test
  run: echo "${{ secrets.MY_SECRET }}"  # *** 로 마스킹됨

마스킹이 실패할 수 있는 경우들

  1. SSH 원격 실행에서의 한계
ssh user@host << 'ENDSSH'
  echo "API_URL=${{ secrets.API_URL }}"  # SSH 세션 내부에서는 마스킹이 불완전할 수 있음
ENDSSH
  1. 문자열 변형/인코딩
echo "${{ secrets.API_URL }}" | base64  # 인코딩된 값은 마스킹되지 않음
  1. 부분 문자열 노출
echo "Config: prefix-${{ secrets.API_URL }}-suffix"  # 변형된 형태는 감지 못할 수 있음

현재 코드에서는 SSH 세션 내부에서 echo를 실행하고 있어서, GitHub의 마스킹이 완벽하게 동작하지 않을 가능성이 있습니다. cat heredoc 방식은 방어적 코딩(defense in depth) 관점에서 더 안전한 접근법입니다.

그래도 일반적인 경우에는 GitHub의 자동 마스킹이 잘 동작하니, 현재 코드를 그대로 유지하셔도 큰 문제는 없을 것 같습니다!

Comment on lines +15 to +17
env_file:
- .env

Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

.env 경로 및 버전관리 제외 여부 확인 필요

env_file: - .env 추가는 배포 스크립트와 잘 연동되지만,

  1. .env 파일이 저장소에 커밋되지 않았는지(.gitignore) 한 번 더 확인해 주세요.
  2. 컨테이너 실행 디렉터리와 .env 위치가 다를 경우 경로가 틀릴 수 있으니 로컬·서버 모두에서 정상 로드되는지 테스트가 필요합니다.

별도 변경은 없어도 되지만 배포 전 두 항목을 검증해 주세요.


아래 스크립트를 실행해 .gitignore.env가 무시 대상으로 등록되어 있는지, 저장소 루트에 .env 파일이 실제로 커밋되지 않았는지 확인해 주세요.

위 결과를 바탕으로 .env 파일이 버전관리에서 제외되어 있는지, 그리고 로컬·서버 환경에서 docker-compose가 .env를 정상 로드하는지 확인해 주세요.


🏁 Script executed:

#!/bin/bash
# 1) .gitignore에 .env가 등록되어 있는지 확인
echo "🔍 .gitignore에서 '.env' 무시 설정 확인"
rg -n '^\s*\.env(\s*#.*)?$' .gitignore || echo "⚠️ .gitignore에 '.env'가 없습니다."

# 2) 저장소 루트에 .env 파일이 커밋된 상태인지 확인
echo "🔍 저장소 루트에 '.env' 파일 존재 여부 확인"
if ls -A | grep -q '^\.env$'; then
  echo "⚠️ 저장소에 '.env' 파일이 존재합니다. 커밋되지 않도록 .gitignore에 추가해주세요."
else
  echo "✅ '.env' 파일이 커밋되지 않았습니다."
fi

Length of output: 360


.env 무시 설정 추가 및 로드 테스트 필요

  • .gitignore에 .env 항목이 누락되어 있으므로, 저장소에 커밋되지 않도록 아래 라인을 추가해주세요.
    .env
  • 현재 .env 파일은 커밋되지 않은 상태임을 확인했습니다.
  • 로컬·서버 환경에서 docker-compose up 실행 시 .env 파일이 정상적으로 로드되는지 반드시 테스트해주세요.
🤖 Prompt for AI Agents
In docker-compose.yml around lines 15 to 17, the .env file is referenced but not
ignored in version control. Add a line with ".env" to the .gitignore file to
prevent committing this sensitive file. After updating .gitignore, run
"docker-compose up" locally and on the server to verify that the .env file loads
correctly without being tracked by git.

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: 3

♻️ Duplicate comments (1)
.github/workflows/deploy.yml (1)

108-118: echo 사용으로 Secrets 값이 그대로 로그에 노출됩니다
지난 리뷰에서도 동일한 지적이 있었으나 여전히 echo "KEY=${{ secrets.KEY }}" 패턴을 쓰고 있습니다.
cat <<EOF > .env heredoc 방식으로 한 번에 기록하면 STDOUT 출력이 없어 마스킹 실패·로그 유출 위험을 줄일 수 있습니다.
변경 예:

-rm -f .env
-touch .env
-echo "NEXT_PUBLIC_API_URL=${{ secrets.NEXT_PUBLIC_API_URL }}" >> .env
-echo "NEXT_PUBLIC_TEAM_ID=${{ secrets.NEXT_PUBLIC_TEAM_ID }}" >> .env
-...
-cat <<EOF > .env
+rm -f .env
+cat > .env <<'EOF'
+NEXT_PUBLIC_API_URL=${{ secrets.NEXT_PUBLIC_API_URL }}
+NEXT_PUBLIC_TEAM_ID=${{ secrets.NEXT_PUBLIC_TEAM_ID }}
+NEXT_PUBLIC_API_SERVER_URL=${{ secrets.NEXT_PUBLIC_API_SERVER_URL }}
+NEXT_PUBLIC_KAKAO_CLIENT_ID=${{ secrets.NEXT_PUBLIC_KAKAO_CLIENT_ID }}
+NEXT_PUBLIC_KAKAO_APP_JS_KEY=${{ secrets.NEXT_PUBLIC_KAKAO_APP_JS_KEY }}
+NEXT_PUBLIC_SITE_URL=${{ secrets.NEXT_PUBLIC_SITE_URL }}
 EOF
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a7b5cd5 and 7ee2732.

📒 Files selected for processing (1)
  • .github/workflows/deploy.yml (1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.37.1)
.github/workflows/deploy.yml

[error] 119-119: trailing spaces

(trailing-spaces)


[error] 123-123: trailing spaces

(trailing-spaces)

Comment on lines +111 to +112
rm -f .env
touch .env
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

.env 파일 권한을 제한하여 서버 내 노출을 방지하세요
파일을 만들기만 하고 권한을 조정하지 않아 기본 umask 값에 따라 다른 사용자도 읽을 수 있습니다.

 touch .env
+chmod 600 .env  # 소유자만 읽기/쓰기
📝 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
rm -f .env
touch .env
rm -f .env
touch .env
chmod 600 .env # 소유자만 읽기/쓰기
🤖 Prompt for AI Agents
In .github/workflows/deploy.yml at lines 111 to 112, after creating the .env
file with 'touch .env', set restrictive file permissions to prevent other users
on the server from reading it. Add a command like 'chmod 600 .env' immediately
after 'touch .env' to limit access to the file owner only.

Comment on lines 119 to 123
# 최신 코드 가져오기
echo "🔄 Pulling latest code..."
git pull origin develop
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

불필요한 공백(trailing spaces) 삭제 권장
YAML lint 경고가 발생하므로 줄 끝 공백을 제거해 워크플로 파일 품질을 유지하세요.

🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 119-119: trailing spaces

(trailing-spaces)


[error] 123-123: trailing spaces

(trailing-spaces)

🤖 Prompt for AI Agents
In .github/workflows/deploy.yml around lines 119 to 123, there are trailing
spaces at the end of some lines causing YAML lint warnings. Remove all trailing
spaces from these lines to ensure the workflow file is clean and free of
formatting issues.

# GHCR 로그인 (PAT 사용)
echo "🔐 Logging in to GHCR..."
echo "🔐 Logging in to GHCR..."
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

로그 메시지에 불필요한 ‘ㅇ’ 문자가 포함되어 있습니다
🔐ㅇ Logging in to GHCR...🔐 Logging in to GHCR... 로 수정해 가독성을 높이세요.

🤖 Prompt for AI Agents
In .github/workflows/deploy.yml at line 125, remove the unnecessary 'ㅇ'
character from the log message so that it reads "🔐 Logging in to GHCR..."
instead of "🔐ㅇ Logging in to GHCR...". This will improve the readability of the
log output.

@LeeCh0129 LeeCh0129 merged commit f89d52a into develop Jul 28, 2025
2 checks passed
@LeeCh0129 LeeCh0129 deleted the deploy/79 branch July 28, 2025 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[deploy] 프로젝트 환경변수 등록(GitHub Secrets)

4 participants