Merge pull request #143 from SportsEcho/dev1 #29
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: '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 }} >> .env_b | ||
echo AWS_ACCESS_KEY=${{ secrets.AWS_ACCESS_KEY }} >> .env_b | ||
echo AWS_SECRET_KEY=${{ secrets.AWS_SECRET_KEY }} >> .env_b | ||
echo BASEBALL_API_KEY=${{ secrets.BASEBALL_API_KEY }} >> .env_b | ||
echo BASKETBALL_API_KEY=${{ secrets.BASKETBALL_API_KEY }} >> .env_b | ||
echo FOOTBALL_API_KEY=${{ secrets.FOOTBALL_API_KEY }} >> .env_b | ||
echo GOOGLE_API_KEY=${{ secrets.GOOGLE_API_KEY }} >> .env_b | ||
echo GOOGLE_API_SECRET=${{ secrets.GOOGLE_API_SECRET }} >> .env_b | ||
echo JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }} >> .env_b | ||
echo KAKAO_API_KEY=${{ secrets.KAKAO_API_KEY }} >> .env_b | ||
echo NAVER_API_KEY=${{ secrets.NAVER_API_KEY }} >> .env_b | ||
echo NAVER_API_SECRET=${{ secrets.NAVER_API_SECRET }} >> .env_b | ||
echo RDS_USERNAME=${{ secrets.RDS_USERNAME }} >> .env_b | ||
echo RDS_PASSWORD=${{ secrets.RDS_PASSWORD }} >> .env_b | ||
echo ${{ secrets.PORT }}:${{ secrets.PORT }} >> .env_b | ||
# 백엔드 도커 이미지 pull 및 도커 컴포즈 실행 | ||
sudo docker-compose up -d |