# include:
#   - project: 'cokoapps/ci'
#     ref: main
#     file: 'ci-templates.yml'

variables:
  IMAGE_NAME_DEMO: $CI_REGISTRY/wax/wax-prosemirror/wax-demo
  BUILD_PATH: .

stages:
  - Build
  - Deploy

build demo:
  stage: Build
  image: docker:26
  services:
    - docker:26-dind
  before_script:
    - echo "$CI_REGISTRY_PASSWORD" | docker login "$CI_REGISTRY" -u "$CI_REGISTRY_USER" --password-stdin
  script:
    - docker pull $IMAGE_NAME_DEMO:latest || true
    - docker build
      --cache-from $IMAGE_NAME_DEMO:latest
      --tag $IMAGE_NAME_DEMO:$CI_COMMIT_SHA
      --tag $IMAGE_NAME_DEMO:latest
      -f $BUILD_PATH/Dockerfile-production
      $BUILD_PATH
    - docker push $IMAGE_NAME_DEMO:$CI_COMMIT_SHA
    - docker push $IMAGE_NAME_DEMO:latest
  only:
    - master

pages:
  stage: Deploy
  image: $IMAGE_NAME_DEPLOY
  script:
    - mv _build public
  artifacts:
    paths:
      - public
  only:
    - master

# .build demo image:
#   extends: .build production
#   stage: Build demo
#   variables:
#     IMAGE_NAME: $IMAGE_NAME_DEPLOY
#     BUILD_PATH: .
#   only:
#     - master

# .deploy demo:
#   extends: .deploy
#   stage: Deploy demo
#   only:
#     - master
