Dockerfile templates


#1

Hey everyone,

We released this feature sometime ago but until now haven’t officially announced it.

Dockerfile templates allow you to push variables to our resin builders. Current available variables are RESIN_ARCH and RESIN_MACHINE_NAME.

What this allows you to do is push your repository to any application with any device type without having to change any code.

For example our current base-image naming scheme is: <devicetype>-<language> e.g. raspberrypi-node

Therefore we could use the RESIN_MACHINE_NAME variable to push apps to multiple applications without changing the device type. All we would need to do is adjust the FROM command and rename our Dockerfile to Dockerfile.template like so:

FROM resin/%%RESIN_MACHINE_NAME%%-node

Our builders then infer RESIN_MACHINE_NAME from what “device type” application you are pushing to. So if the resin remote you are pushing to is associated to an Intel Edison application, the machine name will be edison and an i386 architecture base image will be built.

You can read more about them in our docs

If you’d like to see more Dockerfile variables let us know the usecase and we’d be happy to implement!

Happy Hacking!


#2

So in this case this would work by pushing to multiple apps from the same git repo, right? The resin apps themselves are still single-device-type only.


#3

That’s correct. For now :slight_smile:


#4

I tried to use this and received this error:

Step 1 : FROM resin/%%RESIN_MACHINE_NAME%%-node
       Error while processing push: Error: repository name component must match "[a-z0-9](?:-*[a-z0-9])*(?:[._][a-z0-9](?:-*[a-z0-9])*)*"

#5

Hi @justin8, this error is normally because someone tries to use the templating %% symbols in a regular Dockerfile, unfortunately the templates only work if your file is named Dockerfile.template …In the future we will implement some logic to try catch these cases and build the correct dockerfile, but at the moment it results in this quiet ugly error.
sorry for the inconvenience.
cheers
Shaun


#6

Ah, I skimmed the docs and didn’t notice the .template extension. Working well now. Thanks


#7

How do I access and RESIN_ARCH and RESIN_MACHINE_NAME in a conainer?

In a bash script running in my main container, I can echo $RESIN_DEVICE_UUID and $RESIN_DEVICE_NAME_AT_INIT, but $RESIN_MACHINE_NAME and $RESIN_ARCH return nothing.


#8

@winstonford would RESIN_DEVICE_TYPE work? That will tell you intel-nuc or raspberrypi3.

Otherwise there may be a way to use a docker-compose file to push arguments into a container during the docker build process.


#9

Thx @jgentes , that works.