Beginnings build container sample.#1
Conversation
|
|
||
| rm -r ./out | ||
|
|
||
| if [ -n "$currentBuildImage" ]; then |
There was a problem hiding this comment.
Why persist this state and then wait until the end to do the cleanup? Why not just do it up front?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
or am I missing something that makes this unnecessary?
There was a problem hiding this comment.
@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:
- 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.
- 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.
|
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 | |||
There was a problem hiding this comment.
Feels like this may better belong at the root.
|
several of the files are missing a newline at the end of the file. |
| @@ -0,0 +1,4 @@ | |||
| FROM microsoft/dotnet:core | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
--configuration [](start = 33, length = 15)
I think we should be consistent across our samples. Rich is using -c in the samples he created.
| # 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 |
There was a problem hiding this comment.
If I follow what is happening correctly, the Dockerfile is getting copied to the dockerapp image. That doesn't seem optimal.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
3b5c898 to
b40d79e
Compare
|
@richlander @MichaelSimons How does that look now? Added some windows support... |
|
@kendrahavens Want to take a look? |
|
|
||
| param( | ||
| [ValidateSet('win', 'linux')] | ||
| [string]$baseImage = "win" |
There was a problem hiding this comment.
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.
|
|
||
| # 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) |
There was a problem hiding this comment.
Same comment as with the build.sh - what is the goal of this cleanup logic?
I just noticed an inconsistency with the other sample apps. They are explicitly named - e.g. Refers to: dotnetapp-buildcontainer/project.json:1 in 315cd4e. [](commit_id = 315cd4e, deletion_comment = False) |
| @@ -0,0 +1,38 @@ | |||
|
|
|||
| param( | |||
There was a problem hiding this comment.
I like that you are utilizing xplat powershell!
| @@ -0,0 +1,27 @@ | |||
| #!/bin/sh | |||
There was a problem hiding this comment.
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?
|
This problem is solved by the multi-step build infrastructure Docker now has. This PR is replaced with #44. |
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