Skip to content

Dockerfile fixes #35

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

Merged
merged 6 commits into from
Mar 21, 2017
Merged

Dockerfile fixes #35

merged 6 commits into from
Mar 21, 2017

Conversation

maxjacobson
Copy link
Contributor

While pursuing an unrelated bug, I noticed the engine wasn't building.

Otherwise there's no /usr/bin/php7 and nothing works
We should leverage docker caching so builds take less time.
Dockerfile Outdated
@@ -22,13 +21,18 @@ RUN apk --update add \
rm /var/cache/apk/* && \
ln -s /usr/bin/php7 /usr/bin/php

COPY composer.json /usr/src/app/composer.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use a pattern for these two files to avoid the extra layer. Also, since the WORKDIR is already set to /usr/src/app above, you can use ./ for the second argument:

COPY composer.* ./

Copy link
Contributor Author

@maxjacobson maxjacobson Mar 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice. I see this works, but tbh I don't totally understand it. the COPY directive knows to copy files relative to the Dockerfile into the workdir? cp composer.* ./ wouldn't do anything, but I shouldn't think of COPY and cp as conceptually the same thing, huh?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. COPY in a Dockerfile does not have the same interface or behavior as cp.

Here's a snippet from the docs:

COPY <src>... <dest>

Multiple resources may be specified but they must be relative to the source directory that is being built (the context of the build).

Each may contain wildcards and matching will be done using Go’s filepath.Match rules.

The is an absolute path, or a path relative to WORKDIR, into which the source will be copied inside the destination container.

https://docs.docker.com/engine/reference/builder/#copy

Dockerfile Outdated
RUN apk --update add curl && \
curl -sS https://getcomposer.org/installer | php && \
./composer.phar install && \
apk del curl && \
rm /usr/src/app/composer.phar \
/var/cache/apk/*

COPY bin/build-content /usr/src/app/bin/build-content
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of adding the bin/ directory to the COPY directive above to avoid this extra layer? It's rare that these bin files change so I think we can take the cache miss when they do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm I like that idea, but how do you write that? Trying

COPY composer.*|bin ./

But that ... does not seem to work 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would try:

COPY composer.* bin/ ./

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. it seems to copy the contents of bin, into /, not bin itself. From reading the docs, I'm not sure if there's a way to get around that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, could you try without the trailing slash? I think there's a difference in behavior there:

COPY composer.* bin ./

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that behavior difference only applies to the <dest> parameter. I'm getting the same result both ways

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behavior is a little confusing. Looks like when the <dest> has a trailing slash, the contents of the <src>s are copied in. If you want to copy an entire directory, you need to specify a specific destination: COPY bin ./bin

Unfortunately this means you can't mix and match so I think keeping the bin/build-content COPY line where you have it is fine 👌

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

COPY bin/build-content /usr/src/app/bin/build-content

You can use a relative destination though:

COPY bin/build-content ./bin/build-content

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Niice. Updated

Dockerfile Outdated
@@ -37,6 +41,8 @@ RUN apk --update add build-base ca-certificates ruby ruby-dev && \
apk del build-base ca-certificates ruby ruby-dev && \
rm /var/cache/apk/*

COPY . /usr/src/app
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second argument here can also change to ./ since the WORKDIR is still /usr/src/app

@maxjacobson maxjacobson merged commit f8852f0 into master Mar 21, 2017
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.

2 participants