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

Enable multi-architecture docker image builds #327

Merged
merged 2 commits into from
Apr 3, 2021

Conversation

tkw1536
Copy link
Contributor

@tkw1536 tkw1536 commented Jul 13, 2020

Previously, the Dockerfile downloaded a 'docker-gen' binary during build time. This caused a problem as it hard-coded the amd64 architecture for the image.

This PR updates the Dockerfile to build the docker-gen executable from source instead of downloading a binary. This updated Dockerfile uses a multi-stage build [1].
The first stage downloads a source tarball from GitHub and produces a binary out of it. The second stage corresponds to the old Dockerfile, with the sole change being that is fetches the binary from the first stage instead of GitHub.

This has the advantage that the build process no longer assumes a certain architecture and enables building the image for any architecture that both the golang and alpine base images support.
I've tested building this modified Dockerfile on both a linux desktop (amd64) and a raspberry pi (armv7). I've also used the built image to successfully test a modified architecture independent variant of [2] successfully, I will make a similar PR there soon as well.
Together with actually publishing multi-architecture images to DockerHub this PR fixes #304 and #318.

This PR also bumps the version being built to 0.7.4, as 0.7.3 can no longer be compiled from source.

[1] https://docs.docker.com/develop/develop-images/multistage-build/
[2] https://github.com/nginx-proxy/nginx-proxy

Previously, the Dockerfile downloaded a 'docker-gen' binary during build
time. This caused a problem as it hard-coded the amd64 architecture for
the image.

This commit updates the Dockerfile to build the docker-gen executable
from source instead of downloading a binary. This updated Dockerfile
uses a multi-stage build [1]. The first stage downloads a source tarball
from github and produces a binary out of it. The second stage
corresponds to the old Dockerfile, with the sole change being that is
fetches the binary from the first stage instead of GitHub.

This has the advantage that the build process no longer assumes a
certain architecture and enables building the image for any architecture
that both the golang and alpine base images support.

[1] https://docs.docker.com/develop/develop-images/multistage-build/
The previous version of the Dockerfile made use of version 0.7.3. However because of changes in dependencies, this can no longer be compiled from source. To fix this regression, this commit updates the version used to 0.7.4.
tkw1536 added a commit to KWARC/nginx-proxy that referenced this pull request Jul 13, 2020
Previously, the Dockerfile downloaded 'docker-gen' and 'forego' binaries
during build time. This caused a problem as it hard-coded the amd64
architecture for the images.

This commit updates both 'Dockerfile' and 'Dockerfile.alpine' to build
the `forego` and `docker-gen` executables from scratch instead of
downloading binaries directly.

This is achieved using multi-stage builds [1]. Two seperate stages first
build the binaries, and are then copied over to the final stage.

The advantage of this change is two-fold: First, it enables building
this image on architectures other than amd64. Secondly it adds trust by
not adding external binaries to the docker image.

This modified version passes the test both a linux desktop (amd64) as
well as a raspberry pi (armv7) with some caveats:

- On armv7, a modified version of the `jwilder/docker-gen` image is
required. See a seperate PR at [2].

- The 'test_dhparam_is_generated_if_missing' test fails. This also
doesn't currently pass on master.

[1] https://docs.docker.com/develop/develop-images/multistage-build/ [2]
nginx-proxy/docker-gen#327
tkw1536 added a commit to KWARC/nginx-proxy that referenced this pull request Oct 11, 2020
Previously, the Dockerfile downloaded 'docker-gen' and 'forego' binaries
during build time. This caused a problem as it hard-coded the amd64
architecture for the images.

This commit updates both 'Dockerfile' and 'Dockerfile.alpine' to build
the `forego` and `docker-gen` executables from scratch instead of
downloading binaries directly.

This is achieved using multi-stage builds [1]. Two seperate stages first
build the binaries, and are then copied over to the final stage.

The advantage of this change is two-fold: First, it enables building
this image on architectures other than amd64. Secondly it adds trust by
not adding external binaries to the docker image.

This modified version passes the test both a linux desktop (amd64) as
well as a raspberry pi (armv7) with some caveats:

- On armv7, a modified version of the `jwilder/docker-gen` image is
required. See a seperate PR at [2].

- The 'test_dhparam_is_generated_if_missing' test fails. This also
doesn't currently pass on master.

[1] https://docs.docker.com/develop/develop-images/multistage-build/ [2]
nginx-proxy/docker-gen#327
tkw1536 added a commit to KWARC/nginx-proxy that referenced this pull request Jan 10, 2021
Previously, the Dockerfile downloaded 'docker-gen' and 'forego' binaries
during build time. This caused a problem as it hard-coded the amd64
architecture for the images.

This commit updates both 'Dockerfile' and 'Dockerfile.alpine' to build
the `forego` and `docker-gen` executables from scratch instead of
downloading binaries directly.

This is achieved using multi-stage builds [1]. Two seperate stages first
build the binaries, and are then copied over to the final stage.

The advantage of this change is two-fold: First, it enables building
this image on architectures other than amd64. Secondly it adds trust by
not adding external binaries to the docker image.

This modified version passes the test both a linux desktop (amd64) as
well as a raspberry pi (armv7) with some caveats:

- On armv7, a modified version of the `jwilder/docker-gen` image is
required. See a seperate PR at [2].

- The 'test_dhparam_is_generated_if_missing' test fails. This also
doesn't currently pass on master.

[1] https://docs.docker.com/develop/develop-images/multistage-build/ [2]
nginx-proxy/docker-gen#327
tkw1536 added a commit to KWARC/nginx-proxy that referenced this pull request Feb 6, 2021
Previously, the Dockerfile downloaded 'docker-gen' and 'forego' binaries
during build time. This caused a problem as it hard-coded the amd64
architecture for the images.

This commit updates both 'Dockerfile' and 'Dockerfile.alpine' to build
the `forego` and `docker-gen` executables from scratch instead of
downloading binaries directly.

This is achieved using multi-stage builds [1]. Two seperate stages first
build the binaries, and are then copied over to the final stage.

The advantage of this change is two-fold: First, it enables building
this image on architectures other than amd64. Secondly it adds trust by
not adding external binaries to the docker image.

This modified version passes the test both a linux desktop (amd64) as
well as a raspberry pi (armv7) with some caveats:

- On armv7, a modified version of the `jwilder/docker-gen` image is
required. See a seperate PR at [2].

- The 'test_dhparam_is_generated_if_missing' test fails. This also
doesn't currently pass on master.

[1] https://docs.docker.com/develop/develop-images/multistage-build/ [2]
nginx-proxy/docker-gen#327
tkw1536 added a commit to KWARC/nginx-proxy that referenced this pull request Mar 21, 2021
Previously, the Dockerfile downloaded 'docker-gen' and 'forego' binaries
during build time. This caused a problem as it hard-coded the amd64
architecture for the images.

This commit updates both 'Dockerfile' and 'Dockerfile.alpine' to build
the `forego` and `docker-gen` executables from scratch instead of
downloading binaries directly.

This is achieved using multi-stage builds [1]. Two seperate stages first
build the binaries, and are then copied over to the final stage.

The advantage of this change is two-fold: First, it enables building
this image on architectures other than amd64. Secondly it adds trust by
not adding external binaries to the docker image.

This modified version passes the test both a linux desktop (amd64) as
well as a raspberry pi (armv7) with some caveats:

- On armv7, a modified version of the `jwilder/docker-gen` image is
required. See a seperate PR at [2].

- The 'test_dhparam_is_generated_if_missing' test fails. This also
doesn't currently pass on master.

[1] https://docs.docker.com/develop/develop-images/multistage-build/ [2]
nginx-proxy/docker-gen#327
@jwilder jwilder merged commit faaa781 into nginx-proxy:master Apr 3, 2021
@tkw1536 tkw1536 deleted the build-from-scratch branch April 4, 2021 11:04
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

Successfully merging this pull request may close these issues.

Add support for multiple architectures for Docker container
2 participants