Repository navigation
80 lines (69 loc) · 2.64 KB
/
Copy pathfront.yml
File metadata and controls
80 lines (69 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
name: Build Nextjs
on:
workflow_call:
secrets:
ECR_REPO_DEV_FRONT:
OIDC_ROLE:
AWS_REGION:
WEBHOOK:
AWS_DEPLOY_APP_NAME:
AWS_DEPLOY_GROUP:
AWS_DEPLOY_CONFIG:
permissions:
id-token: write
contents: read
jobs:
build:
name: To push ECR
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Docker build
run: docker build -t catcher-web .
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ secrets.AWS_REGION }}
role-session-name: GitHubActions
role-to-assume: ${{ secrets.OIDC_ROLE }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Remove Old Image from ECR(CATCHER-WEB)
run: |
# ECR Front 레포의 기존 이미지 조회
aws ecr describe-images \
--repository-name ${{ secrets.ECR_REPO_DEV_FRONT }} \
--region ${{ secrets.AWS_REGION }} \
--output yaml | grep imageDigest | awk -F ' ' '{print $2}' > ./delete_list.txt
# ECR Front 레포의 기존 이미지 모두 삭제
for front_image in `cat ./delete_list.txt`
do
aws ecr batch-delete-image \
--repository-name ${{ secrets.ECR_REPO_DEV_FRONT }} \
--image-ids imageDigest=$front_image \
--output yaml > /dev/null
done
- name: Publish Image to ECR(CATCHER-WEB)
run: |
docker tag catcher-web:latest ${{ secrets.ECR_REPO_DEV_FRONT }}:${{ github.sha }}
docker push ${{ secrets.ECR_REPO_DEV_FRONT }}:${{ github.sha }}
- name: Deploy to Frontend Instance from ECR Image
run: |
aws deploy create-deployment \
--application-name ${{ secrets.AWS_DEPLOY_APP_NAME }} \
--deployment-group-name ${{ secrets.AWS_DEPLOY_GROUP }} \
--deployment-config-name ${{ secrets.AWS_DEPLOY_CONFIG }} \
--github-location repository=${{ github.repository }},commitId=${{ github.sha }}
- name: Send Notification
if: ${{ always() }}
run: |
if [[ ${{ job.status }} == "success" ]]; then
MESSAGE="✅ ${{ job.status }} 프론트 배포 성공 : catcher-web - by ${{ github.actor }}"
else
MESSAGE="❌ ${{ job.status }} 프론트 배포 실패 : catcher-web - by ${{ github.actor }}"
fi
curl -X POST -H "Content-Type: application/json" --data "{\"text\":\"${MESSAGE}\"}" ${{ secrets.WEBHOOK }}