Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] Manager CD test #67

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading