Fix : url 수정 #10
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy to ECR | |
# 배포 테스트 단계 : dev/auto-deploy에 push되는 코드가 aws에 올라가는지 확인 | |
on: | |
push: | |
branches: [ dev/auto-deploy ] | |
jobs: | |
deploy: | |
name: Deploy | |
runs-on: ubuntu-latest | |
env: | |
IMAGE_TAG: v${{ github.run_number }} | |
ECR_REGISTRY: 900017126942.dkr.ecr.ap-northeast-2.amazonaws.com | |
ECR_REPOSITORY: team3-server | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v2 | |
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 ECR | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Remove all images from ECR | |
run: | | |
aws ecr list-images --repository-name $ECR_REPOSITORY --query 'imageIds[*]' --output json | jq -r '.[] | .imageDigest' | xargs -I {} aws ecr batch-delete-image --repository-name $ECR_REPOSITORY --image-ids imageDigest={} | |
- name: Docker build, tag, and push image to ECR | |
run: | | |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" | |
- name: Deploy to EC2 | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_SSH_KEY }} | |
script: | | |
docker pull $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
docker stop my-container || true | |
docker rm my-container || true | |
docker run -d --name my-container -p 80:8080 $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG |