Merge pull request #134 from newzet-dev/Fix/issue-#133 #17
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: Build and Deploy To Dev Environment | |
| on: | |
| push: | |
| branches: | |
| - dev | |
| jobs: | |
| build_and_deploy: | |
| runs-on: ubuntu-latest | |
| env: | |
| IMAGE_NAME: ${{ secrets.DEV_DOCKERHUB_USERNAME }}/newzet-spring-server | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: temurin | |
| java-version: 21 | |
| - name: Authenticate to Google Cloud | |
| uses: google-github-actions/auth@v2 | |
| with: | |
| credentials_json: '${{ secrets.DEV_GCP_SERVICE_ACCOUNT_KEY }}' | |
| - name: Set up gcloud CLI | |
| uses: google-github-actions/setup-gcloud@v2 | |
| with: | |
| project_id: eminent-ember-468115-i1 | |
| - name: Download New Relic Files from GCS | |
| run: | | |
| mkdir -p newrelic | |
| gsutil cp gs://newzet-dev-st/newrelic.jar ./newrelic/newrelic.jar | |
| gsutil cp gs://newzet-dev-st/newrelic.yml ./newrelic/newrelic.yml | |
| - name: Gradle Caching | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.gradle/caches | |
| ~/.gradle/wrapper | |
| key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
| restore-keys: | | |
| ${{ runner.os }}-gradle- | |
| - name: Build with Gradle | |
| run: ./gradlew build | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DEV_DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DEV_DOCKERHUB_TOKEN }} | |
| - name: Build and push Docker image | |
| run: | | |
| docker build -t $IMAGE_NAME:latest --build-arg JAR_FILE=build/libs/*.jar . | |
| docker push $IMAGE_NAME:latest | |
| - name: Setup SSH | |
| uses: webfactory/[email protected] | |
| with: | |
| ssh-private-key: ${{ secrets.DEV_SSH_PRIVATE_KEY }} | |
| - name: Deploy to VM | |
| run: | | |
| ssh -o StrictHostKeyChecking=no ${{ secrets.DEV_SSH_USER }}@${{ secrets.DEV_SSH_HOST }} \ | |
| "cd /home/jiho99322/app && bash ./deploy.sh ${{ github.sha }}" |