codelab/03_buildpacks-runimage-override/tutorial.md
Cloud Native Buildpacks (CNB) enable building a container image from source code without the need for a Dockerfile. Skaffold supports building with CNB, requiring only a local Docker daemon.
CNB uses two images when building an application image:
Time to complete: <walkthrough-tutorial-duration duration=10></walkthrough-tutorial-duration>
Click the Start button to move to the next step.
We'll use minikube as our local kubernetes cluster of choice.
Run:
minikube start
CNB run and build images require some additional metadata to identify the Stack ID and user/group accounts to be used. A stack is a specification or contract. For example, the io.buildpacks.stacks.bionic stack defines that it provides the same packages as installed on Ubuntu 18.04.
We add a base artifact with a single <walkthrough-editor-open-file filePath="base/Dockerfile">Dockerfile</walkthrough-editor-open-file> that defines the required metadata, and reference this as an <walkthrough-editor-select-line filePath="skaffold.yaml" startLine="4" startCharacterOffset="4" endLine="6" endCharacterOffset="0">artifact</walkthrough-editor-select-line> called base in our skaffold.yaml.
Next we'll use this artifact as the run image for a sample Buildpacks app.
<walkthrough-footnote> We will use the `gcr.io/buildpacks/builder:v1` builder image which supports the Stack ID `google`. So that's what we added to the Dockerfile. </walkthrough-footnote>We use a simple <walkthrough-editor-open-file filePath="app/main.go">Go application</walkthrough-editor-open-file> and reference it as an <walkthrough-editor-select-line filePath="skaffold.yaml" startLine="6" startCharacterOffset="4" endLine="8" endCharacterOffset="0">artifact</walkthrough-editor-select-line> called app in our skaffold.yaml.
To use the base artifact as the custom run image we:
app artifact on the base artifact.app artifact to be the base artifact.Run this command and Skaffold should take care of building the artifacts in order and deploying the provided <walkthrough-editor-open-file filePath="k8s/web.yaml">manifest</walkthrough-editor-open-file>.
skaffold dev --port-forward
Once the image has been built and deployed click on the <walkthrough-web-preview-icon></walkthrough-web-preview-icon> icon and select Preview on port 8080. This should redirect to the running service and show the output:
Hello, World!
The Go app reads <walkthrough-editor-open-file filePath="base/hello.txt">hello.txt</walkthrough-editor-open-file> that's provided by the base artifact. Lets change the text from <walkthrough-editor-select-line filePath="base/hello.txt" startLine="0" startCharacterOffset="0" endLine="1" endCharacterOffset="0">Hello, World!</walkthrough-editor-select-line> to Hello, Buildpacks!. This should trigger a rebuild of the base artifact which in turn triggers a rebuild and redeploy for the app artifact. Once that completes click on the <walkthrough-web-preview-icon></walkthrough-web-preview-icon> icon again and select Preview on port 8080. This should redirect to the running service and show the output:
Hello, Buildpacks!
<walkthrough-conclusion-trophy></walkthrough-conclusion-trophy>
All done!
You now know how to use Buildpacks with custom run images and use Skaffold to tie the loop together.