name: Build and Deploy docker container
'on':
  push:
    branches: main
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout main
        uses: actions/checkout@v4
      - name: Install Yarn
        run: npm install -g yarn
      - name: Set Node.js 22.x
        uses: actions/setup-node@v4
        with:
          node-version: 22.x
          cache: yarn
      - name: Get yarn cache directory path
        id: yarn-cache-dir-path
        run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
      - name: Restore cache
        uses: actions/cache@v4
        id: yarn-cache
        with:
          path: |
            ${{ steps.yarn-cache-dir-path.outputs.dir }}
            ${{ github.workspace }}/.next/
            node_modules/
            ${{ github.workspace }}/out/
          key: '${{ runner.os }}-yarn-${{ hashFiles(''**/yarn.lock'') }}'
          restore-keys: |
            ${{ runner.os }}-yarn-
      - name: Update node modules
        run: yarn install --immutable
      - name: Lint
        run: yarn lint
      - name: Build app and export to ./out
        run: EXPORT=1 UNOPTIMIZED=1 yarn build
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
      - name: Login to Docker Hub
        uses: docker/login-action@v3
        with:
          registry: git.jonb.io
          username: '${{ gitea.actor }}'
          password: '${{ secrets.JONBIO_CI }}'
      - name: Build and push
        uses: docker/build-push-action@v6
        with:
          context: .
          push: true
          tags: 'git.jonb.io/jblu/jonbio:latest'
          cache-from: 'type=registry,ref=git.jonb.io/jblu/jonbio:buildcache'
          cache-to: >-
            type=registry,image-manifest=true,oci-mediatypes=true,ref=git.jonb.io/jblu/jonbio:buildcache,mode=max
      - name: Deploy app
        uses: fjogeleit/http-request-action@v1
        with:
          url: 'http://10.5.0.11:7777/v1/update'
          method: GET
          bearerToken: '${{ secrets.DEPLOYTOKEN }}'
          timeout: 60000