Skip to content

Commit

Permalink
feat: cicd docker 버전2
Browse files Browse the repository at this point in the history
  • Loading branch information
yooookm committed Nov 14, 2024
1 parent f2121de commit 7a64040
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Java CI and Deploy to AWS EC2 with Docker

on:
push:
branches: [ "Week10" ]
branches: [ "readme" ]

jobs:
build:
Expand All @@ -18,15 +18,15 @@ jobs:

- name: Build Docker Image
run: |
docker build -t your-app:latest .
docker build -t care-app:latest .
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Decode and save .pem file
- name: Save SSH key
env:
EC2_SSH_KEY_BASE64: ${{ secrets.EC2_SSH_KEY_BASE64 }}
EC2_SSH_KEY: ${{ secrets.EC2_SSH_KEY }}
run: |
echo "$EC2_SSH_KEY" > ec2-key.pem
chmod 600 ec2-key.pem
Expand All @@ -37,11 +37,13 @@ jobs:
EC2_USER: ${{ secrets.EC2_USER }}
run: |
# Docker 이미지 μ €μž₯ ν›„ EC2에 전솑
docker save your-app:latest | bzip2 | ssh -i ec2-key.pem -o StrictHostKeyChecking=no $EC2_USER@$EC2_HOST 'bunzip2 | docker load'
docker save care-app:latest | bzip2 | ssh -i ec2-key.pem -o StrictHostKeyChecking=no $EC2_USER@$EC2_HOST 'bunzip2 | docker load'
# application-secret.yml νŒŒμΌμ„ /app/config에 λ§ˆμš΄νŠΈν•˜μ—¬ Docker μ»¨ν…Œμ΄λ„ˆ μ‹€ν–‰
# κΈ°μ‘΄ μ»¨ν…Œμ΄λ„ˆ 쀑지 및 μ‚­μ œ ν›„ μƒˆ μ»¨ν…Œμ΄λ„ˆ μ‹€ν–‰
ssh -i ec2-key.pem -o StrictHostKeyChecking=no $EC2_USER@$EC2_HOST << 'EOF'
docker stop your-app-container || true
docker rm your-app-container || true
docker run -d --name your-app-container -v /path/on/ec2/application-secret.yml:/app/config/application-secret.yml -p 8080:8080 your-app:latest
echo "κΈ°μ‘΄ μ»¨ν…Œμ΄λ„ˆ 쀑지 및 μ‚­μ œ 쀑..."
docker stop care-app-container || echo "μ‹€ν–‰ 쀑인 μ»¨ν…Œμ΄λ„ˆ μ—†μŒ"
docker rm care-app-container || echo "μ œκ±°ν•  μ»¨ν…Œμ΄λ„ˆ μ—†μŒ"
echo "μƒˆλ‘œμš΄ μ»¨ν…Œμ΄λ„ˆλ₯Ό μ‹€ν–‰ν•©λ‹ˆλ‹€."
docker run -d --name care-app-container -v /path/on/ec2/application-secret.yml:/app/config/application-secret.yml -p 8080:8080 care-app:latest
EOF

0 comments on commit 7a64040

Please sign in to comment.