Merge branch 'develop' #86
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 Spring Boot to EC2 | |
on: | |
push: | |
branches: | |
- main | |
# - develop | |
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: Set up Docker credentials | |
run: | | |
echo "DOCKER_USERNAME=${{ secrets.DOCKER_USERNAME }}" >> $GITHUB_ENV | |
echo "DOCKER_PASSWORD=${{ secrets.DOCKER_PASSWORD }}" >> $GITHUB_ENV | |
- name: Build JAR file | |
run: ./gradlew bootJar | |
- name: Build and push Docker image with JIB | |
run: ./gradlew jib -Pprod --image=${{ secrets.DOCKER_USERNAME }}/the_monitor:latest | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Connect to EC2 and deploy | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ec2-user | |
key: ${{ secrets.EC2_PRIVATE_KEY }} | |
script: | | |
# Create a custom network if it doesn't exist | |
docker network inspect the_monitor_network >/dev/null 2>&1 || docker network create the_monitor_network | |
# Stop and remove any existing Redis container | |
docker stop redis-server || true | |
docker rm redis-server || true | |
# Run Redis in the custom network | |
docker run -d --name redis-server --network the_monitor_network \ | |
-p 6379:6379 redis | |
# Pull the latest application image | |
docker pull ${{ secrets.DOCKER_USERNAME }}/the_monitor:latest | |
# Stop and remove any existing application container | |
docker stop the_monitor-container || true | |
docker rm the_monitor-container || true | |
# Run the application in the custom network | |
docker run -d --network the_monitor_network -p 8080:8080 --name the_monitor-container \ | |
-e SPRING_DATASOURCE_URL="${{ secrets.SPRING_DATASOURCE_URL }}" \ | |
-e SPRING_DATASOURCE_USERNAME="${{ secrets.SPRING_DATASOURCE_USERNAME }}" \ | |
-e SPRING_DATASOURCE_PASSWORD="${{ secrets.SPRING_DATASOURCE_PASSWORD }}" \ | |
-e CLOUD_AWS_REGION_STATIC="${{ secrets.CLOUD_AWS_REGION_STATIC }}" \ | |
-e CLOUD_AWS_CREDENTIALS_ACCESS_KEY="${{ secrets.CLOUD_AWS_CREDENTIALS_ACCESS_KEY }}" \ | |
-e CLOUD_AWS_CREDENTIALS_SECRET_KEY="${{ secrets.CLOUD_AWS_CREDENTIALS_SECRET_KEY }}" \ | |
-e CLOUD_AWS_S3_BUCKET="${{ secrets.CLOUD_AWS_S3_BUCKET }}" \ | |
-e SPRING_MAIL_HOST="smtp.gmail.com" \ | |
-e SPRING_MAIL_PORT="587" \ | |
-e SPRING_MAIL_USERNAME="${{ secrets.SPRING_MAIL_USERNAME }}" \ | |
-e SPRING_MAIL_PASSWORD="${{ secrets.SPRING_MAIL_PASSWORD }}" \ | |
-e JWT_SECRET_KEY="${{ secrets.JWT_SECRET_KEY }}" \ | |
-e JWT_ACCESS_TOKEN_EXPIRE="${{ secrets.JWT_ACCESS_TOKEN_EXPIRE }}" \ | |
-e JWT_REFRESH_TOKEN_EXPIRE="${{ secrets.JWT_REFRESH_TOKEN_EXPIRE }}" \ | |
-e SPRING_DATA_REDIS_HOST="redis-server" \ | |
-e SPRING_DATA_REDIS_PORT=6379 \ | |
-e NAVER_API_CLIENT_ID="${{ secrets.NAVER_API_CLIENT_ID }}" \ | |
-e NAVER_API_CLIENT_SECRET="${{ secrets.NAVER_API_CLIENT_SECRET }}" \ | |
-e NAVER_API_BASE_URL="${{ secrets.NAVER_API_BASE_URL }}" \ | |
-e GOOGLE_API_KEY="${{ secrets.GOOGLE_API_KEY }}" \ | |
-e GOOGLE_API_SEARCH_ENGINE_ID="${{ secrets.GOOGLE_API_SEARCH_ENGINE_ID }}" \ | |
-e GOOGLE_API_BASE_URL="${{ secrets.GOOGLE_API_BASE_URL }}" \ | |
${{ secrets.DOCKER_USERNAME }}/the_monitor:latest |