Skip to content

Commit

Permalink
[Feat] Manager CD test
Browse files Browse the repository at this point in the history
  • Loading branch information
lcj1204 committed Apr 29, 2024
1 parent 695581a commit f601c78
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
EC2_IP: ${{ secrets.EC2_IP }}
EC2_USERNAME: ${{ secrets.EC2_USERNAME }}
EC2_SSH_KEY: ${{ secrets.EC2_SSH_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
ECR_REGISTRY: ${{ secrets.ECR_REGISTRY }}

deploy_worker:
if: github.event.pull_request.merged == true
Expand All @@ -43,4 +45,6 @@ jobs:
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
EC2_IP: ${{ secrets.EC2_IP }}
EC2_USERNAME: ${{ secrets.EC2_USERNAME }}
EC2_SSH_KEY: ${{ secrets.EC2_SSH_KEY }}
EC2_SSH_KEY: ${{ secrets.EC2_SSH_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
ECR_REGISTRY: ${{ secrets.ECR_REGISTRY }}
22 changes: 13 additions & 9 deletions .github/workflows/reusable-CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ on:
required: true
EC2_SSH_KEY:
required: true
AWS_REGION:
required: true
ECR_REGISTRY:
required: true


permissions:
contents: read

env:
AWS_REGION: ap-northeast-2
ECR_REGISTRY: 339712790479.dkr.ecr.ap-northeast-2.amazonaws.com
# AWS_REGION: ap-northeast-2
# ECR_REGISTRY: 339712790479.dkr.ecr.ap-northeast-2.amazonaws.com
ECR_REPOSITORY: pothole-${{ inputs.module }}
MODULE_PACKAGE: pothole-${{ inputs.module }}-api
IMAGE_NAME: pothole-${{ inputs.module }}-api
Expand Down Expand Up @@ -57,7 +61,7 @@ jobs:
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
Expand All @@ -68,9 +72,9 @@ jobs:
cd ./${{ env.MODULE_PACKAGE }}
# Build a Docker container and push it to ECR
docker build -t ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} .
docker build -t ${{ secrets.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} .
echo "Pushing image to ECR..."
docker push ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
docker push ${{ secrets.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
- name: docker-compose.yml 파일 전송
uses: appleboy/scp-action@master
Expand Down Expand Up @@ -99,11 +103,11 @@ jobs:
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_KEY }}
script: |
aws ecr get-login-password --region ${{ env.AWS_REGION }} | docker login --username AWS --password-stdin ${{ env.ECR_REGISTRY }}
aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin ${{ secrets.ECR_REGISTRY }}
docker pull ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
docker image tag ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} ${{ env.IMAGE_NAME }}
docker rmi ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
docker pull ${{ secrets.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
docker image tag ${{ secrets.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} ${{ env.IMAGE_NAME }}
docker rmi ${{ secrets.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
- name: docker compose up [${{ inputs.module }}] on EC2
uses: appleboy/ssh-action@master
Expand Down

0 comments on commit f601c78

Please sign in to comment.