apiVersion: workspace.devfile.io/v1alpha2
kind: DevWorkspaceTemplate
metadata:
  name: che-code-nodejs-mongodb
spec:
  commands:
    - id: init-container-command
      apply:
        component: che-code-injector
  events:
    preStart:
      - init-container-command
  components:
    - name: che-code-runtime-description
      container:
        image: registry.redhat.io/devspaces/udi-rhel8:3.5
        command:
          - /checode/entrypoint-volume.sh
        volumeMounts:
          - name: checode
            path: /checode
        memoryLimit: 1024Mi
        memoryRequest: 256Mi
        cpuLimit: 500m
        cpuRequest: 30m
        endpoints:
          - name: che-code
            attributes:
              type: main
              cookiesAuthEnabled: true
              discoverable: false
              urlRewriteSupported: true
            targetPort: 3100
            exposure: public
            secure: false
            protocol: https
          - name: code-redirect-1
            attributes:
              discoverable: false
              urlRewriteSupported: false
            targetPort: 13131
            exposure: public
            protocol: http
          - name: code-redirect-2
            attributes:
              discoverable: false
              urlRewriteSupported: false
            targetPort: 13132
            exposure: public
            protocol: http
          - name: code-redirect-3
            attributes:
              discoverable: false
              urlRewriteSupported: false
            targetPort: 13133
            exposure: public
            protocol: http
      attributes:
        app.kubernetes.io/component: che-code-runtime
        app.kubernetes.io/part-of: che-code.eclipse.org
        controller.devfile.io/container-contribution: true
    - name: checode
      volume: {}
    - name: che-code-injector
      container:
        image: registry.redhat.io/devspaces/code-rhel8:3.5
        command:
          - /entrypoint-init-container.sh
        volumeMounts:
          - name: checode
            path: /checode
        memoryLimit: 256Mi
        memoryRequest: 32Mi
        cpuLimit: 500m
        cpuRequest: 30m
---
apiVersion: workspace.devfile.io/v1alpha2
kind: DevWorkspace
metadata:
  name: nodejs-mongodb
spec:
  started: true
  template:
    components:
      - name: nodejs
        container:
          image: registry.redhat.io/devspaces/udi-rhel8:3.5
          env:
            - name: SECRET
              value: 220fd770-c028-480d-8f95-f84353c7d55a
            - name: NODE_ENV
              value: production
          endpoints:
            - exposure: public
              name: nodejs
              targetPort: 8080
          memoryLimit: 1G
          mountSources: true
          volumeMounts:
            - name: npm
              path: /home/user/.npm
        attributes:
          controller.devfile.io/merge-contribution: true
      - name: npm
        volume:
          size: 1G
      - name: mongo
        container:
          image: registry.redhat.io/rhscl/mongodb-36-rhel7:1-50
          env:
            - name: MONGODB_USER
              value: user
            - name: MONGODB_PASSWORD
              value: password
            - name: MONGODB_DATABASE
              value: guestbook
            - name: MONGODB_ADMIN_PASSWORD
              value: password
          endpoints:
            - name: mongodb
              exposure: internal
              targetPort: 27017
          memoryLimit: 512Mi
          mountSources: false
          volumeMounts:
            - name: mongo-storage
              path: /var/lib/mongodb/data
      - name: mongo-storage
        volume:
          size: 1G
    commands:
      - id: 1-run
        exec:
          label: Run the application
          component: nodejs
          workingDir: ${PROJECTS_ROOT}/nodejs-mongodb-sample
          commandLine: npm install && node --inspect=9229 app.js
          group:
            kind: run
    projects:
      - name: nodejs-mongodb-sample
        zip:
          location: '{{ INTERNAL_URL }}/resources/v2/nodejs-mongodb-sample.zip'
  contributions:
    - name: editor
      kubernetes:
        name: che-code-nodejs-mongodb
