In this document, we will discuss the outputs and metadata of the project “docker/build-push-action”, which is a GitHub action for building and pushing Docker images.
Build Outputs
The docker/build-push-action
provides several outputs that can be used in subsequent steps of the workflow. The available outputs are:
name
: The name of the builder.version
: The version of the builder.platforms
: A list of platforms that the builder supports.digest
: The digest of the built image.tags
: A list of tags associated with the built image.
Here’s an example of how to use these outputs:
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
builder: ${{ steps.buildx.outputs.name }}
push: true
tags: bengotch/simplewhale:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Use the output
run: |
echo "The name of the builder is ${{ steps.docker_build.outputs.name }}"
echo "The digest of the built image is ${{ steps.docker_build.outputs.digest }}"
echo "The tags of the built image are ${{ steps.docker_build.outputs.tags }}"
Interpreting the Build Summary
The docker/build-push-action
provides a detailed build summary that includes information about the build stages, build cache hits, and the time taken for each stage. Here’s an example of a build summary:
Building image 'bengotch/simplewhale:latest'
Step 1/5 : FROM node:14-alpine
---> 8123456789ab
Step 2/5 : WORKDIR /app
---> Using cache
---> 0123456789ab
Step 3/5 : COPY package*.json ./
---> Using cache
---> 234567890123
Step 4/5 : RUN npm install
---> Running in 123456789012
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^2.1.2 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
added 10 packages from 10 contributors and audited 10 packages in 1.318s
found 0 vulnerabilities
Removing intermediate container 123456789012
---> 345678901234
Step 5/5 : CMD [ "node", "server.js" ]
---> Running in 234567890123
Removing intermediate container 234567890123
---> 456789012345
Successfully built 456789012345
Successfully tagged bengotch/simplewhale:latest
In this example, we can see that the build consists of five steps. The first step is to pull the base image node:14-alpine
. The second step is to set the working directory to /app
. The third step is to copy the package.json
file to the working directory. The fourth step is to install the dependencies using npm install
. The fifth and final step is to set the command to run the application.
We can also see that the second and third steps used the build cache, which resulted in faster build times.
Downloadable Build Record
The docker/build-push-action
provides a downloadable build record in JSON format that contains detailed information about the build, including the build stages, build cache hits, and the time taken for each stage.
Here’s an example of a build record:
{
"aux": {
"events": [
{
"id": "0",
"status": "started",
"time": 1633012345
},
{
"id": "1",
"status": "completed",
"time": 1633012345,
"action": {
"id": "0",
"name": "pull",
"description": "Pulling image: node:14-alpine"
}
},
{
"id": "2",
"status": "started",
"time": 1633012345
},
{
"id": "3",
"status": "completed",
"time": 1633012345,
"action": {
"id": "1",
"name": "set-working-dir",
"description": "Setting the working directory to /app"
}
},
{
"id": "4",
"status": "started",
"time": 1633012345
},
{
"id": "5",
"status": "completed",
"time": 1633012345,
"action": {
"id": "2",
"name": "copy",
"description": "Copying package*.json to /app"
}
},
{
"id": "6",
"status": "started",
"time": 1633012345
},
{
"id": "7",
"status": "completed",
"time": 1633012345,
"action": {
"id": "3",
"name": "run",
"description": "Running command: npm install"
}
},
{
"id": "8",
"status": "started",
"time": 1633012345
},
{
"id": "9",
"status": "completed",
"time": 1633012345,
"action": {
"id": "4",
"name": "set-cmd",
"description": "Setting command to [\"node\", \"server.js\"]"
}
},
{
"id": "10",
"status": "completed",
"time": 1633012345,
"action": {
"id": "5",
"name": "build",
"description": "Building image: bengotch/simplewhale:latest"
}
}
]
},
"config": {
"digest": "sha256:1234567890123456789012345678901234567890123456789012345678901234",
"tags": [
"bengotch/simplewhale:latest"
],
"history": [
{
"created": "2021-09-30T12:30:45.123456789+00:00",
"createdBy": "/bin/sh -c #(nop) CMD [\"node\", \"server.js\"]",
"emptyLayer": true
},
{
"created": "2021-09-30T12:30:45.123456789+00:00