Docker Community Forums

Share and learn in the Docker community.

Help with context when auto building from git and using build hooks

I’m not too experienced with docker, so I am running into a wall here trying to figure out what I have done wrong.

I am auto building from git using 3 separate docker files (amd64, arm64 and armhf) and I found on stack overflow a way this could be setup to auto build with docker hub using build hooks.

At present, most the docker files are in the git root dir, so things are a bit messy. I want to move them to a docker sub dir, but I think I am coming unstuck with relative root or context.

I either get an error saying that my post_checkout has failed, or I get an error about copying files from outside the context. I cannot seem to get it working.

At present:

Project
 |
 +-- readme
 +-- Dockerfile1
 +-- Dockerfile2.armhf
 +-- Dockerfile3.aarch64
 +-- hooks
 |      |
 |      +-- build
 |      +-- pre_build
 |      +-- post_checkout
 | 
 +-- project file 1
 +-- project file 2
 +-- project file 3

But I want to change it to:

Project
 |
 +-- readme
 |    
 +-- Docker
 |  |  
 |  +-- Dockerfile1
 |  +-- Dockerfile2.armhf
 |  +-- Dockerfile3.aarch64
 |  +-- hooks
 |      |
 |      +-- build
 |      +-- pre_build
 |      +-- post_checkout
 |    
 +-- project file 1
 +-- project file 2
 +-- project file 3

Here are my hooks: https://pastebin.com/7wM3mgxS

An example of one of the docker files:

FROM alpine:3.10.3

ENV LANG="en_US.utf8" APP_NAME="app" IMG_NAME="app" PATH="/opt/app:$PATH"

RUN apk add --no-cache bash curl git nano vim ca-certificates python3 su-exec

COPY . /opt/$APP_NAME

RUN rm -rf /tmp/* /var/tmp/* /opt/$APP_NAME/entrypoint.sh /opt/$APP_NAME/Docker

WORKDIR /opt/app

COPY /Docker/entrypoint.sh /

RUN chmod +x /entrypoint.sh && mkdir /config

VOLUME /config

EXPOSE 9090

ENTRYPOINT ["/entrypoint.sh"]

CMD ["app.py"]

What am I doing wrong here? How do I move those files into the ‘Docker’ sub folder?

If I put them in the docker folder and change the build context, I cannot get outside the docker folder. If I put them inside the folder, but specificy “Docker/Dockerfile” as the dockerfile path, it also causes issues.

Any help greatly appreciated :slight_smile:

For anyone else with this problem, I have worked around it by setting the build context to the sub folder containing the dockerfiles and changing:

COPY . /path/to/app/dir/

to

RUN mkdir /app/dir && cd /app/dir/ && git clone https://github.com/repo .

This is the second time I have posted on these forums for help, had no answers and ended up solving my own issue. I’d probably get more answers with a subscription to docker cloud, right? :rofl: :unamused: