Skip to content

Commit 9321e0e

Browse files
committed
Add "Prune intermediate container images" proposal
Add "Prune intermediate container images" enhancement proposal.
1 parent cd27374 commit 9321e0e

File tree

1 file changed

+143
-0
lines changed

1 file changed

+143
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
<!--
2+
Copyright The Shipwright Contributors
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
-->
6+
7+
---
8+
title: prune-intermediate-container-images
9+
authors:
10+
- "@HeavyWombat"
11+
reviewers:
12+
- "@qu1queee"
13+
- "@SaschaSchwarze0"
14+
- "@adambkaplan"
15+
approvers:
16+
- "@qu1queee"
17+
- "@SaschaSchwarze0"
18+
- "@adambkaplan"
19+
creation-date: 2024-07-04
20+
last-updated: 2024-07-04
21+
status: implementable
22+
see-also:
23+
- "/ships/0026-shipwright-managed-push.md"
24+
replaces:
25+
superseded-by:
26+
---
27+
28+
# Prune intermediate container images
29+
30+
## Release Signoff Checklist
31+
32+
- [X] Enhancement is `implementable`
33+
- [ ] Design details are appropriately documented from clear requirements
34+
- [ ] Test plan is defined
35+
- [ ] Graduation criteria for dev preview, tech preview, GA
36+
- [ ] User-facing documentation is created in [docs](/docs/)
37+
38+
## Open Questions [optional]
39+
40+
n/a
41+
42+
## Summary
43+
44+
Shipwright builds allow for (post) processing of container images as part of the build, previously called mutation of the image. This includes changes to the labels/annotations of an image or the image creation timestamp.
45+
46+
Depending on the actual build software (Buildpacks, BuildKit, etc.) the build itself can result in two images being pushed to the container registry, which is sometimes also referred to as a double push. This is due to the fact that for example Paketo Buildpacks builds don't have an option to store the container image on disk during the build for which there are very good reasons. However, this results in any post processing to require to obtain the image content in the build pod via a pull. Subsequently, changing image metadata and pushing it to the target location leads to a second push and therefore also two images in the container registry.
47+
48+
The following excerpt from a build shows the additional loading of the image (image pull) followed by an image push.
49+
50+
```text
51+
Loading the image from the registry "registry.com/namespace/image-name:latest"
52+
Loaded single image
53+
Mutating the image timestamp
54+
Pushing the image to registry "registry.com/namespace/image-name:latest"
55+
Image registry.com/namespace/image-name:latest@sha256:2302fa7c3af6599a62cb33a79260cbeb0e091657de40a3c63a2f3633dd455874 pushed
56+
```
57+
58+
Since the final push will use the same tag, the first image that was pushed will be untagged.
59+
60+
## Motivation
61+
62+
Conceptionally, there are two paths that we can follow to improve on the situation:
63+
64+
- Avoid the first push to the target registry all together by introducing a temporary intermediate container registry in which the image is being pushed. Shipwright would then only push to the configured target registry once everything is done. This however will increase the resource requirements of a build and will also result in a performance degredation, since the image needs to be pushed to the intermediate registry, which will be fast, but still require time.
65+
- Mitigate the storage effects of the double push by cleaning up the first container image that was pushed in case post processing results in a second container image.
66+
67+
This enhancement proposal is about the later one.
68+
69+
### Goals
70+
71+
Users will not have two images in their container registry when a double push scenario occurrs.
72+
73+
### Non-Goals
74+
75+
Avoid having two container images in the target registry.
76+
77+
## Proposal
78+
79+
Introduce additional configuration settings in the BuildSpec that enables the possibility to remove the untagged image.
80+
81+
### User Stories
82+
83+
#### Story 1
84+
85+
User can define a setting so that the untagged image from the first push will be pruned.
86+
87+
#### Story 2
88+
89+
User can use Shipwright as-is with the same behavior as before, but end up with an untagged image.
90+
91+
### Implementation Notes
92+
93+
Add `PruneUntaggedImage` to define whether intermediate output images should be pruned. It defaults to `false`, which is the current behavior of doing nothing with the additional image.
94+
95+
```yaml
96+
apiVersion: shipwright.io/v1beta1
97+
kind: Build
98+
metadata:
99+
name: buildpack-nodejs-build
100+
spec:
101+
source:
102+
type: Git
103+
git:
104+
url: https://github.com/shipwright-io/sample-nodejs
105+
contextDir: source-build
106+
strategy:
107+
name: buildpacks-v3
108+
kind: ClusterBuildStrategy
109+
output:
110+
image: image-registry.openshift-image-registry.svc:5000/build-examples/taxi-app
111+
timestamp: SourceTimestamp
112+
pruneUntaggedImage: true
113+
```
114+
115+
### Test Plan
116+
117+
This feature can only be tested in an E2E test case, since it requires a container registry.
118+
119+
Run a build with default settings and verify that there are two images being created.
120+
121+
Run a build with pruning of untagged images and verify that there is only one image in the registry.
122+
123+
### Release Criteria
124+
125+
n/a
126+
127+
### Risks and Mitigations
128+
129+
## Drawbacks
130+
131+
This is only a mitigtion, there will be still an addtional image in the container registry for a brief moment.
132+
133+
## Alternatives
134+
135+
As touched briefly in the beginning, the alternative would be to rewrite the build in such a way that an additional intermediate container registry can be used. This additional registry doesn't necessarily have to be a temporary registry that is deployed in the build pod or along with the build, but could be a standalone container registry that needs to be configured and acts as a temporary location. However, this approach requires a significant more planning work and additional enhancement proposal to clarify the requirements.
136+
137+
## Infrastructure Needed
138+
139+
n/a
140+
141+
## Implementation History
142+
143+
_Major milestones in the life cycle of a proposal should be tracked in `Implementation History`._

0 commit comments

Comments
 (0)