C.W.K.
Stream
Lesson 04 of 12 · published

Environment secret

~12 min · environments, secrets, deploy

Level 0Apprentice
0 XP0/101 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

Deploy 타겟에 scope 된 secret

GitHub Actions 의 environment 는 이름 있는 deploy 타겟 (staging, production, preview). 각 environment 가 자기 secret, variable, protection rule, deployment URL 가질 수 있어.

클래식 모양:

  • STAGING_DB_URL, STAGING_API_KEY 가진 staging environment.
  • PROD_DB_URL, PROD_API_KEY + required reviewer 가진 production.
  • 같은 workflow 파일, job 둘 — 각각 한 environment 에 scope.

왜 environment 가 중요

  1. Blast radiusstaging 타겟 workflow run 은 말그대로 production secret 읽을 수 없음. 벽이 진짜.
  2. 승인 — environment 는 'required reviewer' (수동 승인) 과 'wait timer' (대기 기간) 지원. Deploy job 이 만족까지 일시정지.
  3. Branch 정책 — environment 를 특정 branch 로 제한 (prod 는 main 만).
  4. 가시성 — Deployments tab 이 각 environment 에 현재 어느 commit 이 있는지, run 링크와 함께 보여줘.

Code

Scope 된 secret 으로 두 environment deploy·yaml
jobs:
  deploy-staging:
    runs-on: ubuntu-latest
    environment:
      name: staging
      url: https://staging.example.com
    steps:
      - uses: actions/checkout@v4
      - env:
          DB_URL: ${{ secrets.DB_URL }}        # staging value
          API_KEY: ${{ secrets.API_KEY }}      # staging value
        run: ./deploy.sh

  deploy-prod:
    needs: deploy-staging
    runs-on: ubuntu-latest
    environment:
      name: production               # required reviewers configured here
      url: https://www.example.com
    steps:
      - uses: actions/checkout@v4
      - env:
          DB_URL: ${{ secrets.DB_URL }}        # production value
          API_KEY: ${{ secrets.API_KEY }}      # production value
        run: ./deploy.sh

External links

Exercise

Sandbox repo 에 stagingproduction environment 만들어. 각각 다른 값으로 single secret API_KEY 추가. Environment 당 deploy job 한 개씩 두 개 작성. Redact 된 값의 echo 가 다른 길이 보이는지 확인.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.