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

[Feature Request] Ability to build dockerfile located inside sub-directories #83

Closed
dduportal opened this issue Feb 26, 2018 · 6 comments

Comments

@dduportal
Copy link
Contributor

Hello!

Thanks for your work on this project!

I would want to replace my handmade Makefile by habitus to build my docker images library, which are all located on a single repository (inter-dependencies).

Each Dockerfile is stored in a dedicated folder (goal: only upload the context of a given image when building it).

With the current habitus version (v1.0.1), the COPY directives are exiting in error with the following message:

Build for step test failed due to COPY failed: stat /var/lib/docker/tmp/docker-builder225133515/entrypoint.sh: no such file or directory 

If I move (and adapt) my build.yml into the image directory, then it works as expected.
I can also use the "artifacts" instruction to make it work, but it would make my Dockerfile too tightened to habitus (and not feature-complete).

Based on the documentation, I understand that the flag "d" passed to the commandline give the working directory for habitus. Haven't read the code yet, but I suppose this working directory is uploaded to the remote docker engine, with the generated Dockerfiles inside. But the content of sub directories is not, leading in this error.

It would nice to be able to specify sub directories for the dockerfile instruction in the build.yml.
It would allow the build.yml to "orchestrate" the build, but keeping a logical isolation for the source code, as well as allowing more complex build patterns using git subtrees, virtual FS views, etc.

I've put an example of expectation for this feature below:

  • Directory tree view:
$ tree
.
├── build.yml
├── test
│   ├── Dockerfile
│   └── entrypoint.sh
  • build.yml:

build:
  version: 2016-03-14 # version of the build schema.
  steps:
    test:
      name: test
      dockerfile: test/Dockerfile
  • Dockerfile:
FROM alpine:3.7
RUN apk add --no-cache tini

COPY ./entrypoint.sh /entrypoint.sh

ENTRYPOINT ["tini","-g","--","sh"]
CMD ["/entrypoint.sh"]

Tell me if this is clear, or if you need more information, review, or whatever help on this.

@mumoshu
Copy link
Collaborator

mumoshu commented Mar 8, 2018

@dduportal Hi! Have you tried setting work_dir in your build.yaml like:

build:
  version: 2016-03-14 # version of the build schema.
  steps:
    test:
      name: test
      dockerfile: test/Dockerfile
      work_dir: test/

I suppose it would work as far as I could see from the implementation 😉

@khash khash changed the title [Feature Request] Hability to build dockerfile located inside sub-directories [Feature Request] Ability to build dockerfile located inside sub-directories Apr 5, 2018
@dduportal
Copy link
Contributor Author

Hello @mumoshu @khash , thanks for your feedback (and title fix, my aplogizes).

While I am playing with the work_dir option, I would like to contribute to the documentation to add it in the sights of newcomers.

Where could I find the www.habitus.io website documentation content to help?

@dduportal
Copy link
Contributor Author

dduportal commented May 10, 2018

Thanks for this @mumoshu , but alas, it is not working:

2018/05/10 11:31:00 ▶ Using '/Users/dadou/workspace/habitus/gh-83-workdir/build.yml' as build file 
2018/05/10 11:31:00 ▶ Collecting artifact information 
2018/05/10 11:31:00 ▶ Building 1 steps 
2018/05/10 11:31:00 ▶ Step 1 - test, image-name = 'test' 
2018/05/10 11:31:00 ▶ Step 1 - Build for test 
2018/05/10 11:31:00 ▶ Step 1 - Building test from context '/Users/dadou/workspace/habitus/gh-83-workdir' 
2018/05/10 11:31:00 ▶ Step 1 - Parsing and converting 'test/Dockerfile' 
2018/05/10 11:31:00 ▶ Step 1 - Writing the new Dockerfile into '/Users/dadou/workspace/habitus/gh-83-workdir/test/Dockerfile.generated' 
2018/05/10 11:31:00 ▶ Step 1 - Building the test image from /Users/dadou/workspace/habitus/gh-83-workdir/test/Dockerfile.generated 
Step 1/5 : FROM alpine:3.7
 ---> 3fd9065eaf02
Step 2/5 : RUN apk add --no-cache tini
 ---> Using cache
 ---> 4d2ec547ded1
Step 3/5 : COPY ./entrypoint.sh /entrypoint.sh
2018/05/10 11:31:00 ▶ Build for step test failed due to COPY failed: stat /var/lib/docker/tmp/docker-builder136767931/entrypoint.sh: no such file or directory 

I am reading the source code and trying to get myself ready in Go to contribute.

As I understand the work_dir directive, it is the same thing as the -d option provided byt the habitus CLI, when means "Path to work directory. This is the path where Dockerfiles should exist for each step and the build happens. Defaults to the current directory., so expctation is a flattened file tree. Am I right?

@khash
Copy link
Member

khash commented May 10, 2018

@dduportal thanks for the offer of help with documentation. You can find Habitus.io contents under the gh-pages branch of the repository.

@dduportal
Copy link
Contributor Author

Hello @khash @mumoshu , I have opened a first PR with an implementation proposal for this feature: #102

@dduportal
Copy link
Contributor Author

And documentation PR: #103

@khash khash closed this as completed Jan 29, 2019
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

No branches or pull requests

3 participants