develop:npm:
  image: harbor.vimpelcom.ru/dockerhub/library/node:lts
  stage: build
  cache:
    - key:
        files:
          - package.json
      paths:
        - node_modules/
  rules:
    - !reference [.build-npm-rules, rules]
  variables:
    PRODUCT: "$PRODUCT_PROD"
  script:
    - export PRODUCT_VERSION=$(node -p "require('./package.json').version")
    - echo PRODUCT_VERSION="$PRODUCT_VERSION" >> .env
    - echo PRODUCT="$PRODUCT_PROD" >> .env
    - npm install
    - npm run build
    - export VITE_NEW_VERSION="true"
    - echo "$DMZ_DIST_DIR"
    - ./node_modules/.bin/vitepress build src --outDir "$DMZ_DIST_DIR"
  artifacts:
    paths:
      - "$DIST_DIR"
      - "$DMZ_DIST_DIR"
    reports:
      dotenv: .env
    expire_in: 1h

build-image-npm:
  image: harbor.vimpelcom.ru/dockerhub/library/docker:20.10.11-dind
  stage: package
  rules:
    - !reference [.build-npm-rules, rules]
  before_script:
    - cat /certs/ca.crt >> /etc/ssl/certs/ca-certificates.crt 
    - echo PRODUCT="$PRODUCT" >> .env
    - echo PRODUCT_VERSION="$PRODUCT_VERSION" >> .env
    - echo "$HARBOR_SECRET" | docker login ${CONTAINER_REGISTRY} --username $HARBOR_USER --password-stdin
  script:
    - docker build --build-arg DIST_DIR=${DIST_DIR} -f ./build.Dockerfile -t ${CONTAINER_REGISTRY}/${PRODUCT}/${IMAGE_NAME}:$PRODUCT_VERSION -t ${CONTAINER_REGISTRY}/${PRODUCT}/${IMAGE_NAME}:latest .
    - docker push ${CONTAINER_REGISTRY}/${PRODUCT}/${IMAGE_NAME}:$PRODUCT_VERSION
    - docker push ${CONTAINER_REGISTRY}/${PRODUCT}/${IMAGE_NAME}:latest
    - docker build --build-arg DIST_DIR=${DMZ_DIST_DIR} --build-arg WROOT_DIR="/usr/share/nginx/html" -f ./build.Dockerfile -t ${CONTAINER_REGISTRY}/${PRODUCT_DMZ}/${IMAGE_NAME}:$PRODUCT_VERSION -t ${CONTAINER_REGISTRY}/${PRODUCT_DMZ}/${IMAGE_NAME}:latest .
    - docker push ${CONTAINER_REGISTRY}/${PRODUCT_DMZ}/${IMAGE_NAME}:$PRODUCT_VERSION
    - docker push ${CONTAINER_REGISTRY}/${PRODUCT_DMZ}/${IMAGE_NAME}:latest
  needs:
    - job: develop:npm
      artifacts: true
      optional: true
  artifacts:
    # Передача env без импорта с помощью source
    reports:
      dotenv: .env
