-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add node version selection heuristic to handle conditional Node…
….JS version in package.json (#834) * feat: Add node version selection heuristic to handle conditional Node.JS version in package.json Signed-off-by: Akash Nayak <[email protected]> Co-authored-by: Harikrishnan Balagopal <[email protected]>
- Loading branch information
1 parent
607d042
commit be8685d
Showing
9 changed files
with
115 additions
and
21 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
assets/built-in/transformers/dockerfilegenerator/mappings/nodeversions.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
apiVersion: move2kube.konveyor.io/v1alpha1 | ||
kind: NodeVersionsMapping | ||
metadata: | ||
name: NodeVersionsMapping | ||
spec: | ||
nodeVersions: | ||
- "v16.16.0" | ||
- "v14.20.0" | ||
- "v12.22.12" | ||
- "v10.24.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright IBM Corporation 2021 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dockerfilegenerator | ||
|
||
import ( | ||
"github.com/hashicorp/go-version" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// getNodeVersion returns the Node version to be used for the service | ||
func getNodeVersion(versionConstraint, defaultNodejsVersion string, supportedVersions []string) string { | ||
v1, err := version.NewVersion(versionConstraint) | ||
if err == nil { | ||
logrus.Debugf("the constraint is a Node version: %#v", v1) | ||
return "v" + v1.String() | ||
} | ||
constraints, err := version.NewConstraint(versionConstraint) | ||
if err != nil { | ||
logrus.Errorf("failed to parse the Node version constraint string. Error: %q Actual: %s", err, versionConstraint) | ||
return defaultNodejsVersion | ||
} | ||
logrus.Debugf("Node version constraints len = %d; constraints = %#v", constraints.Len(), constraints.String()) | ||
for _, supportedVersion := range supportedVersions { | ||
ver, _ := version.NewVersion(supportedVersion) | ||
if constraints.Check(ver) { | ||
logrus.Debugf("%#v satisfies constraints %#v\n", ver, constraints) | ||
return supportedVersion | ||
} | ||
} | ||
logrus.Infof("no supported Node version detected in package.json. Selecting default Node version- %s", defaultNodejsVersion) | ||
return defaultNodejsVersion | ||
} |