1+ name : ' [TossSecurities] CI For JP'
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ image_tag :
7+ description : ' Harbor image tag to push to JP ECR'
8+ required : true
9+ type : string
10+ phase :
11+ description : ' Target environment'
12+ required : true
13+ type : choice
14+ options :
15+ - alpha
16+ - live
17+
18+ jobs :
19+ push-to-jp-alpha :
20+ if : ${{ inputs.phase == 'alpha' }}
21+ runs-on : ts-dp-alpha-apne2-arm64
22+ steps :
23+ - name : Login to Harbor
24+ run : |
25+ docker login -u ${{ secrets.HARBOR_LIVE_ID }} -p ${{ secrets.HARBOR_LIVE_PW }} harbor.live.tossinvest.bz
26+
27+ - name : Pull image from Harbor
28+ run : |
29+ docker pull harbor.live.tossinvest.bz/dp/amoro:${{ inputs.image_tag }}
30+
31+ - name : install-aws-cli
32+ uses : tossinvest-actions/install-aws-cli-action@v2
33+ with :
34+ version : 2
35+
36+ - name : Configure AWS credentials
37+ uses : tossinvest-actions/configure-aws-credentials@main
38+ with :
39+ aws-access-key-id : ${{ secrets.AWS_ACCESS_KEY_ID_JP_ALPHA }}
40+ aws-secret-access-key : ${{ secrets.AWS_SECRET_ACCESS_KEY_JP_ALPHA }}
41+ aws-region : ap-northeast-1
42+
43+ - name : Login to Amazon ECR
44+ id : login-ecr
45+ uses : tossinvest-actions/amazon-ecr-login@v1
46+ with :
47+ registry-ids : 887721946944
48+
49+ - name : Create ECR repository and set lifecycle policy
50+ env :
51+ ECR_REPOSITORY : dp/amoro
52+ run : |
53+ aws ecr describe-repositories --repository-names $ECR_REPOSITORY \
54+ || aws ecr create-repository --repository-name $ECR_REPOSITORY
55+ aws ecr put-lifecycle-policy --repository-name $ECR_REPOSITORY --lifecycle-policy-text '{
56+ "rules": [{
57+ "rulePriority": 1,
58+ "description": "Keep only the latest 10 images",
59+ "selection": {
60+ "tagStatus": "any",
61+ "countType": "imageCountMoreThan",
62+ "countNumber": 10
63+ },
64+ "action": {
65+ "type": "expire"
66+ }
67+ }]
68+ }'
69+
70+ - name : Tag and push image to JP Alpha ECR
71+ env :
72+ ECR_REGISTRY : ${{ steps.login-ecr.outputs.registry }}
73+ ECR_REPOSITORY : dp/amoro
74+ IMAGE_TAG : ${{ inputs.image_tag }}
75+ run : |
76+ docker tag harbor.live.tossinvest.bz/dp/amoro:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
77+ docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
78+
79+ push-to-jp-live :
80+ if : ${{ inputs.phase == 'live' }}
81+ runs-on : dc2-amd64
82+ steps :
83+ - name : Login to Harbor
84+ run : |
85+ docker login -u ${{ secrets.HARBOR_LIVE_ID }} -p ${{ secrets.HARBOR_LIVE_PW }} harbor.live.tossinvest.bz
86+
87+ - name : Pull image from Harbor
88+ run : |
89+ docker pull harbor.live.tossinvest.bz/dp/amoro:${{ inputs.image_tag }}
90+
91+ - name : install-aws-cli
92+ uses : tossinvest-actions/install-aws-cli-action@v2
93+ with :
94+ version : 2
95+
96+ - name : Configure AWS credentials
97+ uses : tossinvest-actions/configure-aws-credentials@main
98+ with :
99+ aws-access-key-id : ${{ secrets.AWS_ACCESS_KEY_ID_JP_LIVE }}
100+ aws-secret-access-key : ${{ secrets.AWS_SECRET_ACCESS_KEY_JP_LIVE }}
101+ aws-region : ap-northeast-1
102+
103+ - name : Login to Amazon ECR
104+ id : login-ecr
105+ uses : tossinvest-actions/amazon-ecr-login@v1
106+ with :
107+ registry-ids : 965031587152
108+
109+ - name : Create ECR repository and set lifecycle policy
110+ env :
111+ ECR_REPOSITORY : dp/amoro
112+ run : |
113+ aws ecr describe-repositories --repository-names $ECR_REPOSITORY \
114+ || aws ecr create-repository --repository-name $ECR_REPOSITORY
115+ aws ecr put-lifecycle-policy --repository-name $ECR_REPOSITORY --lifecycle-policy-text '{
116+ "rules": [{
117+ "rulePriority": 1,
118+ "description": "Keep only the latest 10 images",
119+ "selection": {
120+ "tagStatus": "any",
121+ "countType": "imageCountMoreThan",
122+ "countNumber": 10
123+ },
124+ "action": {
125+ "type": "expire"
126+ }
127+ }]
128+ }'
129+
130+ - name : Tag and push image to JP Live ECR
131+ env :
132+ ECR_REGISTRY : ${{ steps.login-ecr.outputs.registry }}
133+ ECR_REPOSITORY : dp/amoro
134+ IMAGE_TAG : ${{ inputs.image_tag }}
135+ run : |
136+ docker tag harbor.live.tossinvest.bz/dp/amoro:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
137+ docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
0 commit comments