-
Notifications
You must be signed in to change notification settings - Fork 4
61 lines (55 loc) · 2.3 KB
/
wc-cd-01-deploy.yaml
File metadata and controls
61 lines (55 loc) · 2.3 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
on:
workflow_call:
inputs:
app:
type: string
jobs:
deploy-ec2:
name: "🚀deploy"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4.2.2
with:
ref: ${{ github.ref }}
fetch-depth: 0
- name: Download image tag artifact
uses: actions/download-artifact@v4
with:
name: ${{ inputs.app }}-image-tag
- name: Load Docker image tag
id: get-docker-image-tag
run: echo "image-tag=$(cat ${{ inputs.app }}-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:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.ECR_REPO_NAME }}
IMAGE_TAG: ${{ steps.get-docker-image-tag.outputs.image-tag }}
with:
host: ${{ inputs.app == 'api' && secrets.EC2_PAYMENT_HOST || secrets.EC2_BACKOFFICE_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
script_stop: true
script: |
CONTAINER_NAME=${{ inputs.app == 'api' && 'payment_application' || 'backoffice_application' }}
if [ "$(docker ps -a -q -f name=$CONTAINER_NAME)" ]; then
docker stop $CONTAINER_NAME
docker rm $CONTAINER_NAME
fi
aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${{ env.ECR_REGISTRY }}
docker pull ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}/${{ inputs.app }}:${{ env.IMAGE_TAG }}
docker run -d -p 8080:8080 \
-e JAVA_TOOL_OPTIONS="-XX:MaxDirectMemorySize=5M -XX:ReservedCodeCacheSize=140M -Xss512K" \
-e SPRING_PROFILES_ACTIVE=dev \
--name $CONTAINER_NAME \
${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}/${{ inputs.app }}:${{ env.IMAGE_TAG }}