name: Build Docker Image
run-name: Build Docker Image 
on: [push]

jobs:
  Build Docker Image:
    runs-on: ubuntu-node
    steps:
      - name: Check out repository code
        uses: actions/checkout@v4
      - name: Install project dependencies
        run: |
          (
          cd accounting-ng-nuttakit
          npm install --force --legacy-peer-deps --include=dev
          npm install -g @angular/cli
          )
          (
          cd ng-ttc-frontend
          npm install --force --legacy-peer-deps --include=dev
          npm install -g @angular/cli
          )
      - name: Build webapp
        run: |
          (
          cd accounting-ng-nuttakit
          # temporary change api url for development
          #sed -i 's@https://api.nuttakit.work@http://10.9.0.0:8080@g' src/environments/environment.ts
          ng build
          )
          (
          cd ng-ttc-frontend
          # temporary change api url for development
          #sed -i 's@https://api.nuttakit.work@http://10.9.0.0:8080@g' src/environments/environment.ts
          ng build
          )
      - name: Build docker image
        run: |
          set +e
          docker rm $(docker stop $(docker ps -a -q --filter ancestor=accounting-frontend:latest --format="{{.ID}}"))
          docker rm $(docker stop $(docker ps -a -q --filter ancestor=ttc-frontend:latest --format="{{.ID}}"))
          set -e
          docker image rm -f accounting-frontend:latest
          docker build . -t accounting-frontend:latest
          docker image rm -f ttc-frontend:latest
          docker build . -f Dockerfile-TTC -t ttc-frontend:latest

  Restart Docker Compose:
    runs-on: host
    steps:
      - name: Restart compose project
        run: |
          echo '(cd frontend-development-kickstarter && ddd && ddd && ddud)' > /hostpipe
          