You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When adding verbiage for restriction on duplicate entries in the tar
archive, it was not immediately clear where this information would be
organized.
This revamp seeks to make the document on the whole more suitable for
implementors and be interpretable for compliance.
Signed-off-by: Vincent Batts <[email protected]>
Copy file name to clipboardExpand all lines: layer.md
+93-33Lines changed: 93 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,63 +1,109 @@
1
-
# Creating an Image Filesystem Changeset
1
+
# Filesystem Layer Changeset
2
2
3
-
An example of creating an Image Filesystem Changeset follows.
3
+
A layer changeset is the distributable difference between filesystems.
4
+
A layer changeset is not directly extracted, but applied to a filesystem.
4
5
5
-
An image root filesystem is first created as an empty directory.
6
-
Here is the initial empty directory structure for a changeset using the randomly-generated directory name `c3167915dc9d` ([actual layer DiffIDs are generated based on the content](#id_desc)).
6
+
## Distributable Format
7
+
8
+
Layer Changesets for the [mediatype](./media-types.md)`application/vnd.oci.image.layer.tar+gzip` MUST be packaged in [tar archive][tar-archive].
9
+
Layer Changesets for the [mediatype](./media-types.md)`application/vnd.oci.image.layer.tar+gzip` MUST NOT include duplicate entries for file paths in the resulting [tar archive][tar-archive].
10
+
11
+
## Change Types
12
+
13
+
Types of changes that can occur in a changeset are:
14
+
15
+
* Additions
16
+
* Modifications
17
+
* Removals
18
+
19
+
Additions and Modifications are reflected the same in the changeset tar archive.
20
+
21
+
Removals are reflected using "[whiteout](#whiteouts)" file entries (See [Representing Changes](#representing-changes)).
22
+
23
+
## Creating
24
+
25
+
### Initial Root Filesystem
26
+
27
+
An image root filesystem has an initial state as an empty directory.
28
+
The name of the directory is not relevant to the layer itself, only for the purpose of producing comparisons.
29
+
30
+
Here is an initial empty directory structure for a changeset, with a unique directory name `rootfs-c9d-v1`.
7
31
8
32
```
9
-
c3167915dc9d/
33
+
rootfs-c9d-v1/
10
34
```
11
35
36
+
### Populate Initial Filesystem
37
+
12
38
Files and directories are then created:
13
39
14
40
```
15
-
c3167915dc9d/
41
+
rootfs-c9d-v1/
16
42
etc/
17
43
my-app-config
18
44
bin/
19
45
my-app-binary
20
46
my-app-tools
21
47
```
22
48
23
-
The `c3167915dc9d` directory is then committed as a plain Tar archive with entries for the following files:
49
+
The `rootfs-c9d-v1` directory is then committed as a plain [Tar archive][tar-archive] with relative path to `rootfs-c9d-v1`.
50
+
Entries for the following files:
24
51
25
52
```
26
-
etc/my-app-config
27
-
bin/my-app-binary
28
-
bin/my-app-tools
53
+
./
54
+
./etc/
55
+
./etc/my-app-config
56
+
./bin/
57
+
./bin/my-app-binary
58
+
./bin/my-app-tools
29
59
```
30
60
31
-
To make changes to the filesystem of this container image, create a new directory, such as `f60c56784b83`, and initialize it with a snapshot of the parent image's root filesystem, so that the directory is identical to that of `c3167915dc9d`.
32
-
NOTE: a copy-on-write or union filesystem can make this very efficient:
61
+
### Populate a Comparison Filesystem
62
+
63
+
Create a new directory and initialize it with an identical copy or snapshot of the prior root filesystem.
64
+
Any changes to the snapshot MUST not change or affect the directory it was copied from.
65
+
66
+
For example `rootfs-c9d-v1.s1` is an identical snapshot of `rootfs-c9d-v1`.
67
+
In this way `rootfs-c9d-v1.s1` is prepared for updates and alterations.
68
+
69
+
**NOTE**: *a copy-on-write or union filesystem can efficiently make directory snapshots*
70
+
71
+
Initial layout of the snapshot:
33
72
34
73
```
35
-
f60c56784b83/
74
+
rootfs-c9d-v1.s1/
36
75
etc/
37
76
my-app-config
38
77
bin/
39
78
my-app-binary
40
79
my-app-tools
41
80
```
42
81
43
-
This example change is going to add a configuration directory at `/etc/my-app.d` which contains a default config file.
44
-
There's also a change to the `my-app-tools` binary to handle the config layout change.
45
-
The `f60c56784b83` directory then looks like this:
82
+
Changes include new files, file and path removals, and updates to file attributes (mtime, uid, gid, mode, xattrs, etc.).
83
+
84
+
For example, add a directory at `/etc/my-app.d` containing a default config file, removing the existing config file.
85
+
Also a change to the `./bin/my-app-tools` binary to handle the config layout change.
86
+
87
+
Following these changes, the representation of the `rootfs-c9d-v1.s1` directory:
46
88
47
89
```
48
-
f60c56784b83/
90
+
rootfs-c9d-v1.s1/
49
91
etc/
50
-
.wh.my-app-config
51
92
my-app.d/
52
93
default.cfg
53
94
bin/
54
95
my-app-binary
55
96
my-app-tools
56
97
```
57
98
58
-
This reflects the removal of `/etc/my-app-config` and creation of a file and directory at `/etc/my-app.d/default.cfg`.
59
-
`/bin/my-app-tools` has also been replaced with an updated version.
60
-
Before committing this directory to a changeset, because it has a parent image, it is first compared with the directory tree of the parent snapshot, `f60c56784b83`, looking for files and directories that have been added, modified, or removed.
99
+
### Determining Changes
100
+
101
+
When two directories are compared, the relative root is the top-level directory.
102
+
The directories are compared, looking for files that have been added, modified, or removed.
103
+
Where "files" includes regular files, directories, sockets, symbolic links, block devices, character devices and FIFOs.
104
+
105
+
For this example, `rootfs-c9d-v1/` and `rootfs-c9d-v1.s1/` are recursively compared, each as relative root path.
106
+
61
107
The following changeset is found:
62
108
63
109
```
@@ -66,23 +112,33 @@ Modified: /bin/my-app-tools
66
112
Deleted: /etc/my-app-config
67
113
```
68
114
69
-
A Tar Archive is then created which contains *only* this changeset:
115
+
This reflects the removal of `/etc/my-app-config` and creation of a file and directory at `/etc/my-app.d/default.cfg`.
116
+
`/bin/my-app-tools` has also been replaced with an updated version.
70
117
71
-
- Added and modified files and directories in their entirety
72
-
- Deleted files or directory marked with a whiteout file
118
+
### Representing Changes
73
119
74
-
A whiteout file is an empty file that prefixes the deleted paths basename `.wh.`.
75
-
When a whiteout is found in the upper changeset of a filesystem, any matching name in the lower changeset is ignored, and the whiteout itself is also hidden.
76
-
As files prefixed with `.wh.` are special whiteout tombstones it is not possible to create a filesystem which has a file or directory with a name beginning with `.wh.`.
120
+
A [tar archive][tar-archive] is then created which contains *only* this changeset:
77
121
78
-
The resulting Tar archive for `f60c56784b83` has the following entries:
122
+
- Added and modified files and directories in their entirety
123
+
- Deleted files or directory marked with a [whiteout file](#whiteouts)
124
+
125
+
The resulting Tar archive for `rootfs-c9d-v1.s1` has the following entries:
79
126
80
127
```
81
-
/etc/my-app.d/default.cfg
82
-
/bin/my-app-tools
83
-
/etc/.wh.my-app-config
128
+
./etc/my-app.d/
129
+
./etc/my-app.d/default.cfg
130
+
./bin/my-app-tools
131
+
./etc/.wh.my-app-config
84
132
```
85
133
134
+
## Applying
135
+
136
+
## Whiteouts
137
+
138
+
A whiteout file is an empty file that prefixes the deleted paths basename with `.wh.`.
139
+
As files prefixed with `.wh.` are special whiteout markers, it is not possible to create a filesystem which has a file or directory with a name beginning with `.wh.`.
140
+
When a whiteout is found in the upper changeset of a filesystem, any matching name in the lower changeset is ignored, and the whiteout itself is also hidden.
141
+
86
142
Whiteout files MUST only apply to resources in lower layers.
87
143
Files that are present in the same layer as a whiteout file can only be hidden by whiteout files in subsequent layers.
88
144
The following is a base layer with several resources:
@@ -117,6 +173,8 @@ a/.wh..wh..opq
117
173
118
174
Implementations SHOULD generate layers such that the whiteout files appear before sibling directory entries.
119
175
176
+
### Opaque Whiteout
177
+
120
178
In addition to expressing that a single entry should be removed from a lower layer, layers may remove all of the children using an opaque whiteout entry.
121
179
An opaque whiteout entry is a file with the name `.wh..wh..opq` indicating that all siblings are hidden in the lower layer.
122
180
Let's take the following base layer as an example:
@@ -139,7 +197,7 @@ bin/
139
197
```
140
198
141
199
This is called _opaque whiteout_ format.
142
-
An _opaque whiteout_ file hides _all_ children of the `bin/` including sub-directories and all descendents.
200
+
An _opaque whiteout_ file hides _all_ children of the `bin/` including sub-directories and all descendants.
143
201
Using _explicit whiteout_ files, this would be equivalent to the following:
144
202
145
203
```
@@ -151,8 +209,10 @@ bin/
151
209
152
210
In this case, a unique whiteout file is generated for each entry.
153
211
If there were more children of `bin/` in the base layer, there would be an entry for each.
154
-
Note that this opaque file will apply to _all_ children, including sub-directories, other resources and all descendents.
212
+
Note that this opaque file will apply to _all_ children, including sub-directories, other resources and all descendants.
155
213
156
214
Implementations SHOULD generate layers using _explicit whiteout_ files, but MUST accept both.
157
215
158
216
Any given image is likely to be composed of several of these Image Filesystem Changeset tar archives.
0 commit comments