Skip to content

Chore: μ‚­μ œ #19

Chore: μ‚­μ œ

Chore: μ‚­μ œ #19

Workflow file for this run

name: Deploy to EC2 with Docker Compose
on:
push:
branches: ["main"]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Check out the code
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Build with Gradle
run: ./gradlew build
- name: Log in to Docker Hub
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
- name: Build Docker image
run: docker build -t ${{ secrets.DOCKER_USERNAME }}/akoming-test:latest .
- name: Push Docker image to Docker Hub
run: docker push ${{ secrets.DOCKER_USERNAME }}/akoming-test:latest
# docker-compose.yml νŒŒμΌμ„ EC2둜 볡사
- name: Copy docker-compose.yml to EC2
uses: appleboy/scp-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_PRIVATE_KEY }}
source: "./docker-compose.yml" # 둜컬의 docker-compose.yml 파일
target: "/home/ubuntu/docker-compose.yml" # EC2 λ‚΄μ˜ μ •ν™•ν•œ 파일 경둜
- name: Deploy on EC2 with Docker Compose
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_PRIVATE_KEY }}
script: |
cd /home/ubuntu
sudo docker-compose down # κΈ°μ‘΄ μ»¨ν…Œμ΄λ„ˆ 쀑지
sudo docker-compose pull # μ΅œμ‹  이미지 κ°€μ Έμ˜€κΈ°
sudo docker-compose up -d # μƒˆλ‘œμš΄ μ»¨ν…Œμ΄λ„ˆ μ‹œμž‘