Skip to content

Merge pull request #13 from wafflestudio21-5/feat/signin #23

Merge pull request #13 from wafflestudio21-5/feat/signin

Merge pull request #13 from wafflestudio21-5/feat/signin #23

Workflow file for this run

name: Deploy to ECR
on:
push:
branches: [ main ]
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
env:
IMAGE_TAG: latest
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 900017126942.dkr.ecr.ap-northeast-2.amazonaws.com/team3-server:latest
docker stop my-container || true
docker rm my-container || true
docker run -d --name my-container --network my_network -p 80:8080 900017126942.dkr.ecr.ap-northeast-2.amazonaws.com/team3-server:latest