🚀 deploy config update #22
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: Build and Deploy with JIB | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v1 | |
with: | |
java-version: '21' | |
- name: Log in to Docker Hub | |
env: | |
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | |
run: | | |
echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin | |
- name: Build and push Docker image with JIB | |
env: | |
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
DATABASE_URL: ${{ secrets.DATABASE_URL }} | |
run: ./gradlew jib -Djib.to.auth.username=${{ secrets.DOCKER_USERNAME }} -Djib.to.auth.password=${{ secrets.DOCKER_PASSWORD }} -Djib.to.image=${{ secrets.DOCKER_USERNAME }}/learnmate:latest | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Create SSH Key Directory | |
run: mkdir -p ~/.ssh | |
- name: Create SSH Key File | |
run: | | |
echo "${{ secrets.EC2_SSH_KEY }}" > ~/.ssh/id_rsa | |
cat ~/.ssh/id_rsa # 디버그용: 키 파일 내용을 출력 | |
chmod 600 ~/.ssh/id_rsa | |
- name: Create SSH Key File | |
run: | | |
echo "${{ secrets.EC2_SSH_KEY }}" > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
- name: Connect to EC2 and deploy | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ec2-user | |
key_path: ~/.ssh/id_rsa | |
script: | | |
echo "Stopping and removing any existing application container..." | |
docker-compose -f /home/ec2-user/your_project_folder/docker-compose.yml down || true | |
echo "Pulling the latest Docker image..." | |
docker pull ${{ secrets.DOCKER_USERNAME }}/learnmate:latest | |
echo "Starting application with docker-compose..." | |
docker-compose -f /home/ec2-user/your_project_folder/docker-compose.yml up -d |