Skip to content
This repository was archived by the owner on Mar 1, 2018. It is now read-only.

Beginnings build container sample.#1

Closed
glennc wants to merge 3 commits intodotnet:masterfrom
glennc:glennc-buildContainer
Closed

Beginnings build container sample.#1
glennc wants to merge 3 commits intodotnet:masterfrom
glennc:glennc-buildContainer

Conversation

@glennc
Copy link
Copy Markdown

@glennc glennc commented Oct 11, 2016

This still needs work, but enough is there to show what I was thinking with this sample. We would add a nano build image and a powershell script to finish it off.

What do you think?

@MichaelSimons @richlander


rm -r ./out

if [ -n "$currentBuildImage" ]; then
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why persist this state and then wait until the end to do the cleanup? Why not just do it up front?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you explain what the goal of this cleanup logic is? On a clean machine, run the script twice back to back. It appears that on the second run, the cleanup logic ends up deleting the images that were just built. Additionally the script errors out if there is a container that is referencing the app image.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You want the layers available when you are building the next image so that you don't do NuGet restore again. But after you are done you will have tagged the new build image and the old one will have no tag. So we use the tag to identify an image that after the build will be untagged and should be cleaned up. Does that make sense now?

The app image I just threw in because it was a sample and it seemed reasonable to delete it instead of leaving it untagged. I could add -f to avoid errors and do the delete but that seemed a bit aggressive.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

or am I missing something that makes this unnecessary?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@glennc - I understand what you are trying to achieve. My concern is there seems to be some edge cases that aren't handled, for example:

  1. If you run the script without changing the program after running it once already, then the app image doesn't get rebuilt because the layers haven't changed (this also occurs for the build image). The end result is the cleanup logic is deleting the previous image which is also the current image.
  2. As I mentioned if you run the app image and don't cleanup the container, then you will get an error from the cleanup logic.

While I think it is important to showcase how you should cleanup the Docker artifacts. If we don't handle the these edge cases that I think users could easily get into, then I think it detracts from the sample.

@richlander
Copy link
Copy Markdown
Member

richlander commented Oct 16, 2016

LGTM

The readme needs to be updated, still. That can be done after the merge. Same with the batch/ps script for Windows.

Great sample!

Thoughts @MichaelSimons ?

@@ -0,0 +1 @@
project.lock.json No newline at end of file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Feels like this may better belong at the root.

@MichaelSimons
Copy link
Copy Markdown
Member

several of the files are missing a newline at the end of the file.

Comment thread dotnetapp-buildcontainer/Dockerfile Outdated
@@ -0,0 +1,4 @@
FROM microsoft/dotnet:core
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

microsoft/dotnet:core [](start = 5, length = 21)

I think our samples should be using an explicit version as showcasing the best practices and avoiding the risk of breaking.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sure, I'll change it. IIRC I thought I still had a lot of work to do on this one so I hadn't done a pass looking for this sort of stuff.


# Add the rest of my source files.
COPY . .
RUN dotnet publish --output /out --configuration Release No newline at end of file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

--configuration [](start = 33, length = 15)

I think we should be consistent across our samples. Rich is using -c in the samples he created.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sure thing, I'll change that.

Comment thread dotnetapp-buildcontainer/build.sh Outdated
# Copy the contents of the /out directory out so that we can build our app image.
docker cp build-container:/out ./out
# Build the application image.
docker build -t dockerapp -f ./out/Dockerfile ./out
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If I follow what is happening correctly, the Dockerfile is getting copied to the dockerapp image. That doesn't seem optimal.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You could just put it in the project.json and you wouldn't need to copy it. I had meant to make that change, I was experimenting with how I could do it without.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not following how that is going to prevent the Dockerfile from being added to the dockerapp image. I was thinking you would need to do something like, stop coping the Dockerfile to the out directory and build via docker build -t dockerapp . Lastly the Dockerfile would have to be modified to copy from out - a74d917

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I misunderstood what you were asking about. For some reason I thought you were asking about copying the Dockerfile into the publish output folder, not adding it to the image. Yes I can change that.

…re consistent, use explicit version in the Dockerfile, and stop the Dockerfile from being part of the final image.
@glennc glennc force-pushed the glennc-buildContainer branch from 3b5c898 to b40d79e Compare October 18, 2016 19:05
@glennc
Copy link
Copy Markdown
Author

glennc commented Oct 18, 2016

@richlander @MichaelSimons How does that look now? Added some windows support...

@richlander
Copy link
Copy Markdown
Member

@kendrahavens Want to take a look?


param(
[ValidateSet('win', 'linux')]
[string]$baseImage = "win"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

win [](start = 26, length = 3)

We should be consistent across the samples on the terminology used for the nano images. The other samples are using nano.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

ok, sure thing.


# Capture the current build and app image, if any, so that we can clean them up when we are done.
$currentBuildImage=$(docker images build-image -q)
$currentAppImage=$(docker images dockerapp -q)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same comment as with the build.sh - what is the goal of this cleanup logic?

@MichaelSimons
Copy link
Copy Markdown
Member

{

I just noticed an inconsistency with the other sample apps. They are explicitly named - e.g. "name": "dotnetapp", I honestly have no preference other than we are consistent. This obviously affects the prod containers.


Refers to: dotnetapp-buildcontainer/project.json:1 in 315cd4e. [](commit_id = 315cd4e, deletion_comment = False)

@@ -0,0 +1,38 @@

param(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like that you are utilizing xplat powershell!

@@ -0,0 +1,27 @@
#!/bin/sh
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For both script files, what are your thoughts on handling error cases. I am primarily thinking about the experience when there is a build error in the app that is getting built.

This really comes down to how complete of a sample are we trying to build and what are we trying to showcase? Is this sample something we would want devs to be able to copy into their workflow with relatively few changes? Do we want to keep this sample relatively simple in order to better showcase the flow that can be achieved?

@MichaelSimons
Copy link
Copy Markdown
Member

This problem is solved by the multi-step build infrastructure Docker now has. This PR is replaced with #44.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants