---
kind: pipeline
type: kubernetes
name: build

metadata:
  labels:
    pod-security.kubernetes.io/audit: privileged

services:
  - name: docker daemon
    image: docker:dind
    privileged: true
    environment:
      DOCKER_TLS_CERTDIR: ""
#    when:
#      event:
#        - tag
#        - promote

steps:
  - name: node.js build
    image: node:18
    commands:
      - npm add --global pnpm
      - pnpm i
      - rm -f ./node_modules/ngx-monaco-editor/lib/monaco.d.ts
      - sed -i '1d' ./node_modules/ngx-monaco-editor/lib/types.d.ts
      - ./node_modules/.bin/ionic build --prod
      - ./node_modules/.bin/ngsw-config ./www/ ./ngsw-config.json /i
      - echo -n $(npx uuid) | tee ./www/version.html
    environment:
      NODE_OPTIONS: --openssl-legacy-provider

  - name: container build
    image: docker:latest
    privileged: true
    commands:
      - "while ! docker stats --no-stream; do sleep 1; done"
      - docker image build -t $DOCKER_REGISTRY/noded/frontend .
      - docker push $DOCKER_REGISTRY/noded/frontend
    environment:
      DOCKER_HOST: tcp://localhost:2375
      DOCKER_REGISTRY:
        from_secret: DOCKER_REGISTRY
#    when:
#      event:
#        - tag
#        - promote

  - name: k8s rollout
    image: bitnami/kubectl:latest
    commands:
      - kubectl rollout restart -n noded deployment/noded-frontend
#    when:
#      event:
#        - tag
#        - promote
