Build and Deploy to Staging Server #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: Build and Deploy to Staging Server | |
| on: | |
| workflow_dispatch: | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| environment: staging | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x gradlew | |
| - name: Build all modules | |
| run: | | |
| ./gradlew clean build -p aics-admin -x test | |
| ./gradlew clean build -p aics-api -x test | |
| ./gradlew clean build -p aics-auth -x test | |
| - name: Build Docker images | |
| run: | | |
| docker build -t aics-admin:${GITHUB_SHA} -f aics-admin/Dockerfile aics-admin | |
| docker build -t aics-api:${GITHUB_SHA} -f aics-api/Dockerfile aics-api | |
| docker build -t aics-auth:${GITHUB_SHA} -f aics-auth/Dockerfile aics-auth | |
| - name: Save Docker images as tar | |
| run: | | |
| mkdir -p deploy | |
| docker save aics-admin:${GITHUB_SHA} -o deploy/aics-admin.tar | |
| docker save aics-api:${GITHUB_SHA} -o deploy/aics-api.tar | |
| docker save aics-auth:${GITHUB_SHA} -o deploy/aics-auth.tar | |
| - name: Upload Docker images to server | |
| uses: appleboy/scp-action@v1.0.0 | |
| with: | |
| host: ${{ secrets.STAGING_SERVER_HOST }} | |
| username: ${{ secrets.STAGING_SERVER_USERNAME }} | |
| password: ${{ secrets.STAGING_SERVER_PASSWORD }} | |
| port: ${{ secrets.STAGING_SERVER_PORT }} | |
| source: "deploy/*" | |
| target: ${{ secrets.STAGING_DEPLOY_PATH }} | |
| - name: Deploy on server | |
| uses: appleboy/ssh-action@v1.1.0 | |
| with: | |
| host: ${{ secrets.STAGING_SERVER_HOST }} | |
| username: ${{ secrets.STAGING_SERVER_USERNAME }} | |
| password: ${{ secrets.STAGING_SERVER_PASSWORD }} | |
| port: ${{ secrets.STAGING_SERVER_PORT }} | |
| script: | | |
| cd ${{ secrets.STAGING_DEPLOY_PATH }} | |
| chmod +x backend/deploy.sh | |
| ./backend/deploy.sh |