Feat: init MongoDB (#12) #5
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 Deployment | |
| on: | |
| push: | |
| branches: [ develop, feat/mongo ] | |
| jobs: | |
| build: | |
| name: Build and push Docker image | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - uses: actions/checkout@v3 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '17' | |
| distribution: 'adopt' | |
| - name: Build with Gradle | |
| run: | | |
| chmod +x ./gradlew | |
| ./gradlew clean build -x test | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Build Docker image | |
| run: docker build -t devsolfe/server:latest . | |
| - name: Push Docker image to Docker Hub | |
| run: docker push devsolfe/server:latest | |
| deploy: | |
| name: Deploy | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: executing remote ssh commands using ssh key | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.SERVER_HOST }} | |
| username: ${{ secrets.SSH_USERNAME }} | |
| key: ${{ secrets.SSH_KEY }} | |
| port: ${{ secrets.PORT }} | |
| script: | | |
| docker pull devsolfe/server:latest | |
| if [ "$(docker ps -aq -f name=server)" ] | |
| then | |
| echo "[ spring is running ]" | |
| docker stop server | |
| docker rm server | |
| else | |
| echo "[ spring is not running ]" | |
| fi | |
| docker run -d --name server -e SPRING_PROFILES_ACTIVE=dev -e MONGODB_URI_DEV=${{ secrets.MONGODB_URI_DEV }} -e MONGODB_DATABASE_DEV=${{ secrets.MONGODB_DATABASE_DEV }} -p 80:8080 devsolfe/server | |
| docker image prune -f |