ci: 중복 yml 설정 제거 #4
This file contains hidden or 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: cicd-prod | |
on: | |
push: | |
branches: [ "main" ] | |
jobs: | |
deploy-to-ec2: | |
environment: prod | |
runs-on: ubuntu-latest | |
steps: | |
- name: Github Repository Checkout | |
uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Build with Gradle | |
uses: gradle/gradle-build-action@v2 | |
with: | |
arguments: build | |
- name: Generate .env file | |
run: | | |
cd "build/libs" | |
echo "export KAFKA_URL=${{ secrets.KAFKA_URL }}" > env.sh | |
echo "export KAFKA_GROUP_ID=${{ secrets.KAFKA_GROUP_ID }}" >> env.sh | |
echo "export PROD_MYSQL_URL=${{ secrets.PROD_MYSQL_URL }}" >> env.sh | |
echo "export PROD_MYSQL_USERNAME=${{ secrets.PROD_MYSQL_USERNAME }}" >> env.sh | |
echo "export PROD_MYSQL_PASSWORD=${{ secrets.PROD_MYSQL_PASSWORD }}" >> env.sh | |
echo "cd /home/ubuntu/build/libs" >> restart.sh | |
echo "source env.sh" >> restart.sh | |
echo "pkill -f 'java -Dspring.profiles.active=prod -jar'" >> restart.sh | |
echo "nohup java -Dspring.profiles.active=prod -jar product-0.0.1-SNAPSHOT.jar > app.log 2>&1 &" >> restart.sh | |
chmod 755 restart.sh | |
chmod 755 env.sh | |
- name: Sending build file to NAS | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
port: ${{ secrets.EC2_PORT }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_KEY }} | |
source: "build/libs/*" | |
target: "/home/ubuntu/" | |
- name: Deploy to EC2 and Restart Service | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
port: ${{ secrets.EC2_PORT }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_KEY }} | |
script: | | |
/home/ubuntu/build/libs/restart.sh |