name: Build Flutter Web and Docker Image for Local Registry

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

jobs:
  build:
    name: Build Flutter Web App
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Install Flutter
        run: |
          sudo apt-get update
          sudo apt-get install -y curl
          cd /usr/local
          curl -o flutter.tar.xz https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_3.7.7-stable.tar.xz
          tar xf flutter.tar.xz
          pwd
          export PATH="$PATH:/usr/local/flutter/bin"
          flutter upgrade
          flutter doctor

      - name: Flutter Pub Get
        run: |
          /usr/local/flutter/bin/flutter pub get

      - name: Build Flutter Web
        run: |
          /usr/local/flutter/bin/flutter build web --release --dart-define=WS_BASE_URL=${{ secrets.WS_BASE_URL }} --dart-define=REST_BASE_URL=${{ secrets.REST_BASE_URL }}
          ls -l 

      - name: List Web Build Output
        run: |
          ls -l build/web

      - name: Build Docker Image
        run: |
          docker build -t localhost:5000/pogdark-app:latest .

      - name: Push Docker Image to Local Registry
        run: |
          docker push localhost:5000/pogdark-app:latest