Merge pull request #22 from utsmannn/feature/router-failure-handling #21
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 WASM Application | |
| on: | |
| pull_request: | |
| types: [closed] | |
| branches: [ main ] | |
| paths: | |
| - 'samples/**' | |
| push: | |
| branches: [ '*' ] | |
| workflow_dispatch: | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| if: | | |
| (github.event_name == 'pull_request' && github.event.pull_request.merged == true && startsWith(github.head_ref, 'samples/')) || | |
| (github.event_name == 'push' && contains(github.event.head_commit.message, '--sample-deploy')) | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| with: | |
| submodules: false | |
| - name: Set up JDK | |
| uses: actions/setup-java@v3 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '17' | |
| cache: 'gradle' | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x ./gradlew | |
| - name: Build WASM with Gradle | |
| run: ./gradlew :samples:routerApp:composeApp:wasmJsBrowserDevelopmentExecutableDistribution | |
| - name: Check WASM build output | |
| run: | | |
| echo "Checking if wasmJsDist folder was created" | |
| ls -la samples/routerApp/ | |
| # Create wasmJsDist if it doesn't exist | |
| mkdir -p samples/routerApp/wasmJsDist | |
| # Copy build output to wasmJsDist | |
| cp -r samples/routerApp/build/dist/wasmJs/developmentExecutable/* samples/routerApp/wasmJsDist/ || true | |
| echo "Contents of wasmJsDist: " | |
| ls -la samples/routerApp/wasmJsDist/ | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Build Docker image | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: ./samples/routerApp | |
| dockerfile: ./samples/routerApp/Dockerfile | |
| push: false | |
| load: true | |
| tags: wasm-server:latest | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Save Docker image | |
| run: docker save wasm-server:latest | gzip > wasm-server.tar.gz | |
| - name: Deploy to VM | |
| uses: appleboy/scp-action@master | |
| with: | |
| host: ${{ secrets.VM_HOST }} | |
| username: ${{ secrets.VM_USERNAME }} | |
| key: ${{ secrets.VM_SSH_KEY }} | |
| source: "wasm-server.tar.gz,samples/routerApp/docker-compose.yaml,samples/routerApp/Dockerfile,samples/routerApp/wasmJsDist/**" | |
| target: "~/wasm-deployment" | |
| strip_components: 0 | |
| - name: Execute remote deployment commands | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.VM_HOST }} | |
| username: ${{ secrets.VM_USERNAME }} | |
| key: ${{ secrets.VM_SSH_KEY }} | |
| script: | | |
| cd ~/wasm-deployment | |
| docker load < wasm-server.tar.gz | |
| rm -r ./wasmJsDist | |
| mv samples/routerApp/docker-compose.yaml ./docker-compose.yaml | |
| mv samples/routerApp/Dockerfile ./Dockerfile | |
| mv samples/routerApp/wasmJsDist ./wasmJsDist | |
| docker compose down | |
| docker compose up -d | |
| docker image prune -f |