name: Build and Push Docker Image
on:
    push:
        branches:
            - dev
jobs:
    build-and-push:
        runs-on: ubuntu-latest
        steps:
            - name: Checkout code
              uses: actions/checkout@v2
            - name: Install dependencies & build next app
              run: |
                  npm i -g pnpm
                  pnpm i
                  pnpm build
            - name: Login to Docker Hub
              uses: docker/login-action@v1
              with:
                  username: ${{ secrets.DOCKER_USERNAME }}
                  password: ${{ secrets.DOCKER_PASSWORD }}
            - name: Build and push Docker image
              uses: docker/build-push-action@v2
              with:
                  context: .
                  push: true
                  tags: jadenxiong/chat-query:latest
                  build-args: |
                      NEXT_PUBLIC_BACKEND_URL=${{ secrets.NEXT_PUBLIC_BACKEND_URL }}
                      NEXT_PUBLIC_OPEN_AI_API_KEY=${{ secrets.NEXT_PUBLIC_OPEN_AI_API_KEY }}
                      OPENAI_PROXY_URL=${{ secrets.OPENAI_PROXY_URL }}
