name: Build & Push Image

on:
  push:
    branches: [main]
  workflow_dispatch:

jobs:
  build:
    name: Build and push to GHCR
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:
      - name: Checkout Code
        uses: actions/checkout@v4
        with:
          lfs: true

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Login to GHCR
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      # Сборка Лендинга (Next.js)
      - name: Build and Push Landing
        uses: docker/build-push-action@v5
        with:
          context: .
          file: ./Dockerfile
          push: true
          tags: ghcr.io/nineap/netrunner-landing:latest
          cache-from: type=registry,ref=ghcr.io/nineap/netrunner-landing:cache
          cache-to: type=registry,ref=ghcr.io/nineap/netrunner-landing:cache,mode=max

      # Сборка Прокси (Rust)
      - name: Build and Push Proxy
        uses: docker/build-push-action@v5
        with:
          context: ./proxy-ws
          file: ./proxy-ws/Dockerfile
          push: true
          tags: ghcr.io/nineap/netrunner-landing-proxy:latest
          cache-from: type=registry,ref=ghcr.io/nineap/netrunner-landing-proxy:cache
          cache-to: type=registry,ref=ghcr.io/nineap/netrunner-landing-proxy:cache,mode=max
