Merge pull request #152 from SportsEcho/dev1 #37
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 kill ${{ secrets.PROJECT_NAME }} | |
sudo docker rm -f ${{ secrets.PROJECT_NAME }} | |
sudo docker rmi ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }} | |
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }} | |
sudo docker run \ | |
-e ADMIN_SECRET_KEY=${{ secrets.ADMIN_SECRET_KEY }} \ | |
-e AWS_ACCESS_KEY=${{ secrets.AWS_ACCESS_KEY }} \ | |
-e AWS_SECRET_KEY=${{ secrets.AWS_SECRET_KEY }} \ | |
-e BASEBALL_API_KEY=${{ secrets.BASEBALL_API_KEY }} \ | |
-e BASKETBALL_API_KEY=${{ secrets.BASKETBALL_API_KEY }} \ | |
-e FOOTBALL_API_KEY=${{ secrets.FOOTBALL_API_KEY }} \ | |
-e GOOGLE_API_KEY=${{ secrets.GOOGLE_API_KEY }} \ | |
-e GOOGLE_API_SECRET=${{ secrets.GOOGLE_API_SECRET }} \ | |
-e JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }} \ | |
-e KAKAO_API_KEY=${{ secrets.KAKAO_API_KEY }} \ | |
-e NAVER_API_KEY=${{ secrets.NAVER_API_KEY }} \ | |
-e NAVER_API_SECRET=${{ secrets.NAVER_API_SECRET }} \ | |
-e RDS_USERNAME=${{ secrets.RDS_USERNAME }} \ | |
-e RDS_PASSWORD=${{ secrets.RDS_PASSWORD }} \ | |
-p ${{ secrets.PORT }}:${{ secrets.PORT }} \ | |
--name ${{ secrets.PROJECT_NAME }} \ | |
-d ${{ secrets.DOCKERHUB_USERNAME}}/${{ secrets.PROJECT_NAME }} |