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

Add hint to keep version of node and meteor flexible #30

Closed
SimonSimCity opened this issue Feb 6, 2020 · 3 comments
Closed

Add hint to keep version of node and meteor flexible #30

SimonSimCity opened this issue Feb 6, 2020 · 3 comments

Comments

@SimonSimCity
Copy link

SimonSimCity commented Feb 6, 2020

I am now planning on moving my own build script to using this package as multi stage build, and I found a neat trick in my script which might be cool to share to the users of this script.

When running my script, I have a docker-variable for the name of the base-image, which is filled with the value used in my current environment. Let me put this into an example.

In the environment of my project, I have a clear reference what version of meteor and nodejs I'm using.

A call of meteor node --version | cut -c2-99 reveals the version of nodejs and meteor --version | cut -c8-99 reveals the version of meteor.

So why not propose to start the build-script with:

ARG  METEOR_VERSION
ARG  NODE_VERSION

FROM geoffreybooth/meteor-base:${METEOR_VERSION}

[...]

FROM node:${NODE_VERSION}-alpine

[...]

And call docker build --build-arg NODE_VERSION=$(meteor node --version | cut -c2-99) --build-arg METEOR_VERSION=$(meteor --version | cut -c8-99) and use them in the multi stage build script? It's just a very neat trick, I think, people should get to know of.

But I sadly have to drop it since I cannot get a docker-build argument being passed on by another build-step. This means I cannot have a docker file which you just run and it will figure all this out 😢 Maybe it helps someone leaving it as a hint.

EDIT: Fixed the example of a Dockerfile file according to moby/moby#37345 (comment). Variables which I want to have available in all steps must be declared before the first FROM definition.

@GeoffreyBooth
Copy link
Collaborator

So https://github.com/disney/meteor-base/blob/master/src/Dockerfile already has ARG METEOR_VERSION. It doesn’t need NODE_VERSION because that’s set by when Meteor is installed.

Therefore I assume you’re talking about https://github.com/disney/meteor-base/blob/master/example/default.dockerfile, which is meant as example boilerplate for users to use in their own projects. So sure, we can at least put a comment in this file along the lines of “if you don’t want to hard-code the Meteor version, uncomment the next line”. I would be hesitant to make the ARG lines the default in the example, because that adds complexity in users needing to create a shell script or the like to kick off their building; I was trying to keep the build command as a simple docker-compose up. We could add the ARG lines and just have the argument values set in docker-compose.yml, but that just moves the hard-coding to another place.

So at the very least I’m fine with adding a comment and/or a note in the README, and I’m open to discussing any ways to further automate this; but I want to avoid users needing to use scripts to build, because that adds complexity and makes us need to figure out how to make that cross-platform (since I don’t want to exclude Windows users). Also something else to be aware of is that the example Dockerfile does change between Meteor versions; I’ve submitted PRs to node-fibers to make Fibers much more compatible with Alpine (it previously didn’t include an Alpine-compatible binary, and now it does) but the versions of Meteor using older node-fibers from before my PRs needs a lot more dependencies in the example Dockerfile in order to compile Fibers during the build.

@SimonSimCity
Copy link
Author

Yes, adding a comment to the sample is all I'm asking for here. It's just to show the possibility.

Well ... I now also have to move away from it because I want to use docker hub and automated builds there and I haven't found a way to support it. But it could be a nice tweak for others, so I thought it would be good to mention it.

@SimonSimCity
Copy link
Author

SimonSimCity commented Feb 9, 2020

I've just written a build-script which allows you to 1. not use a lot of additional resources and 2. take the version numbers from the project itself. Here it is:

#!/bin/bash

METEOR_VERSION=$(cat ./.meteor/release | cut -c8-99)
NODE_VERSION=$(docker run --rm geoffreybooth/meteor-base:${METEOR_VERSION} meteor node --version | cut -c2-99 | grep -o "[0-9\.]*")

docker build --build-arg METEOR_VERSION=$METEOR_VERSION --build-arg NODE_VERSION=$NODE_VERSION .

Since this is a separate script (which I use on DockerHub because it allows to overwrite the build script) - where should I add this as a good flexible version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants