10

Trying to make a simple GitLab pipeline that builds a Docker image for Alpine Linux + Openshift CLI.

This is the code:

FROM frolvlad/alpine-glibc:latest

MAINTAINER Daniel Widerin <daniel@widerin.net>

ENV OC_VERSION=v3.11.0 \
    OC_TAG_SHA=0cbc58b \
    BUILD_DEPS='tar gzip' \
    RUN_DEPS='curl ca-certificates gettext'

RUN apk --no-cache add $BUILD_DEPS $RUN_DEPS && \
    curl -sLo /tmp/oc.tar.gz https://github.com/openshift/origin/releases/download/${OC_VERSION}/openshift-origin-client-tools-${OC_VERSION}-${OC_TAG_SHA}-linux-64bit.tar.gz && \
    tar xzvf /tmp/oc.tar.gz -C /tmp/ && \
    mv /tmp/openshift-origin-client-tools-${OC_VERSION}-${OC_TAG_SHA}-linux-64bit/oc /usr/local/bin/ && \
    rm -rf /tmp/oc.tar.gz /tmp/openshift-origin-client-tools-${OC_VERSION}-${OC_TAG_SHA}-linux-64bit && \
    apk del $BUILD_DEPS

CMD ["/bin/sh"]

Now for some reason when running the pipeline it gets stuck on the curl part that downloads the openshift archive.

Status: Downloaded newer image for frolvlad/alpine-glibc:latest
 ---> 38dd85a430e8
Step 2/5 : MAINTAINER Daniel Widerin <daniel@widerin.net>
 ---> Running in bdacc7e92e79
Removing intermediate container bdacc7e92e79
 ---> c56da0a68f7f
Step 3/5 : ENV OC_VERSION=v3.11.0     OC_TAG_SHA=0cbc58b     BUILD_DEPS='tar gzip'     RUN_DEPS='curl ca-certificates gettext'
 ---> Running in cb1e6cdb39ca
Removing intermediate container cb1e6cdb39ca
 ---> 727952120e67
Step 4/5 : RUN apk --no-cache add $BUILD_DEPS $RUN_DEPS &&     curl -sLo /tmp/oc.tar.gz https://github.com/openshift/origin/releases/download/${OC_VERSION}/openshift-origin-client-tools-${OC_VERSION}-${OC_TAG_SHA}-linux-64bit.tar.gz &&     tar xzvf /tmp/oc.tar.gz -C /tmp/ &&     mv /tmp/openshift-origin-client-tools-${OC_VERSION}-${OC_TAG_SHA}-linux-64bit/oc /usr/local/bin/ &&     rm -rf /tmp/oc.tar.gz /tmp/openshift-origin-client-tools-${OC_VERSION}-${OC_TAG_SHA}-linux-64bit &&     apk del $BUILD_DEPS
 ---> Running in ef344ef4a96b
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/main/x86_64/APKINDEX.tar.gz

It stays like this for an hour until the pipeline times out.

Tried this same Dockerfile manually and it works fine.

How can I diagnose this issue? How can I find any logs for this?

robliv
  • 1,351
  • 3
  • 15
  • 30
  • If it works on your machine but not on the machine that executes the GitLab job, something has to be different. I would start with trying to run the `curl` commands directly from the GitLab job and to the same URL, to see if there is some trouble there. If it works, something prevents the docker container from reaching that URL. If it doesn't work, something is wrong with the runner executing the jobs. I would also try to make an even simpler Dockerfile until I have something that works, and then add things until it breaks. – MrBerta Dec 30 '19 at 09:53
  • If you are running on a cloud runner from GitLab, you can try to change to a gitlab runner that you have control over. If it is using the `docker-executor`, after the job has finished/timed out, there should be a docker container left over from the job that you can check if it has some log files. You could also try to manually start a docker container that uses the same image as your job is using and see if you can run the steps of your build jobs manually. – MrBerta Dec 30 '19 at 09:55
  • 2
    Thanks for the help. I did a mistake with the title as it didn't get stuck on Curl, but on apk. Found that this issue is related to docker-in-docker(DinD) and Alpine image having some networking issues and adding `--network host` to `Docker build` helps to fix this issue. https://github.com/gliderlabs/docker-alpine/issues/307 – robliv Jan 02 '20 at 13:41

1 Answers1

16

Found that this issue is related to Alpine image having networking issues when run in Docker-in-Docker configuration on Kubernetes/OpenShift based runner. Adding --network host to Docker build helps to fix this issue.

Docker build --network host .

Related GitHub issue: github.com/gliderlabs/docker-alpine/issues/307

robliv
  • 1,351
  • 3
  • 15
  • 30