Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save PROJECT_SOURCE for containers mounting source #3979

Merged
merged 7 commits into from
Sep 24, 2020

Conversation

maysunfaisal
Copy link
Contributor

@maysunfaisal maysunfaisal commented Sep 17, 2020

Signed-off-by: Maysun J Faisal maysunaneek@gmail.com

/kind feature

What does does this PR do / why we need it:

  • Introduces an env, PROJECT_SOURCE to all component containers that mount sources
  • devfile can now use PROJECT_SOURCE which holds the project path in a container
  • PROJECT_SOURCE value depends upon container's sourceMapping & project's clonePath
  • Updated GetSyncFolder() logic for devfile containing more than one project ie; the first project is now selected
  • New and updated tests
  • Updated public docs about env
  • PROJECTS_ROOT & PROJECT_SOURCE are reserved, check Should PROJECTS_ROOT and PROJECT_SOURCE be reserved environment variables? devfile/api#132

Which issue(s) this PR fixes:

Fixes #3781

PR acceptance criteria:

How to test changes / Special notes to the reviewer:

  • push odo component by varying number of projects, project's clonePath and container's sourceMapping
  • PROJECT_SOURCE cannot be explicitly mentioned in the devfile
schemaVersion: 2.0.0
metadata:
  name: java-springboot
  version: 1.1.0
# projects:
#   - name: myproj1
#     # clonePath: myapp1/
#     git:
#       remotes:
#         origin: https://github.com/odo-devfiles/springboot-ex
#   - name: myproj2
#     clonePath: myapp2/
#     git:
#       remotes:
#         origin: https://github.com/odo-devfiles/springboot-ex
starterProjects:
- name: springbootproject
  git:
    remotes:
      origin: https://github.com/odo-devfiles/springboot-ex.git
components:
- name: tools
  container:
    endpoints:
    - name: 8080-tcp
      targetPort: 8080
    - exposure: public
      path: /
      name: myjava
      targetPort: 8080
      protocol: http
    image: quay.io/eclipse/che-java11-maven:nightly
    memoryLimit: 768Mi
    mountSources: true
    volumeMounts:
    - name: m2
      path: /home/user/.m2
    # env:
    # - name: PROJECTS_ROOT
    #   value: /mycustom/path/
- name: dummy
  container:
    image: quay.io/eclipse/che-java11-maven:nightly
    memoryLimit: 768Mi
    mountSources: true
    sourceMapping: /test
    command: ['tail']
    args: [ '-f', '/dev/null']
    # env:
    # - name: PROJECT_SOURCE
    #   value: /mycustom/path/
- name: m2
  volume:
    size: 3Gi
commands:
- exec:
    commandLine: mvn clean -Dmaven.repo.local=/home/user/.m2/repository package -Dmaven.test.skip=true
    workingDir: ${PROJECT_SOURCE}
    component: tools
    group:
      isDefault: true
      kind: build
  id: build
- exec:
    commandLine: mvn -Dmaven.repo.local=/home/user/.m2/repository spring-boot:run
    workingDir: ${PROJECT_SOURCE}
    component: tools
    group:
      isDefault: true
      kind: run
  id: run
- exec:
    commandLine: java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=${DEBUG_PORT},suspend=n -jar target/*.jar
    component: tools
    group:
      isDefault: true
      kind: debug
  id: debug

@openshift-ci-robot openshift-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. Required by Prow. kind/feature Categorizes issue as a feature request. For PRs, that means that the PR is the implementation labels Sep 17, 2020
@openshift-ci-robot
Copy link
Collaborator

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@codecov
Copy link

codecov bot commented Sep 18, 2020

Codecov Report

Merging #3979 into master will increase coverage by 0.11%.
The diff coverage is 88.46%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3979      +/-   ##
==========================================
+ Coverage   43.17%   43.29%   +0.11%     
==========================================
  Files         146      147       +1     
  Lines       12338    12411      +73     
==========================================
+ Hits         5327     5373      +46     
- Misses       6445     6470      +25     
- Partials      566      568       +2     
Impacted Files Coverage Δ
pkg/devfile/adapters/common/utils.go 94.23% <ø> (ø)
pkg/testingutil/devfile.go 0.00% <0.00%> (ø)
pkg/devfile/adapters/kubernetes/utils/utils.go 80.66% <86.66%> (+21.34%) ⬆️
pkg/devfile/validate/components.go 93.10% <100.00%> (+1.10%) ⬆️
pkg/devfile/validate/errors.go 43.75% <100.00%> (+3.75%) ⬆️
pkg/sync/adapter.go 76.64% <100.00%> (ø)
pkg/component/component.go 21.48% <0.00%> (-1.22%) ⬇️
pkg/envinfo/envinfo.go 41.54% <0.00%> (-0.30%) ⬇️
pkg/component/pushed_component.go 47.36% <0.00%> (ø)
pkg/devfile/parser/representation.go
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b3c126d...a35bc65. Read the comment docs.

@maysunfaisal maysunfaisal marked this pull request as ready for review September 21, 2020 17:50
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. Required by Prow. label Sep 21, 2020
@maysunfaisal
Copy link
Contributor Author

@adisky @johnmcollier Could you pls help review the PR? thx!

Value: syncFolder,
})
} else {
return nil, fmt.Errorf("env variable %s is reserved and cannot be customized in component %s", adaptersCommon.EnvProjectsSrc, comp.Name)
Copy link
Member

@johnmcollier johnmcollier Sep 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I thought about this. But I was wondering if for some reason, devfile parse validation changes in the future and it removed the env check; then we'd somehow allow this when creating a container. So put it as double fail safe. I know its redundant but i can remove it, if you feel strongly

Copy link
Member

@johnmcollier johnmcollier Sep 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, we just need the one check for now to avoid having duplicate code (and code that won't get triggered currently), and if anyone overhauls the validation code in the future, it's their responsibility to make sure the check for PROJECT_SOURCE still occurs

But I'm totally flexible either way, TBH. I can see where you're coming from.

Copy link
Contributor Author

@maysunfaisal maysunfaisal Sep 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With devfile parser being extracted out soon, would we want to validate this at the parser level or push level? 🤔

Copy link
Member

@johnmcollier johnmcollier Sep 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the parser level in my opinion, so the validation should be kept there as well.

Modifying PROJECT_SOURCE isn't valid at the devfile spec level, so it makes sense to have the check there

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened devfile/api#132 for discussion too, FYI.

Your point about moving out the devfile parser reminded me that we don't really have anything in the spec right now that says PROJECT_SOURCE can't be overridden.

Signed-off-by: Maysun J Faisal <maysunaneek@gmail.com>
Signed-off-by: Maysun J Faisal <maysunaneek@gmail.com>
Signed-off-by: Maysun J Faisal <maysunaneek@gmail.com>
Signed-off-by: Maysun J Faisal <maysunaneek@gmail.com>
Signed-off-by: Maysun J Faisal <maysunaneek@gmail.com>
Signed-off-by: Maysun J Faisal <maysunaneek@gmail.com>
Signed-off-by: Maysun J Faisal <maysunaneek@gmail.com>
@maysunfaisal
Copy link
Contributor Author

/retest

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Sep 23, 2020
Copy link
Contributor

@adisky adisky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maysunfaisal Tried it out working well, code wise also looks good.
/lgtm

@girishramnani
Copy link
Contributor

/approve

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: girishramnani

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. Required by Prow. label Sep 23, 2020
@openshift-merge-robot openshift-merge-robot merged commit 4ad9ce3 into redhat-developer:master Sep 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. Required by Prow. kind/feature Categorizes issue as a feature request. For PRs, that means that the PR is the implementation lgtm Indicates that a PR is ready to be merged. Required by Prow.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

$PROJECT_SOURCE env variable
6 participants