|
| 1 | +# Console Import from Devfile |
| 2 | + |
| 3 | +This document outlines how the console is going to use a devfile 2.0.0 spec for it's import feature targeted for the upcoming release. |
| 4 | + |
| 5 | +## Dev Preview POC |
| 6 | + |
| 7 | +The Devfile import feature was mocked with a POC [openshift/console PR](https://github.com/openshift/console/pull/6321). The POC PR, required the build guidance devfile spec to be implemented. However, the build guidance spec is still an open discussion in the [devfile/api PR](https://github.com/devfile/api/pull/127). |
| 8 | + |
| 9 | +With an initial target date for the Dec 04, 2020; the devfile import developer preview should look similar to this [demo video](https://drive.google.com/file/d/1uLzDibVZlkMqbjtKkho04e8k2-Ns5A2W/view). |
| 10 | + |
| 11 | +## Required Data |
| 12 | + |
| 13 | +The information required to build a component from devfile are: |
| 14 | +- Git Repo Url |
| 15 | +- Git Repo Ref |
| 16 | +- Devfile Context Dir |
| 17 | +- Docker Build Context Dir |
| 18 | +- Dockerfile Location |
| 19 | +- Container Port |
| 20 | +- Image Name |
| 21 | + |
| 22 | +The console devfile import page has the Git Repo Url, Git Repo Ref & the Devfile Context Dir. |
| 23 | + |
| 24 | +<img src="https://user-images.githubusercontent.com/31771087/99319303-4ae89180-2837-11eb-8933-eaaf41160bcd.png"> |
| 25 | + |
| 26 | +There are two context directories info required. The `Devfile Context Dir` present in the Console form is used to find the devfile.yaml in a repository. The `Docker Build Context Dir` present in the devfile.yaml is used to establish a context dir for Docker builds relative to the devfile.yaml. |
| 27 | + |
| 28 | + For phase 1, only the Dockerfile Build Guidance is to be implemented. SourceToImage(S2I) will be implemented in the future sprints. |
| 29 | + |
| 30 | +<img src="https://user-images.githubusercontent.com/31771087/99319306-4c19be80-2837-11eb-9639-a5c130deb4ba.png"> |
| 31 | + |
| 32 | +With the target deadline approaching soon, we may need to provide an alternative path for the OpenShift Console to consume the devfile. With the Build Guidance spec [devfile/api PR](https://github.com/devfile/api/pull/127) still an open discussion, this document proposes a solution within the boundaries of the devfile 2.0.0 spec to achieve this. |
| 33 | + |
| 34 | +## Proposed Changes |
| 35 | + |
| 36 | +Here is a proposed 2.0.0 spec devfile that can support devfile build guidance for OpenShift Console: |
| 37 | + |
| 38 | +```yaml |
| 39 | +schemaVersion: 2.0.0 |
| 40 | +metadata: |
| 41 | + name: nodejs |
| 42 | + version: 1.0.0 |
| 43 | + attributes: |
| 44 | + alpha.build-context: mydir # key:value pair that establishes the context dir for Docker builds relative to devfile.yaml |
| 45 | + alpha.build-dockerfile: Dockerfile # key:value pair that specifies the location of the Dockerfile relative to alpha.build-context |
| 46 | +components: |
| 47 | + - name: runtime |
| 48 | + attributes: |
| 49 | + tool: console-import # key:value pair used to filter container type component that only the Console Devfile Import is interested in |
| 50 | + container: |
| 51 | + image: imageplaceholder # image which will be used by the buildConfig output but not supported for Dev Preview, defaults to Console's application name |
| 52 | + memoryLimit: 1024Mi |
| 53 | + endpoints: |
| 54 | + - name: http-3000 |
| 55 | + targetPort: 3000 # define endpoints in devfile.yaml, that will be used for the devfile service |
| 56 | + - name: runtime2 # other components ignored by the Console Devfile Import |
| 57 | + container: |
| 58 | + image: registry.access.redhat.com/ubi8/nodejs-12:1-45 |
| 59 | + memoryLimit: 1024Mi |
| 60 | + mountSources: true |
| 61 | + sourceMapping: /project |
| 62 | + endpoints: |
| 63 | + - name: http-3000 |
| 64 | + targetPort: 3000 |
| 65 | +commands: |
| 66 | + - id: install |
| 67 | + exec: |
| 68 | + component: runtime2 |
| 69 | + commandLine: npm install |
| 70 | + workingDir: /project |
| 71 | + group: |
| 72 | + kind: build |
| 73 | + isDefault: true |
| 74 | + - id: run |
| 75 | + exec: |
| 76 | + component: runtime2 |
| 77 | + commandLine: npm start |
| 78 | + workingDir: /project |
| 79 | + group: |
| 80 | + kind: run |
| 81 | + isDefault: true |
| 82 | +``` |
| 83 | +
|
| 84 | +Without the build guidance devfile spec, the proposed change here is to mention the docker build context and the dockerfile location in the metadata attribute. The attributes is a free form key-value pair and in the above example, `alpha.build-context` & `alpha.build-dockerfile` are used for the values; which would have otherwise been specified by the Dockerfile Build Guidance spec. |
| 85 | + |
| 86 | +To allow the Console to filter only devfile component containers, we use a `tool: console-import` key value pair attribute in the container component. Any other components in the devfile are ignored by the Console. |
| 87 | + |
| 88 | +Asides the devfile change, the Dev Preview would need to be updated to use the above devfile's image in the future. |
| 89 | + |
| 90 | +Console's devfile import Dev Preview is using a `BuildConfig` to build the Dockerfile from the dockerfile path location and build context directory. The `BuildConfig` outputs it to an `ImageStreamTag`. However, for the Dev Preview it assumes the `ImageStream` and `ImageStreamTag` are all the same name as the application name. This is tightly coupled and dependant on the information entered in the Console Devfile Import form and thus does not allow us to mention a custom image name in the devfile. |
| 91 | + |
| 92 | +If we want to decouple `ImageStream` and `ImageStreamTag` from the application name, so that a custom image name can be specified in the devfile's component container; then we would need to update the following information: |
| 93 | +1. `pkg/server/devfile-handler.go` |
| 94 | + - image stream name |
| 95 | + - build config output image stream tag |
| 96 | + - deployment's container image |
| 97 | +2. `frontend/packages/dev-console/src/components/import/import-submit-utils.ts` |
| 98 | + - the annotation mapping for the `ImageStreamTag` in `getTriggerAnnotation()` |
| 99 | + |
| 100 | +This allows us to use the image name from devfile.yaml rather than always using the application name. |
| 101 | + |
| 102 | +These devfile information would be parsed and returned by the library and thus ensuring a consistent UX. |
| 103 | + |
| 104 | +### Note: |
| 105 | +The above devfile proposal and POC PR assumes the `BuildConfig` outputs the build to an `ImageStreamTag` which is used by the OpenShift internal registry. To push the image to a non-OpenShift Image Registry, the `BuiidConfig` output can pushed to a private or Dockerhub registry using `DockerImage`. OpenShift [doc](https://docs.openshift.com/container-platform/4.6/builds/managing-build-output.html) outlines how this can be achieved via a `BuildConfig`. Pushing to a private registry requires secret configuration from the Docker config, and this OpenShift [doc](https://docs.openshift.com/container-platform/3.11/dev_guide/builds/build_inputs.html#using-docker-credentials-for-private-registries) explains how to achieve it. |
| 106 | + |
| 107 | +For phase 1, only the `ImageStreamTag` is to be implemented in the `BuildConfig`, `DockerImage` is to be implemented in the future sprints. |
0 commit comments