Merge pull request #361 from mosu-dev/refactor/mosu-360 #71
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: Docker CI/CD - Deploy | |
| on: | |
| push: | |
| branches: [ develop ] | |
| workflow_dispatch: | |
| jobs: | |
| deploy: | |
| runs-on: self-hosted | |
| steps: | |
| - name: Checkout source | |
| uses: actions/checkout@v3 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '21' | |
| distribution: 'temurin' | |
| - name: Cache Gradle files | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.gradle/caches | |
| ~/.gradle/wrapper | |
| key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
| restore-keys: | | |
| gradle-${{ runner.os }}- | |
| - name: Clone external repo with jar into libs/ | |
| run: | | |
| mkdir -p libs | |
| git clone https://x-access-token:${{ secrets.GH_PAT }}@github.com/mosu-dev/mosu-kmc-jar.git temp-jar | |
| cp temp-jar/*.jar libs/ | |
| - name: Build with Gradle | |
| run: ./gradlew build -x test | |
| - name: Log in to DockerHub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Build Docker image | |
| run: sudo docker build -t kangtaehyun1107/mosu-server:${{ github.sha }} . | |
| working-directory: | |
| - name: Push Docker image | |
| run: sudo docker push kangtaehyun1107/mosu-server:${{ github.sha }} | |
| - name: Deploy via SSH | |
| run: | | |
| cd ~/mosu-server | |
| echo "${{ secrets.ENV_BASE }}" > .env | |
| echo "${{ secrets.ENV_BASE }}" > .env.blue | |
| echo "${{ secrets.ENV_BASE }}" > .env.green | |
| echo "${{ secrets.ENV_TEST }}" >> .env | |
| echo "${{ secrets.ENV_TEST }}" >> .env.blue | |
| echo "${{ secrets.ENV_TEST }}" >> .env.green | |
| echo "APP_IMAGE_VERSION=${{ github.sha }}" >> .env | |
| echo "APP_IMAGE_VERSION=${{ github.sha }}" >> .env.blue | |
| echo "APP_IMAGE_VERSION=${{ github.sha }}" >> .env.green | |
| sudo docker stop $(sudo docker ps -aq) || true | |
| sudo docker rm $(sudo docker ps -aq) || true | |
| echo "Stopping all containers..." | |
| sudo ./deploy.sh |