Chore: μμ #19
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 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 # μλ‘μ΄ μ»¨ν μ΄λ μμ |