alpine-docker / git

A useful simple git container running in alpine linux, especially for tiny linux distro, such as RancherOS, which don't have package manager.
Apache License 2.0
155 stars 86 forks source link

multi-arch support #30

Closed ozbillwang closed 3 years ago

ozbillwang commented 3 years ago

I read this document, this is a right direction to deal with multi-arch

https://docs.docker.com/docker-for-mac/multi-arch/

https://www.docker.com/blog/multi-arch-build-and-images-the-simple-way/

We should go with simple way, not the hard way with docker manifest

# run one time
docker buildx create --name mybuilder --use

# build multi-arch image with one tag
docker buildx build --platform linux/arm/v7,linux/arm64/v8,linux/amd64 --tag alpine/git:${version} --push .

With this way, we don't need maintain multiple tags, such as v2.26.2-arm64 and v2.26.2 for same version and the system itself will know to pull the image for its arch automatically.

I did a sample with alphone/helm:3.5.0-rc.1 for reference 104883378-cb06b100-59b8-11eb-9112-02330ce1dacd

ozbillwang commented 3 years ago

@barthy1

The old part of multi-arch need be re-written.

ozbillwang commented 3 years ago

@barthy1

Could you please run a test on a ARM64 machine with below command:

docker run -ti --rm alpine/helm:3.5.0-rc.1 version

what output do you get?

I need a final confirmation to prove if my way is correct or not.

barthy1 commented 3 years ago

@ozbillwang I have s390x or ppc64le hardware only to verify. Could you please add linux/s390x platform to your build for me to verify?

Also found interesting blog post about building with docker buildx on Travis - https://www.docker.com/blog/multi-arch-build-what-about-travis. However do you think it's time to move to Github actions for the same purpose https://github.com/marketplace/actions/docker-buildx#quick-start?

Anyway I think using docker buildx can be simpler and cleaner solution for multi-arch, so it would be great to use it.

ozbillwang commented 3 years ago

@barthy1

I have built for s390x and ppc64le, could you test now?

image

two test commands:

docker run -ti --rm alpine/helm:3.5.0-rc.1 version

and

$ docker run -ti --rm --entrypoint=sh alpine/helm:3.5.0-rc.1
/apps # uname -m
ozbillwang commented 3 years ago

For your second question. I still think Github Action is in early age currently, not mature enough, we can migrate all of them to Github Action later. But now, it is not suitable.

The main reason is, I don't see the feature to manage secrets properly.

In travis, I can manage secrets with nominated branches. I don't see the same feature in Github Action.

barthy1 commented 3 years ago
# uname -m
ppc64le
# docker run -ti --rm alpine/helm:3.5.0-rc.1 version
standard_init_linux.go:175: exec user process caused "exec format error"
# uname -m
s390x
# docker run -it --rm alpine/helm:3.5.0-rc.1 version
standard_init_linux.go:211: exec user process caused "exec format error"

The error means that image is running on wrong architecture. Because it's not running I cannot login inside and check uname -m. Let me try to do alpine/helm build also on my env with configured buildx, just to check. So far I don't understand why we got this failing result

ozbillwang commented 3 years ago

could you pull again to make sure it doesn't use the old one.

docker pull alpine/helm:3.5.0-rc.1
docker run -ti --rm alpine/helm:3.5.0-rc.1 version
barthy1 commented 3 years ago

done. Same result

ozbillwang commented 3 years ago

You can build git image directly and test

replace <your_org> with your own org, that you have write permission to push

# to make sure the support platforms
docker buildx ls

docker buildx build --platform linux/arm/v7,linux/arm64/v8,linux/amd64,linux/ppc64le,linux/s390x  --tag <your_org>/git --push .
barthy1 commented 3 years ago

Update from my side, with /bin/sh entrypoint it works

# docker run -ti --rm --entrypoint=/bin/sh alpine/helm:3.5.0-rc.1
/apps # uname -m
s390x

so actually just helm version doesn't, as helm binary in the current Dockerfile has amd64 version for all archs - https://github.com/alpine-docker/helm/blob/master/Dockerfile#L10

ozbillwang commented 3 years ago

ic. Thanks to find it out. that codes are hard coded, will fix it.

ozbillwang commented 3 years ago

The Dockerfile for git has no same issue. I built a special tag alpine/git:multi for you to run test.

image

This is the command for your reference:

docker buildx build --platform linux/amd64,linux/arm64,linux/ppc64le,linux/s390x,linux/386,linux/arm/v7,linux/arm/v6  --tag alpine/git:multi --push .
barthy1 commented 3 years ago

just fyi, docker buildx has nice set of predefined env variables https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope. TARGETARCH looks promising to fix helm build

ozbillwang commented 3 years ago

Did you have chance to test the git image on s390x and ppc64le?

# uname -m
s390x

# docker pull alpine/git:multi 
# docker run -it --rm alpine/git:multi version

What's the output?

barthy1 commented 3 years ago
# docker run -ti --rm alpine/git:multi version
Unable to find image 'alpine/git:multi' locally
multi: Pulling from alpine/git
3997176601fb: Already exists
8a0ac3530f85: Pull complete
724b374f1a16: Pull complete
Digest: sha256:d0eb5e18f4b7ca63b73a2c687cc6ea68b8e30c02430fa6b7e58d66f840288e73
Status: Downloaded newer image for alpine/git:multi
git version 2.30.0
# docker run -ti --rm --entrypoint=sh alpine/git:multi
/git # uname -m
s390x
# docker run -ti --rm alpine/git:multi version
Unable to find image 'alpine/git:multi' locally
multi: Pulling from alpine/git

cb0f06c26ffd: Already exists
960f1be7c9b3: Pull complete
63b6d4c3f1b9: Pull complete
Digest: sha256:d0eb5e18f4b7ca63b73a2c687cc6ea68b8e30c02430fa6b7e58d66f840288e73
Status: Downloaded newer image for alpine/git:multi
git version 2.30.0
# docker run -ti --rm --entrypoint=sh alpine/git:multi
/git # uname -m
ppc64le
ozbillwang commented 3 years ago

Thanks for the confirmation.

Currently I can't install other multi-arch platfroms in Travis, will try later.

https://travis-ci.org/github/ozbillwang/travis-demo/builds/754997888

https://github.com/ozbillwang/travis-demo/blob/main/.travis.yml

image

ozbillwang commented 3 years ago

all related multi-arch related issues, please follow up at https://github.com/alpine-docker/multi-arch-docker-build-on-ci/issues/1