-
Notifications
You must be signed in to change notification settings - Fork 118
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
feat: Update the NodeJS Dockerfilegenerator transformer and Dockerfile template to support multi-arch build #904
Conversation
Thanks for making a pull request! 😃 |
Codecov ReportBase: 15.30% // Head: 15.30% // No change to project coverage 👍
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. |
5462666
to
9354507
Compare
Hi @ashokponkumar ji, I have updated this PR to use 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. |
f962644
to
df34887
Compare
There was a problem hiding this 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] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"` |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is tag?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
2b73233
to
03df5e7
Compare
…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>
1314107
to
4733542
Compare
Signed-off-by: Akash Nayak akash19nayak@gmail.com