-
Notifications
You must be signed in to change notification settings - Fork 0
feat: GitHub Actions CI/CD #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,63 @@ | ||||||||||||||||||||||||
| name: Deploy Auth to ECS | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| on: | ||||||||||||||||||||||||
| push: | ||||||||||||||||||||||||
| branches: | ||||||||||||||||||||||||
| - main | ||||||||||||||||||||||||
| workflow_dispatch: | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| env: | ||||||||||||||||||||||||
| AWS_REGION: ap-northeast-2 | ||||||||||||||||||||||||
| AWS_ACCOUNT_ID: 727452759104 | ||||||||||||||||||||||||
| ECR_REPOSITORY: momentlit/auth | ||||||||||||||||||||||||
| ECS_CLUSTER: default | ||||||||||||||||||||||||
| ECS_SERVICE: momentlit-auth-service | ||||||||||||||||||||||||
| IMAGE_TAG: latest | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| jobs: | ||||||||||||||||||||||||
| deploy: | ||||||||||||||||||||||||
| name: Build and Deploy Auth | ||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
Comment on lines
+17
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 최소 권한 원칙을 적용하여 명시적인 permissions를 설정하세요. 워크플로우에 명시적인 🔒 제안하는 수정 방안 jobs:
deploy:
name: Build and Deploy Auth
runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ id-token: write # OIDC를 사용하는 경우📝 Committable suggestion
Suggested change
🤖 Prompt for AI AgentsSource: Linters/SAST tools |
||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||
| - name: Checkout source code | ||||||||||||||||||||||||
| uses: actions/checkout@v4 | ||||||||||||||||||||||||
|
Comment on lines
+23
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 자격증명 유지를 비활성화하세요.
🔒 제안하는 수정 방안 - name: Checkout source code
uses: actions/checkout@v4
+ with:
+ persist-credentials: false📝 Committable suggestion
Suggested change
🧰 Tools🪛 zizmor (1.25.2)[warning] 23-24: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false (artipacked) [error] 24-24: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy) (unpinned-uses) 🤖 Prompt for AI AgentsSource: Linters/SAST tools There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Description: 각 액션의 태그에 해당하는 커밋 해시 조회
echo "=== actions/checkout@v4 ==="
gh api repos/actions/checkout/git/ref/tags/v4 --jq '.object.sha'
echo "=== aws-actions/configure-aws-credentials@v5 ==="
gh api repos/aws-actions/configure-aws-credentials/git/ref/tags/v5 --jq '.object.sha'
echo "=== aws-actions/amazon-ecr-login@v2 ==="
gh api repos/aws-actions/amazon-ecr-login/git/ref/tags/v2 --jq '.object.sha'
echo "=== docker/setup-buildx-action@v3 ==="
gh api repos/docker/setup-buildx-action/git/ref/tags/v3 --jq '.object.sha'Repository: MomentLit/Auth Length of output: 377 🏁 Script executed: cat .github/workflows/deploy.ymlRepository: MomentLit/Auth Length of output: 1697 모든 GitHub Actions를 커밋 해시로 고정하세요. 워크플로우의 모든 액션이 버전 태그로만 참조되어 있어 공급망 공격에 취약합니다. 태그는 이동 가능하지만 커밋 해시는 불변이므로, 보안 모범 사례에 따라 각 액션을 특정 커밋 해시로 고정해야 합니다. 다음 액션들을 수정하세요:
🧰 Tools🪛 zizmor (1.25.2)[warning] 23-24: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false (artipacked) [error] 24-24: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy) (unpinned-uses) 📍 Affects 1 file
🤖 Prompt for AI AgentsSource: Linters/SAST tools |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| - name: Configure AWS credentials | ||||||||||||||||||||||||
| uses: aws-actions/configure-aws-credentials@v5 | ||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||
| aws-region: ${{ env.AWS_REGION }} | ||||||||||||||||||||||||
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||||||||||||||||||||||||
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| - name: Login to Amazon ECR | ||||||||||||||||||||||||
| uses: aws-actions/amazon-ecr-login@v2 | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| - name: Set up Docker Buildx | ||||||||||||||||||||||||
| uses: docker/setup-buildx-action@v3 | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| - name: Build and push Docker image | ||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||
| IMAGE_URI=${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${ECR_REPOSITORY}:${IMAGE_TAG} | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| docker buildx build \ | ||||||||||||||||||||||||
| --platform linux/amd64 \ | ||||||||||||||||||||||||
| --provenance=false \ | ||||||||||||||||||||||||
| -t $IMAGE_URI \ | ||||||||||||||||||||||||
| . \ | ||||||||||||||||||||||||
| --push | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| - name: Force new ECS deployment | ||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||
| aws ecs update-service \ | ||||||||||||||||||||||||
| --cluster $ECS_CLUSTER \ | ||||||||||||||||||||||||
| --service $ECS_SERVICE \ | ||||||||||||||||||||||||
| --force-new-deployment \ | ||||||||||||||||||||||||
| --region $AWS_REGION | ||||||||||||||||||||||||
|
Comment on lines
+50
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Task definition을 업데이트하는 방식으로 개선하세요. 현재 특히 이미지 태그를 동적으로 변경하는 경우 (예: Git SHA 사용) task definition 업데이트가 필수입니다. 🔧 제안하는 수정 방안
+ - name: Download task definition
+ run: |
+ aws ecs describe-task-definition \
+ --task-definition momentlit-auth-task \
+ --region ${{ env.AWS_REGION }} \
+ --query 'taskDefinition' > task-definition.json
+
+ - name: Fill in the new image ID in the Amazon ECS task definition
+ id: task-def
+ uses: aws-actions/amazon-ecs-render-task-definition@v1
+ with:
+ task-definition: task-definition.json
+ container-name: auth
+ image: ${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
+
+ - name: Deploy Amazon ECS task definition
+ uses: aws-actions/amazon-ecs-deploy-task-definition@v1
+ with:
+ task-definition: ${{ steps.task-def.outputs.task-definition }}
+ service: ${{ env.ECS_SERVICE }}
+ cluster: ${{ env.ECS_CLUSTER }}
+ wait-for-service-stability: true
-
- - name: Force new ECS deployment
- run: |
- aws ecs update-service \
- --cluster $ECS_CLUSTER \
- --service $ECS_SERVICE \
- --force-new-deployment \
- --region $AWS_REGION
-
- - name: Wait for ECS service stable
- run: |
- aws ecs wait services-stable \
- --cluster $ECS_CLUSTER \
- --services $ECS_SERVICE \
- --region $AWS_REGION참고: task definition 이름과 컨테이너 이름을 실제 값으로 조정해야 합니다. 🤖 Prompt for AI Agents |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| - name: Wait for ECS service stable | ||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||
| aws ecs wait services-stable \ | ||||||||||||||||||||||||
| --cluster $ECS_CLUSTER \ | ||||||||||||||||||||||||
| --services $ECS_SERVICE \ | ||||||||||||||||||||||||
| --region $AWS_REGION | ||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win
이미지 태그에 동적 값 사용을 권장합니다.
이미지 태그가
latest로 고정되어 있어 다음 문제가 발생합니다:Git 커밋 SHA 또는 타임스탬프를 사용하여 각 배포를 고유하게 식별할 수 있도록 개선하는 것이 좋습니다.
♻️ 제안하는 수정 방안
또는 날짜와 SHA를 조합:
📝 Committable suggestion
🤖 Prompt for AI Agents