Merge pull request #127 from KB-Hackerton/feature/112 #90
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: CI-CD.yml | |
| on: | |
| push: | |
| branches: ["develop"] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: 📢 깃허브 checkout!!! | |
| uses: actions/checkout@v3 | |
| - name: 📢 GitHubAction JDK 17 설치 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| - name: 📢 Gradle 실행 권한 부여 | |
| run: chmod +x gradlew | |
| - name: 📢 Gradle 캐싱 | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.gradle/caches | |
| ~/.gradle/wrapper | |
| key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
| restore-keys: | | |
| ${{ runner.os }}-gradle- | |
| - name: 📢 GitIgnore 파일들 넣어주기 | |
| env: | |
| APPLICATION_PROPERTIES: ${{ secrets.APPLICATION_PROPERTIES}} | |
| run: | | |
| rm -f src/main/resources/application.properties | |
| echo "${{ secrets.APPLICATION_PROPERTIES }}" > src/main/resources/application.properties | |
| - name: 📢 Gradle 빌드(jar 만들기) | |
| run: ./gradlew clean bootJar -x test | |
| - name: 📢 Docker image 만들기 | |
| run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/hackerton . | |
| - name: 📢 DockerHub에 로그인 | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME}} | |
| password: ${{ secrets.DOCKERHUB_PASSWORD}} | |
| - name: 📢 DockerHub에 PUSH | |
| run: docker push ${{ secrets.DOCKERHUB_USERNAME}}/hackerton | |
| deploy: | |
| runs-on: ubuntu-latest | |
| needs: build | |
| if: github.event_name == 'push' | |
| steps: | |
| - name: 📢SSH로 EC2에 접속해보자 | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.EC2_HOST}} | |
| username: ${{ secrets.EC2_USERNAME}} | |
| key: ${{ secrets.EC2_PRIVATE_KEY}} | |
| proxy_host: ${{ secrets.SSH_TUN_HOST }} # 퍼블릭 IP를 가진 중간 서버 | |
| proxy_username: ${{ secrets.SSH_USER }} # 터널링 서버의 사용자 | |
| proxy_key: ${{ secrets.SSH_PEM_KEY }} | |
| port: 22 | |
| command_timeout: 30m | |
| script: | | |
| echo "✅ EC2 연결 성공!" | |
| echo "✅ Docker를 실행 시키기 위해 compose.yml 파일로 고고띠" | |
| cd ~/hackerton | |
| echo "✅ DockerHub 에서 이미지 가져오기(pull)" | |
| docker pull ${{ secrets.DOCKERHUB_USERNAME }}/hackerton | |
| echo "✅ 이제 DockeCompose 돌리자!!" | |
| docker compose down | |
| docker compose up -d | |
| echo "✅ PortForwarding을 8080으로 했으니깐 Public IP의 8080포트로 가자 " | |
| echo "✅ 배포 완료" |