Skip to content
This repository has been archived by the owner on Jul 6, 2022. It is now read-only.

Use ARG environment variable as template system #67

Open
isman7 opened this issue Oct 26, 2019 · 0 comments · May be fixed by #99
Open

Use ARG environment variable as template system #67

isman7 opened this issue Oct 26, 2019 · 0 comments · May be fixed by #99

Comments

@isman7
Copy link

isman7 commented Oct 26, 2019

Hi!

I'm in the Barcelona 2019 Hackaton, I've been speaking with some of your developers and I've been advised to post this issue here.

Regarding the template system implemented in your platform, to be able to build Docker images for several boards, i. e. Raspberry Pi 2 or 3 at the same time, documented here: https://www.balena.io/docs/learn/develop/dockerfile/; I believe it should be fully compatible with the new standard ARG environments variables in FROM statements during the build time of a docker image. Which is documented here: https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact

Take into account the example Dockerfile given by this repo: https://github.com/balena-io-playground/balena-sense-hat-python-starter/blob/master/Dockerfile

FROM resin/raspberrypi3-debian:latest

This FROM statement works locally and remotely for Raspberry Pi 3 images, if we want to use this Dockerfile in different machines, we should implement your template system:

FROM resin/%%BALENA_MACHINE_NAME%%-debian:latest

And consequently rename Dockerfile to Dockerfile.template, that would make this Dockerfile not complience with Docker standards.

One would expect that BALENA_MACHINE_NAME would be present as a environment variable as build time during your building, thus,

ARG BALENA_MACHINE_NAME
FROM resin/${BALENA_MACHINE_NAME}-debian:latest

would work, but it does not! The best approach I've currently found it is something like this:

ARG BALENA_MACHINE_NAME=%%BALENA_MACHINE_NAME%%
FROM resin/${BALENA_MACHINE_NAME}-debian:latest

Using a Dockerfile.template as a Dockerfile and it is both compatible with Docker cli and your template system.

robertgzr added a commit that referenced this issue Nov 10, 2021
This basically renders Dockerfile.template useless, since the same can
be achieved using build args. We simply pass the same values to the
docker build and let the user use them. This also includes
TARGETPLATFORM, which buildx injects:
https://docs.docker.com/buildx/working-with-buildx/#build-multi-platform-images

Closes #67

Change-type: minor
Signed-off-by: Robert Günzler <[email protected]>
@robertgzr robertgzr linked a pull request Nov 10, 2021 that will close this issue
robertgzr added a commit that referenced this issue Nov 10, 2021
This basically renders Dockerfile.template useless, since the same can
be achieved using build args. We simply pass the same values to the
docker build and let the user use them. This also includes
TARGETPLATFORM, which buildx injects:
https://docs.docker.com/buildx/working-with-buildx/#build-multi-platform-images

A sample dockerfile could look like this:
```
ARG BALENA_MACHINE_NAME
FROM balenalib/${BALENA_MACHINE_NAME}-alpine

ARG BALENA_ARCH
RUN do some thing with ${BALENA_ARCH}
```

Closes #67

Change-type: minor
Signed-off-by: Robert Günzler <[email protected]>
robertgzr added a commit that referenced this issue Nov 10, 2021
This basically renders Dockerfile.template useless, since the same can
be achieved using build args. We simply pass the same values to the
docker build and let the user use them. This also includes
TARGETPLATFORM, which buildx injects:
https://docs.docker.com/buildx/working-with-buildx/#build-multi-platform-images

A sample dockerfile could look like this:
```
ARG BALENA_MACHINE_NAME
FROM balenalib/${BALENA_MACHINE_NAME}-alpine

ARG BALENA_ARCH
RUN do some thing with ${BALENA_ARCH}
```

Closes #67

Change-type: minor
Signed-off-by: Robert Günzler <[email protected]>
robertgzr added a commit that referenced this issue Nov 12, 2021
This basically renders Dockerfile.template obsolete, since the same can
be achieved using build args. We simply pass the same values to the
docker build and let the user use them. This also includes
TARGETPLATFORM, which buildx injects:
https://docs.docker.com/buildx/working-with-buildx/#build-multi-platform-images

A sample dockerfile could look like this:
```
ARG BALENA_MACHINE_NAME
FROM balenalib/${BALENA_MACHINE_NAME}-alpine

ARG BALENA_ARCH
RUN do some thing with ${BALENA_ARCH}
```

Closes #67

Change-type: minor
Signed-off-by: Robert Günzler <[email protected]>
robertgzr added a commit that referenced this issue Nov 12, 2021
This basically renders Dockerfile.template obsolete, since the same can
be achieved using build args. We simply pass the same values to the
docker build and let the user use them. This also includes
TARGETPLATFORM, which buildx injects:
https://docs.docker.com/buildx/working-with-buildx/#build-multi-platform-images

A sample dockerfile could look like this:
```
ARG BALENA_MACHINE_NAME
FROM balenalib/${BALENA_MACHINE_NAME}-alpine

ARG BALENA_ARCH
RUN do some thing with ${BALENA_ARCH}
```

Closes #67

Change-type: minor
Signed-off-by: Robert Günzler <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant