-
Notifications
You must be signed in to change notification settings - Fork 2
55 lines (48 loc) · 2.05 KB
/
cd.yaml
File metadata and controls
55 lines (48 loc) · 2.05 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
on:
workflow_call:
jobs:
deploy-ec2:
name: "🚀deploy"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4.2.2
- name: Download image tag artifact
uses: actions/download-artifact@v4
with:
name: image-tag
- name: Load Docker image tag
id: get-docker-image-tag
run: echo "image-tag=$(cat image-tag.txt)" >> $GITHUB_OUTPUT
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4.0.2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2.0.1
- name: Deploy to EC2
uses: appleboy/ssh-action@v1.2.0
env:
APP_NAME: "mock_application"
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.MOCK_SERVER_ECR_REPO_NAME }}
IMAGE_TAG: ${{ steps.get-docker-image-tag.outputs.image-tag }}
with:
host: ${{ secrets.MOCK_SERVER_EC2_HOST }}
username: ${{ secrets.MOCK_SERVER_EC2_USER_NAME }}
key: ${{ secrets.MOCK_SERVER_SECRET_KEY }}
script_stop: true
script: |
aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${{ env.ECR_REGISTRY }}
if [ "$(docker ps -a -q -f name=${{ env.APP_NAME }})" ]; then
docker stop ${{ env.APP_NAME }}
docker rm ${{ env.APP_NAME }}
fi
docker pull ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
docker run -d -p 8082:8082 \
-e JAVA_TOOL_OPTIONS="-XX:MaxDirectMemorySize=5M -XX:MaxMetaspaceSize=64M -XX:ReservedCodeCacheSize=140M -Xss512K" \
--name ${{ env.APP_NAME }} \
${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}