Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

feat: add an attribute with starterProject to the devworkspace #786

Merged
merged 4 commits into from
Sep 20, 2023

Conversation

svor
Copy link
Contributor

@svor svor commented Sep 19, 2023

What does this PR do?

Add a logic to analyze a original devfile if it contains a section with starterProjects into devworkspace generator tool. If it contains, we add controller.devfile.io/use-starter-project attribute with value that describes the name of the project:

spec:
  template:
    attributes:
      controller.devfile.io/use-starter-project: name-of-the-project

After applying generated devworkspace the project should be cloned into the workspace and should be available in the Project tree.

An example of the generated devworkspace:

Original devfile:
schemaVersion: 2.1.0
metadata:
  name: nodejs-svelte
  displayName: Svelte
  description: "Svelte is a radical new approach to building user interfaces.
    Whereas traditional frameworks like React and Vue do the bulk of their work in the browser, Svelte shifts that work into a compile step that happens when you build your app."
  icon: https://raw.githubusercontent.com/devfile-samples/devfile-stack-icons/main/svelte.svg
  tags:
    - Node.js
    - Svelte
  projectType: Svelte
  language: TypeScript
  provider: Red Hat
  version: 1.0.3
starterProjects:
  - name: nodejs-svelte-starter
    git:
      checkoutFrom:
        revision: main
      remotes:
        origin: https://github.com/devfile-samples/devfile-stack-nodejs-svelte.git
components:
  - container:
      endpoints:
        - name: http-svelte
          targetPort: 3000
      image: registry.access.redhat.com/ubi8/nodejs-16:1-105.1684740145
      args: ['tail', '-f', '/dev/null']
      memoryLimit: 1024Mi
    name: runtime
commands:
  - exec:
      commandLine: npm install
      component: runtime
      group:
        isDefault: true
        kind: build
      workingDir: ${PROJECT_SOURCE}
    id: install
  - exec:
      commandLine: npm run dev
      component: runtime
      group:
        isDefault: true
        kind: run
      workingDir: ${PROJECT_SOURCE}
    id: run
Resulted devworkspace:
apiVersion: workspace.devfile.io/v1alpha2
kind: DevWorkspaceTemplate
metadata:
  name: che-code-nodejs-svelte
spec:
  commands:
    - id: init-container-command
      apply:
        component: che-code-injector
    - id: init-che-code-command
      exec:
        component: che-code-runtime-description
        commandLine: >-
          nohup /checode/entrypoint-volume.sh > /checode/entrypoint-logs.txt
          2>&1 &
  events:
    preStart:
      - init-container-command
    postStart:
      - init-che-code-command
  components:
    - name: che-code-runtime-description
      container:
        image: >-
          quay.io/devfile/universal-developer-image@sha256:1158f026aa2231cf451ecfdca817ecda7f0e9b18db766195c3f0a4de08494a47
        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: >-
          quay.io/che-incubator/che-code@sha256:857079b48678762a3cf5afe22694e634c98d6d3b58148436b88945938d5d24e5
        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-svelte
  annotations:
    che.eclipse.org/devfile: |
      schemaVersion: 2.1.0
      metadata:
        name: nodejs-svelte
        displayName: Svelte
        description: >-
          Svelte is a radical new approach to building user interfaces. Whereas
          traditional frameworks like React and Vue do the bulk of their work in the
          browser, Svelte shifts that work into a compile step that happens when you
          build your app.
        icon: >-
          https://raw.githubusercontent.com/devfile-samples/devfile-stack-icons/main/svelte.svg
        tags:
          - Node.js
          - Svelte
        projectType: Svelte
        language: TypeScript
        provider: Red Hat
        version: 1.0.3
      starterProjects:
        - name: nodejs-svelte-starter
          git:
            checkoutFrom:
              revision: main
            remotes:
              origin: https://github.com/devfile-samples/devfile-stack-nodejs-svelte.git
      components:
        - container:
            endpoints:
              - name: http-svelte
                targetPort: 3000
            image: registry.access.redhat.com/ubi8/nodejs-16:1-105.1684740145
            args:
              - tail
              - '-f'
              - /dev/null
            memoryLimit: 1024Mi
          name: runtime
      commands:
        - exec:
            commandLine: npm install
            component: runtime
            group:
              isDefault: true
              kind: build
            workingDir: ${PROJECT_SOURCE}
          id: install
        - exec:
            commandLine: npm run dev
            component: runtime
            group:
              isDefault: true
              kind: run
            workingDir: ${PROJECT_SOURCE}
          id: run
spec:
  started: true
  routingClass: che
  template:
    starterProjects:
      - name: nodejs-svelte-starter
        git:
          checkoutFrom:
            revision: main
          remotes:
            origin: https://github.com/devfile-samples/devfile-stack-nodejs-svelte.git
    components:
      - container:
          endpoints:
            - name: http-svelte
              targetPort: 3000
          image: registry.access.redhat.com/ubi8/nodejs-16:1-105.1684740145
          args:
            - tail
            - '-f'
            - /dev/null
          memoryLimit: 1024Mi
        name: runtime
    commands:
      - exec:
          commandLine: npm install
          component: runtime
          group:
            isDefault: true
            kind: build
          workingDir: ${PROJECT_SOURCE}
        id: install
      - exec:
          commandLine: npm run dev
          component: runtime
          group:
            isDefault: true
            kind: run
          workingDir: ${PROJECT_SOURCE}
        id: run
    attributes:
      controller.devfile.io/use-starter-project: nodejs-svelte-starter
  contributions:
    - name: editor
      kubernetes:
        name: che-code-nodejs-svelte

Screenshot/screencast of this PR

screenshot-eclipse-che apps rosa qp5ra-b5547-2tx gkpc p3 openshiftapps com-2023 09 19-16_46_01

What issues does this PR fix or reference?

eclipse-che/che#22486

How to test this PR?

To test that the generated devworkspace is applicable, use the resulted devworkspace from the description and create a workspace by using oc apply -f <path to the devworkspace>

Or you can generate your own. To do that:

  1. Build the generator tool with current changes
  2. Go to che-devfile-registry/tools/devworkspace-generator and run
node lib/entrypoint.js \         
        --devfile-path:path-to-original-devfile \
        --plugin-registry-url:https://che-plugin-registry-main.surge.sh/v3/ \
        --editor-entry:che-incubator/che-code/latest \
        --output-file:/tmp/devworkspace-che-code-latest.yaml
  1. Use oc apply -f /tmp/devworkspace-che-code-latest.yaml to create a workspace
  2. Check that the workspace is started and the sample is present in the Project tree.

PR Checklist

As the author of this Pull Request I made sure that:

Reviewers

Reviewers, please comment how you tested the PR when approving it.

@svor svor requested a review from olexii4 September 19, 2023 14:39
@svor svor requested a review from vinokurig as a code owner September 19, 2023 14:39
@svor svor self-assigned this Sep 19, 2023
@svor svor requested a review from ibuziuk as a code owner September 19, 2023 14:39
@github-actions
Copy link

Click here to review and test in web IDE: Contribute

Signed-off-by: Valeriy Svydenko <[email protected]>
Signed-off-by: Valeriy Svydenko <[email protected]>
@svor svor merged commit bbd66d3 into main Sep 20, 2023
@svor svor deleted the sv-starterProject branch September 20, 2023 10:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants