Skip to content

Commit

Permalink
cd: Add deploy to EC2
Browse files Browse the repository at this point in the history
  • Loading branch information
Arabasta committed Jul 13, 2024
1 parent e48e3b5 commit e0709c1
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions .github/workflows/cd_spring_backend.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CD
name: CD with Docker and AWS

on:
push:
Expand Down Expand Up @@ -36,4 +36,22 @@ jobs:
with:
context: ./spring_backend
push: true
tags: ${{ secrets.KEI_DOCKER_USERNAME }}/oracle_spring_backend:${{ github.sha }}
tags: ${{ secrets.KEI_DOCKER_USERNAME }}/oracle_spring_backend:${{ github.sha }}

- name: Deploy to EC2
env:
EC2_SSH_KEY: ${{ secrets.KEI_EC2_SSH_KEY }}
EC2_PUBLIC_IPV4: ${{ secrets.KEI_EC2_PUBLIC_IPV4 }}
run: |
echo "${EC2_SSH_KEY}" > /tmp/key.pem
chmod 600 /tmp/key.pem
ssh -o StrictHostKeyChecking=no -i /tmp/key.pem ec2-user@${{ env.EC2_PUBLIC_IPV4 }} << 'EOF'
docker pull ${{ secrets.KEI_DOCKER_USERNAME }}/oracle_spring_backend:${{ github.sha }}
docker stop oracle_spring_backend || true
docker rm oracle_spring_backend || true
docker run -d \
--name oracle_spring_backend \
-p 8080:8080 \
${{ secrets.KEI_DOCKER_USERNAME }}/oracle_spring_backend:${{ github.sha }}
docker logs oracle_spring_backend
EOF

0 comments on commit e0709c1

Please sign in to comment.