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

feat: Update the NodeJS Dockerfilegenerator transformer and Dockerfile template to support multi-arch build #904

Merged
merged 5 commits into from
Nov 28, 2022

Conversation

Akash-Nayak
Copy link
Contributor

Signed-off-by: Akash Nayak akash19nayak@gmail.com

@github-actions
Copy link

Thanks for making a pull request! 😃
One of the maintainers will review and advise on the next steps.

@github-actions github-actions bot added the feat label Oct 21, 2022
@codecov
Copy link

codecov bot commented Oct 21, 2022

Codecov Report

Base: 15.30% // Head: 15.30% // No change to project coverage 👍

Coverage data is based on head (4733542) compared to base (9e1e10e).
Patch has no changes to coverable lines.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #904   +/-   ##
=======================================
  Coverage   15.30%   15.30%           
=======================================
  Files          50       50           
  Lines        4568     4568           
=======================================
  Hits          699      699           
  Misses       3696     3696           
  Partials      173      173           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@Akash-Nayak Akash-Nayak force-pushed the update-nodejs-transformer branch 3 times, most recently from 5462666 to 9354507 Compare November 9, 2022 06:39
@Akash-Nayak
Copy link
Contributor Author

Hi @ashokponkumar ji, I have updated this PR to use ubi8/nodejs image in the Dockerfile template for NodeJS and also build the image and tested the deployment on OpenShift cluster.

New Dockerfile generated by Move2Kube.

FROM registry.access.redhat.com/ubi8/nodejs-14
COPY . .
RUN npm install
RUN npm run build
USER root
RUN chown -R 1001:0 /opt/app-root/src/.npm
RUN chmod -R 775 /opt/app-root/src/.npm
USER 1001
EXPOSE 8080
CMD npm run start

Currently, I have not removed the image-tag logic that I added, and I have commented it out in case if we want to switch to docker hub Node image in future.

@Akash-Nayak Akash-Nayak force-pushed the update-nodejs-transformer branch 2 times, most recently from f962644 to df34887 Compare November 11, 2022 07:51
Copy link
Member

@ashokponkumar ashokponkumar left a comment

Choose a reason for hiding this comment

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

Nice work. Few comments.

@@ -135,8 +140,16 @@ func (t *NodejsDockerfileGenerator) Init(tc transformertypes.Transformer, env *e
t.Spec = spec
if t.NodejsConfig.DefaultNodejsVersion == "" {
t.NodejsConfig.DefaultNodejsVersion = t.Spec.NodeVersions[0][versionKey]
Copy link
Member

Choose a reason for hiding this comment

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

We might want to check if the Len of nodeversions is not 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

DefaultNodejsVersion string `yaml:"defaultNodejsVersion"`
// DefaultNodejsTag string `yaml:"defaultNodejsTag"`
DefaultPackageManager string `yaml:"defaultPackageManager"`
NodejsVersionTagMapping map[string]string `yaml:"nodejsVersionTagMapping"`
Copy link
Member

Choose a reason for hiding this comment

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

Aren't we taking this as a config file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have removed this.

}

const (
packageJSONFile = "package.json"
versionMappingFilePath = "mappings/nodeversions.yaml"
defaultPackageManager = "npm"
versionKey = "version"
// tagKey = "tag"
Copy link
Member

Choose a reason for hiding this comment

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

what is tag?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the image tag which can be used in the Dockerfile, for example- FROM node:14.20.0-alpine. https://github.com/Akash-Nayak/move2kube/blob/13141078de0de81e2c705d85b31f162d06772933/assets/built-in/transformers/dockerfilegenerator/mappings/nodeversions.yaml#L10

The image tag is currently unused as we have moved to the ubi-8/node image, but if we want to revert back to node image from docker hub then it will be just required to uncomment this line https://github.com/Akash-Nayak/move2kube/blob/13141078de0de81e2c705d85b31f162d06772933/transformer/dockerfilegenerator/nodejsdockerfiletransformer.go#L262

mv node-{{ .NodeVersion }}-linux-x64 /node && \
rm -f node-{{ .NodeVersion }}-linux-x64.tar.xz
ENV PATH="$PATH:/node/bin"
FROM registry.access.redhat.com/ubi8/nodejs-{{ .NodeMajorVersion }}
COPY . .
RUN {{ .PackageManager }} install
Copy link
Member

Choose a reason for hiding this comment

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

Does the image have both npm and yarn?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The ubi8/nodejs-{version} base image only has npm and doesn't have yarn. Earlier in the ubi8-minimal image, we were downloading node but not installing yarn. So, I have added the command to install yarn if the PackageManager is yarn. https://github.com/Akash-Nayak/move2kube/blob/03df5e77bd6734eb18dfd6645b3c108549655203/assets/built-in/transformers/dockerfilegenerator/nodejs/templates/Dockerfile#L18

Port: port,
NodeVersion: nodeVersion,
// NodeTag: nodeTag,
NodeMajorVersion: strings.TrimPrefix(semver.Major(nodeVersion), "v"),
Copy link
Member

Choose a reason for hiding this comment

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

We might not have all the node versions in the images, isn't it? So we might want to have a list of versions that are present and go to the nearest that fits the version criteria.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, currently there are 4 node versions in the ubi8/node images (10, 12, 14 and 16) that can be pulled.

docker run --rm -it -p 8080:8080 registry.access.redhat.com/ubi8/nodejs-10 bash
bash-4.4$ node -v
v10.24.0
docker run --rm -it -p 8080:8080 registry.access.redhat.com/ubi8/nodejs-12 bash
bash-4.4$ node -v
v12.22.5
docker run --rm -it -p 8080:8080 registry.access.redhat.com/ubi8/nodejs-14 bash
bash-4.4$ node -v
v14.20.1
docker run --rm -it -p 8080:8080 registry.access.redhat.com/ubi8/nodejs-16 bash
bash-4.4$ node -v
v16.17.1

We have the updated list of available versions here- https://github.com/Akash-Nayak/move2kube/blob/13141078de0de81e2c705d85b31f162d06772933/assets/built-in/transformers/dockerfilegenerator/mappings/nodeversions.yaml#L6 and we select the node version that fits the version criteria here https://github.com/Akash-Nayak/move2kube/blob/03df5e77bd6734eb18dfd6645b3c108549655203/transformer/dockerfilegenerator/nodejsdockerfiletransformer.go#L222.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The node version selection heuristic was added in the PR #834 and we are still using the same heuristic for selecting the nearest node version that fits the version constraint if it's there in the package.json.

@Akash-Nayak Akash-Nayak force-pushed the update-nodejs-transformer branch from 2b73233 to 03df5e7 Compare November 16, 2022 11:10
…lti-arch build

Signed-off-by: Akash Nayak <akash19nayak@gmail.com>
…port multi-arch build

Signed-off-by: Akash Nayak <akash19nayak@gmail.com>
… to support multi-arch build

Signed-off-by: Akash Nayak <akash19nayak@gmail.com>
…sformer to support multi-arch build

Signed-off-by: Akash Nayak <akash19nayak@gmail.com>
… used in the ubi8/node images

Signed-off-by: Akash Nayak <akash19nayak@gmail.com>
@Akash-Nayak Akash-Nayak force-pushed the update-nodejs-transformer branch from 1314107 to 4733542 Compare November 22, 2022 06:21
@ashokponkumar ashokponkumar merged commit ae2b33c into konveyor:main Nov 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants