Skip to content

Update CD.yml

Update CD.yml #32

Workflow file for this run

name: 'sports_echo_cd'
on:
push:
branches:
- "main"
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
# JDK17 설치
- name: setup jdk
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
- name: Spring Boot Application Build
run: ./gradlew build -x test
- name: DockerHub Login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME}}
password: ${{ secrets.DOCKERHUB_PASSWORD}}
- name: Docker Image Build
run: docker build --platform linux --build-arg DEPENDENCY=build/dependency -t ${{ secrets.DOCKERHUB_USERNAME}}/${{ secrets.PROJECT_NAME }} .
- name: DockerHub Push
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}
- name: Run Application
uses: appleboy/ssh-action@v0.1.6
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_KEY }}
script: |
sudo docker-compose down
sudo docker rmi ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}
sudo rm .env_b
sudo touch .env_b
echo ADMIN_SECRET_KEY=${{ secrets.ADMIN_SECRET_KEY }} | sudo tee -a .env_b
echo AWS_ACCESS_KEY=${{ secrets.AWS_ACCESS_KEY }} | sudo tee -a .env_b
echo AWS_SECRET_KEY=${{ secrets.AWS_SECRET_KEY }} | sudo tee -a .env_b
echo BASEBALL_API_KEY=${{ secrets.BASEBALL_API_KEY }} | sudo tee -a .env_b
echo BASKETBALL_API_KEY=${{ secrets.BASKETBALL_API_KEY }} | sudo tee -a .env_b
echo FOOTBALL_API_KEY=${{ secrets.FOOTBALL_API_KEY }} | sudo tee -a .env_b
echo GOOGLE_API_KEY=${{ secrets.GOOGLE_API_KEY }} >> | sudo tee -a .env_b
echo GOOGLE_API_SECRET=${{ secrets.GOOGLE_API_SECRET }} | sudo tee -a .env_b
echo JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }} >> | sudo tee -a .env_b
echo KAKAO_API_KEY=${{ secrets.KAKAO_API_KEY }} >> | sudo tee -a .env_b
echo NAVER_API_KEY=${{ secrets.NAVER_API_KEY }} >> | sudo tee -a .env_b
echo NAVER_API_SECRET=${{ secrets.NAVER_API_SECRET }} >> | sudo tee -a .env_b
echo RDS_USERNAME=${{ secrets.RDS_USERNAME }} >> | sudo tee -a .env_b
echo RDS_PASSWORD=${{ secrets.RDS_PASSWORD }} >> | sudo tee -a .env_b
echo ${{ secrets.PORT }}:${{ secrets.PORT }} >> | sudo tee -a .env_b
sudo docker-compose up -d