stages:
  - build

variables:
  HARBOR_REGISTRY: harbor-in-k3s.cheverjohn.me
  HARBOR_PROJECT: iloom
  DOCKER_TLS_CERTDIR: "/certs"
  DOCKER_HOST: tcp://localhost:2376
  DOCKER_TLS_VERIFY: "1"
  DOCKER_CERT_PATH: /certs/client

build-frontend:
  stage: build
  image: docker:27
  services:
    - docker:27-dind
  before_script:
    - until docker info >/dev/null 2>&1; do echo "Waiting for Docker daemon..."; sleep 2; done
    - echo "$HARBOR_PASSWORD" | docker login $HARBOR_REGISTRY -u "$HARBOR_USER" --password-stdin
  script:
    - |
      if [ -n "$CI_COMMIT_TAG" ]; then
        TAG="$CI_COMMIT_TAG"
      else
        TAG="main-${CI_COMMIT_SHORT_SHA}"
      fi
    - docker build -t $HARBOR_REGISTRY/$HARBOR_PROJECT/iloom-frontend:$TAG .
    - docker push $HARBOR_REGISTRY/$HARBOR_PROJECT/iloom-frontend:$TAG
  rules:
    - if: $CI_COMMIT_BRANCH == "main"
    - if: $CI_COMMIT_TAG =~ /^v/
