Skip to content

Commit

Permalink
chore:도커파일,yml파일작성 (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
JjungminLee authored Jan 22, 2024
1 parent 91f5db2 commit c91ed13
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git
Dockerfile
node_modules
.env.development
23 changes: 14 additions & 9 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,13 @@ jobs:
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Cleanup Unused ECR Images
id: cleanup-images
env:
ECR_REPOSITORY: moidot
IMAGE_TAG: ${{ github.sha }}
run: |
# AWS CLI를 사용하여 ECR 이미지 삭제
aws ecr batch-delete-image --repository-name $ECR_REPOSITORY --image-ids imageTag=$IMAGE_TAG
deploy:
Expand All @@ -55,12 +52,20 @@ jobs:
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: moidot
ECR_REPOSITORY: moidot-fe
IMAGE_TAG: ${{ github.sha }}
run: |
# 이미지 빌드 및 푸시
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
# 현재 이미지 태그를 파일에 기록
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_ENV
# 이전 이미지 삭제
aws ecr batch-delete-image --repository-name $ECR_REPOSITORY --image-ids imageTag=$IMAGE_TAG
# 로컬에서 사용된 이미지 삭제
docker rmi $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
- name: Deploy to EC2
Expand All @@ -72,10 +77,10 @@ jobs:
chmod 600 private_key.pem
ssh -i private_key.pem -o StrictHostKeyChecking=no ubuntu@$EC2_IP "
aws ecr get-login-password --region ap-northeast-2 |
sudo docker login --username AWS --password-stdin 903755389667.dkr.ecr.ap-northeast-2.amazonaws.com/moidot &&
sudo docker login --username AWS --password-stdin 637423378629.dkr.ecr.ap-northeast-2.amazonaws.com/moidot-fe &&
if [ \$(sudo docker ps -q -f name=moidot) ]; then
sudo docker stop moidot &&
sudo docker rm moidot
fi &&
sudo docker image pull 903755389667.dkr.ecr.ap-northeast-2.amazonaws.com/moidot:$IMAGE_TAG &&
sudo docker container run --name moidot -d -p 3000:3000 903755389667.dkr.ecr.ap-northeast-2.amazonaws.com/moidot:$IMAGE_TAG"
sudo docker image pull 637423378629.dkr.ecr.ap-northeast-2.amazonaws.com/moidot-fe:$IMAGE_TAG &&
sudo docker container run --name moidot -d -p 3000:3000 637423378629.dkr.ecr.ap-northeast-2.amazonaws.com/moidot-fe:$IMAGE_TAG"
Empty file added Dockerfile
Empty file.

0 comments on commit c91ed13

Please sign in to comment.