chore: CI/CD 세팅 진행중 (테스트 PR) (#17) #1
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: Dev CI/CD - Build and Deploy | |
| on: | |
| push: | |
| branches: | |
| - develop | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: false | |
| env: | |
| REGISTRY: docker.io | |
| IMAGE_NAME: ninecraft0523/ninecraft-server | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-24.04 | |
| timeout-minutes: 20 | |
| outputs: | |
| tags: ${{ steps.meta.outputs.tags }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Inject application-secret.properties from Secrets | |
| run: | | |
| mkdir ./secret | |
| echo "${{ secrets.DEV_SECRET_PROPERTIES }}" > ./secret/application-dev-secret.properties | |
| echo "${{ secrets.PROD_SECRET_PROPERTIES }}" > ./secret/application-prod-secret.properties | |
| echo "${{ secrets.TEST_SECRET_PROPERTIES }}" > ./secret/application-test-secret.properties | |
| chmod 600 ./secret/* | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '21' | |
| distribution: 'temurin' | |
| cache: gradle | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v4 | |
| with: | |
| gradle-home-cache-cleanup: true | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x gradlew | |
| - name: Run full Gradle build | |
| run: ./gradlew build --parallel --build-cache | |
| - name: Extract metadata for Docker | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=raw,value=development-latest | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| platforms: linux/amd64,linux/arm64 | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| deploy-dev: | |
| needs: build-and-push | |
| runs-on: ubuntu-24.04 | |
| timeout-minutes: 10 | |
| environment: development | |
| steps: | |
| - name: Deploy to Development Server | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.DEV_HOST }} | |
| username: ${{ secrets.DEV_USERNAME }} | |
| key: ${{ secrets.DEV_SSH_KEY }} | |
| port: ${{ secrets.DEV_PORT }} | |
| script: | | |
| cd /opt/app | |
| export DOCKERHUB_USERNAME="${{ secrets.DOCKERHUB_USERNAME }}" | |
| export DOCKERHUB_TOKEN="${{ secrets.DOCKERHUB_TOKEN }}" | |
| export IMAGE_TAG="${{ needs.build-and-push.outputs.tags }}" | |
| cd ~/deploy | |
| chmod +x ./deploy.sh | |
| ./deploy.sh | |