@wtf/release-oci 0.0.0-stage → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +136 -2
- package/dist/ecosystem.d.ts +74 -0
- package/dist/ecosystem.d.ts.map +1 -0
- package/dist/ecosystem.js +61 -0
- package/dist/ecosystem.js.map +1 -0
- package/dist/errors.d.ts +31 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +29 -0
- package/dist/errors.js.map +1 -0
- package/dist/images.d.ts +87 -0
- package/dist/images.d.ts.map +1 -0
- package/dist/images.js +124 -0
- package/dist/images.js.map +1 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/publish.d.ts +105 -0
- package/dist/publish.d.ts.map +1 -0
- package/dist/publish.js +184 -0
- package/dist/publish.js.map +1 -0
- package/dist/registry.d.ts +46 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +36 -0
- package/dist/registry.js.map +1 -0
- package/dist/tags.d.ts +43 -0
- package/dist/tags.d.ts.map +1 -0
- package/dist/tags.js +78 -0
- package/dist/tags.js.map +1 -0
- package/package.json +81 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The OCI images of a repo released in trains, of no release tool and no rebuild. Its default export
|
|
3
|
+
* is the ecosystem of OCI images, `ociEcosystem` of `./ecosystem`, which a config of the trains
|
|
4
|
+
* names in `ecosystems` as `'@wtf/release-oci'`, so the trains read the images of the repo by it;
|
|
5
|
+
* and this module holds the type of an image, which the modules of this package do with: the
|
|
6
|
+
* images of the repo, each folder of a Dockerfile, a Containerfile or a
|
|
7
|
+
* `.devcontainer/devcontainer.json` (`./images`), the tags of a release (`./tags`), the tested image
|
|
8
|
+
* of each copied to them by crane (`./publish`), and the page of each in the container registry of
|
|
9
|
+
* GitLab (`./registry`). An image is built and tested by its own pipeline; a release copies the
|
|
10
|
+
* image it tested, by its digest, to the tags of its version, so the bytes released are the bytes
|
|
11
|
+
* tested. Each function takes the `System` it runs by, and runs `git` and `crane` through it.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import type { OciImage } from '@wtf/release-oci'
|
|
15
|
+
*
|
|
16
|
+
* // The repositories of the images, as a release lists them.
|
|
17
|
+
* export const repositoriesOf = (images: readonly OciImage[]): (string | undefined)[] =>
|
|
18
|
+
* images.map(({ repository }) => repository)
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @packageDocumentation
|
|
22
|
+
* @module @wtf/release-oci
|
|
23
|
+
*/
|
|
24
|
+
import { ociEcosystem } from "./ecosystem.js";
|
|
25
|
+
/** The ecosystem of OCI images, which a config of the trains names as `'@wtf/release-oci'`. */
|
|
26
|
+
export default ociEcosystem;
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAmB7C,+FAA+F;AAC/F,eAAe,YAAY,CAAA"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { type GitContext } from '@wtf/release-system/git';
|
|
2
|
+
/** The tested image of a release: its repository and its tag, as the pipeline that tested it wrote it. */
|
|
3
|
+
export interface OciSource {
|
|
4
|
+
/** Its repository, as `registry.gitlab.com/acme/images/base/snapshot`. */
|
|
5
|
+
readonly repository: string;
|
|
6
|
+
/** Its tag, as `base-v1-4-2`. */
|
|
7
|
+
readonly tag: string;
|
|
8
|
+
}
|
|
9
|
+
/** An image of a release: its repository, and the tested image a release copies to its tags. */
|
|
10
|
+
export interface ImageToPublish {
|
|
11
|
+
/** The repository of the image, as `registry.gitlab.com/acme/images/base`. */
|
|
12
|
+
readonly repository: string;
|
|
13
|
+
/** The tested image, which the release copies. */
|
|
14
|
+
readonly source: OciSource;
|
|
15
|
+
}
|
|
16
|
+
/** Where crane runs: the folder, the environment and the system, and the command of crane. */
|
|
17
|
+
export interface CraneContext extends GitContext {
|
|
18
|
+
/** The command of crane, by its name on the path or its path: `crane` by default. */
|
|
19
|
+
readonly crane?: string | undefined;
|
|
20
|
+
}
|
|
21
|
+
/** The tested image of an image, as the registry has it. */
|
|
22
|
+
export interface SmokedImage extends ImageToPublish {
|
|
23
|
+
/** The digest of the source, as `sha256:…`. */
|
|
24
|
+
readonly digest: string;
|
|
25
|
+
/** The platforms it is of, as `linux/amd64`: none of an image of one manifest of no index. */
|
|
26
|
+
readonly platforms: readonly string[];
|
|
27
|
+
}
|
|
28
|
+
/** An image of a release published: each tag copied, and each the registry had already. */
|
|
29
|
+
export interface PublishedImage extends SmokedImage {
|
|
30
|
+
/** The version of the release, as `1.4.2`. */
|
|
31
|
+
readonly version: string;
|
|
32
|
+
/** Each tag the release copied the source to, the version's first. */
|
|
33
|
+
readonly tags: readonly string[];
|
|
34
|
+
/** Each tag the registry had already at the digest of the source, and the release skipped. */
|
|
35
|
+
readonly skipped: readonly string[];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The digest of the image `ref`, as `crane digest` gives it: none of a repository or a tag the
|
|
39
|
+
* registry has not.
|
|
40
|
+
*
|
|
41
|
+
* @param ref - The reference of the image, as `registry.example/a:1.4.2`.
|
|
42
|
+
* @param context - Where crane runs, and its command.
|
|
43
|
+
* @returns The digest, as `sha256:…`; none of an image the registry has not.
|
|
44
|
+
* @throws `EOCISMOKE` of a registry crane cannot ask, as of no credentials.
|
|
45
|
+
*/
|
|
46
|
+
export declare function digestOf(ref: string, context: CraneContext): Promise<string | undefined>;
|
|
47
|
+
/**
|
|
48
|
+
* The platforms of the image `ref` at `digest`: of an index, each manifest's `os/architecture` and
|
|
49
|
+
* variant, of `crane manifest`; of a manifest of no index, none.
|
|
50
|
+
*
|
|
51
|
+
* @param ref - The repository of the image, as `registry.example/a`.
|
|
52
|
+
* @param digest - Its digest, as `sha256:…`.
|
|
53
|
+
* @param context - Where crane runs, and its command.
|
|
54
|
+
* @returns The platforms, as `['linux/amd64', 'linux/arm64']`.
|
|
55
|
+
* @throws `EOCISMOKE` of a manifest crane cannot give, or that is no JSON.
|
|
56
|
+
*/
|
|
57
|
+
export declare function platformsOf(ref: string, digest: string, context: CraneContext): Promise<string[]>;
|
|
58
|
+
/**
|
|
59
|
+
* The tested image of each image of a release, as the registry has it: its digest and its
|
|
60
|
+
* platforms. Throws, together, `EOCISMOKE` of each source the registry has not, or of fewer
|
|
61
|
+
* platforms than `platforms` names.
|
|
62
|
+
*
|
|
63
|
+
* @param images - The images of the release, each of its source.
|
|
64
|
+
* @param context - Where crane runs, and its command.
|
|
65
|
+
* @param platforms - The platforms each source must be of, as `['linux/amd64']`: any by default.
|
|
66
|
+
* @returns Each image, of the digest and the platforms of its source.
|
|
67
|
+
*/
|
|
68
|
+
export declare function smokeImages(images: readonly ImageToPublish[], context: CraneContext, platforms?: readonly string[]): Promise<SmokedImage[]>;
|
|
69
|
+
/** What {@link publishImages} publishes. */
|
|
70
|
+
export interface ImagesRelease {
|
|
71
|
+
/** Where crane runs, and its command. */
|
|
72
|
+
readonly context: CraneContext;
|
|
73
|
+
/** The images of the release, each of its source. */
|
|
74
|
+
readonly images: readonly ImageToPublish[];
|
|
75
|
+
/**
|
|
76
|
+
* The version of the release, its tag, which is copied once and never moved: `1.4.2`, or of a
|
|
77
|
+
* version that is no semver, `12.12-wtf.1`. A tag of an image, `[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}`.
|
|
78
|
+
*/
|
|
79
|
+
readonly version: string;
|
|
80
|
+
/**
|
|
81
|
+
* The tags that move to each release of their line, copied on every run, as `['1.4', '1']`, which
|
|
82
|
+
* `releaseTagsOf` of `./tags` gives of a semver version, or `['12.12', 'latest']`: none of `[]`.
|
|
83
|
+
*/
|
|
84
|
+
readonly moving: readonly string[];
|
|
85
|
+
/** The platforms each source must be of: any by default. */
|
|
86
|
+
readonly platforms?: readonly string[] | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* Where the steps are said, a line each.
|
|
89
|
+
*
|
|
90
|
+
* @param line - The line.
|
|
91
|
+
*/
|
|
92
|
+
readonly log?: ((line: string) => void) | undefined;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The images of a release published: each source smoked ({@link smokeImages}), then copied by its
|
|
96
|
+
* digest to the tag of the version, of an image the registry has not at it, and to each moving tag:
|
|
97
|
+
* the tags the release gives. Throws a `TypeError` of a tag an image cannot have, or of one given
|
|
98
|
+
* twice, before it asks the registry anything; then, together, `EOCIRETAG` of each image whose version the registry has at another digest,
|
|
99
|
+
* before anything is copied; and `EOCITAG` of a copy crane cannot make.
|
|
100
|
+
*
|
|
101
|
+
* @param release - The images, the version and the tags that move, and where crane runs.
|
|
102
|
+
* @returns Each image, of the tags copied and skipped.
|
|
103
|
+
*/
|
|
104
|
+
export declare function publishImages(release: ImagesRelease): Promise<PublishedImage[]>;
|
|
105
|
+
//# sourceMappingURL=publish.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":"AAsCA,OAAO,EAAE,KAAK,UAAU,EAAS,MAAM,yBAAyB,CAAA;AAKhE,0GAA0G;AAC1G,MAAM,WAAW,SAAS;IACxB,0EAA0E;IAC1E,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,iCAAiC;IACjC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CACrB;AAED,gGAAgG;AAChG,MAAM,WAAW,cAAc;IAC7B,8EAA8E;IAC9E,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,kDAAkD;IAClD,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAA;CAC3B;AAED,8FAA8F;AA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,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;IAClC,4DAA4D;IAC5D,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAA;IAClD;;;;OAIG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAA;CACpD;AAED;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAiDrF"}
|
package/dist/publish.js
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The images of a release published, of no rebuild, by crane: {@link smokeImages} finds the tested
|
|
3
|
+
* image of each, its source, by its digest, and the platforms it is of; {@link publishImages} copies
|
|
4
|
+
* that digest to each tag of the release, `crane copy <source>@<digest> <image>:<tag>`, which mounts
|
|
5
|
+
* each blob of the source's repository rather than moving it. The tag of the version is copied once:
|
|
6
|
+
* a registry that has it at the same digest is skipped, so a release that stopped part way is
|
|
7
|
+
* finished by running it again, and at another digest is refused (`EOCIRETAG`), as a released
|
|
8
|
+
* version never moves. The moving tags the release gives, as `1.4` and `1`, of `releaseTagsOf` of
|
|
9
|
+
* `./tags`, or `12.12` and `latest` of a version that is no semver, as `12.12-wtf.1`, are copied
|
|
10
|
+
* every time.
|
|
11
|
+
*
|
|
12
|
+
* crane runs by the `System` it is given, of the environment it is given: it reads the credentials
|
|
13
|
+
* of the registry of its own config, as `crane auth login` writes it, or of the docker config.
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { publishImages } from '@wtf/release-oci/publish'
|
|
17
|
+
* import { releaseTagsOf } from '@wtf/release-oci/tags'
|
|
18
|
+
* import type { System } from '@wtf/release-system'
|
|
19
|
+
*
|
|
20
|
+
* export async function release(system: System): Promise<void> {
|
|
21
|
+
* await publishImages({
|
|
22
|
+
* context: { system },
|
|
23
|
+
* images: [
|
|
24
|
+
* {
|
|
25
|
+
* repository: 'registry.gitlab.com/acme/images/base',
|
|
26
|
+
* source: { repository: 'registry.gitlab.com/acme/images/base/snapshot', tag: 'base-v1-4-2' }
|
|
27
|
+
* }
|
|
28
|
+
* ],
|
|
29
|
+
* version: '1.4.2',
|
|
30
|
+
* moving: releaseTagsOf('1.4.2').moving
|
|
31
|
+
* })
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @packageDocumentation
|
|
36
|
+
* @module @wtf/release-oci/publish
|
|
37
|
+
*/
|
|
38
|
+
import { throwAll } from '@wtf/release-system/errors';
|
|
39
|
+
import { gitOf } from '@wtf/release-system/git';
|
|
40
|
+
import { OciError } from "./errors.js";
|
|
41
|
+
import { checkReleaseTags } from "./tags.js";
|
|
42
|
+
/** The reference of a source, of its repository and its tag. */
|
|
43
|
+
const sourceRef = ({ repository, tag }) => `${repository}:${tag}`;
|
|
44
|
+
/** Whether crane said the registry has no such repository or manifest. */
|
|
45
|
+
const isAbsent = (stderr) => /MANIFEST_UNKNOWN|NAME_UNKNOWN|NOT_FOUND|not found|404/i.test(stderr);
|
|
46
|
+
/** The command of crane of `context`. */
|
|
47
|
+
const craneOf = (context) => context.crane ?? 'crane';
|
|
48
|
+
/**
|
|
49
|
+
* Runs crane with `args`, in the folder and the environment of `context`.
|
|
50
|
+
*
|
|
51
|
+
* @param args - The arguments of crane, as `['digest', 'registry.example/a:1']`.
|
|
52
|
+
* @param context - Where crane runs, and its command.
|
|
53
|
+
* @returns What crane wrote, and its exit code.
|
|
54
|
+
*/
|
|
55
|
+
async function crane(args, context) {
|
|
56
|
+
const { cwd, env, system } = gitOf(context);
|
|
57
|
+
return system.exec(craneOf(context), args, { cwd, env });
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The digest of the image `ref`, as `crane digest` gives it: none of a repository or a tag the
|
|
61
|
+
* registry has not.
|
|
62
|
+
*
|
|
63
|
+
* @param ref - The reference of the image, as `registry.example/a:1.4.2`.
|
|
64
|
+
* @param context - Where crane runs, and its command.
|
|
65
|
+
* @returns The digest, as `sha256:…`; none of an image the registry has not.
|
|
66
|
+
* @throws `EOCISMOKE` of a registry crane cannot ask, as of no credentials.
|
|
67
|
+
*/
|
|
68
|
+
export async function digestOf(ref, context) {
|
|
69
|
+
const { stdout, stderr, code } = await crane(['digest', ref], context);
|
|
70
|
+
if (code === 0 && stdout.trim() !== '')
|
|
71
|
+
return stdout.trim();
|
|
72
|
+
if (isAbsent(stderr))
|
|
73
|
+
return undefined;
|
|
74
|
+
throw new OciError('EOCISMOKE', `crane cannot ask the registry for ${ref}: ${stderr.trim() || `exit code ${code}`}`, 'Log crane in to the registry, as `crane auth login`, of a token that may read the repository, and check that crane is on the path of the run.');
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The platforms of the image `ref` at `digest`: of an index, each manifest's `os/architecture` and
|
|
78
|
+
* variant, of `crane manifest`; of a manifest of no index, none.
|
|
79
|
+
*
|
|
80
|
+
* @param ref - The repository of the image, as `registry.example/a`.
|
|
81
|
+
* @param digest - Its digest, as `sha256:…`.
|
|
82
|
+
* @param context - Where crane runs, and its command.
|
|
83
|
+
* @returns The platforms, as `['linux/amd64', 'linux/arm64']`.
|
|
84
|
+
* @throws `EOCISMOKE` of a manifest crane cannot give, or that is no JSON.
|
|
85
|
+
*/
|
|
86
|
+
export async function platformsOf(ref, digest, context) {
|
|
87
|
+
const { stdout, stderr, code } = await crane(['manifest', `${ref}@${digest}`], context);
|
|
88
|
+
let manifest;
|
|
89
|
+
try {
|
|
90
|
+
if (code !== 0)
|
|
91
|
+
throw new Error(stderr.trim() || `exit code ${code}`);
|
|
92
|
+
manifest = JSON.parse(stdout);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
throw new OciError('EOCISMOKE', `crane cannot give the manifest of ${ref}@${digest}: ${error.message}`, 'Check that the registry has the image, and that crane may read it.');
|
|
96
|
+
}
|
|
97
|
+
return (manifest.manifests ?? []).flatMap(({ platform }) => {
|
|
98
|
+
if (platform?.['os'] === undefined || platform['architecture'] === undefined)
|
|
99
|
+
return [];
|
|
100
|
+
if (platform['os'] === 'unknown')
|
|
101
|
+
return [];
|
|
102
|
+
const variant = platform['variant'] === undefined ? '' : `/${platform['variant']}`;
|
|
103
|
+
return [`${platform['os']}/${platform['architecture']}${variant}`];
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The tested image of each image of a release, as the registry has it: its digest and its
|
|
108
|
+
* platforms. Throws, together, `EOCISMOKE` of each source the registry has not, or of fewer
|
|
109
|
+
* platforms than `platforms` names.
|
|
110
|
+
*
|
|
111
|
+
* @param images - The images of the release, each of its source.
|
|
112
|
+
* @param context - Where crane runs, and its command.
|
|
113
|
+
* @param platforms - The platforms each source must be of, as `['linux/amd64']`: any by default.
|
|
114
|
+
* @returns Each image, of the digest and the platforms of its source.
|
|
115
|
+
*/
|
|
116
|
+
export async function smokeImages(images, context, platforms = []) {
|
|
117
|
+
const errors = [];
|
|
118
|
+
const smoked = [];
|
|
119
|
+
for (const image of images) {
|
|
120
|
+
// oxlint-disable-next-line no-await-in-loop -- crane asks the registry one image at a time
|
|
121
|
+
const digest = await digestOf(sourceRef(image.source), context);
|
|
122
|
+
if (digest === undefined) {
|
|
123
|
+
errors.push(new OciError('EOCISMOKE', `The registry has no ${sourceRef(image.source)}, the tested image of ${image.repository}.`, 'Build and test the image in the pipeline of the release before it publishes, as the devcontainer component does of a tag, or give the plugin the `sourceRepository` and the `sourceTag` the pipeline pushes it as.'));
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
// oxlint-disable-next-line no-await-in-loop -- crane asks the registry one image at a time
|
|
127
|
+
const of = await platformsOf(image.source.repository, digest, context);
|
|
128
|
+
const missing = platforms.filter((platform) => of.length > 0 && !of.includes(platform));
|
|
129
|
+
if (missing.length > 0)
|
|
130
|
+
errors.push(new OciError('EOCISMOKE', `${sourceRef(image.source)} is of ${of.join(', ')}, and not of ${missing.join(', ')}.`, 'Build the image of each platform of the option `platforms`, or name fewer.'));
|
|
131
|
+
smoked.push({ ...image, digest, platforms: of });
|
|
132
|
+
}
|
|
133
|
+
throwAll(errors);
|
|
134
|
+
return smoked;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The images of a release published: each source smoked ({@link smokeImages}), then copied by its
|
|
138
|
+
* digest to the tag of the version, of an image the registry has not at it, and to each moving tag:
|
|
139
|
+
* the tags the release gives. Throws a `TypeError` of a tag an image cannot have, or of one given
|
|
140
|
+
* twice, before it asks the registry anything; then, together, `EOCIRETAG` of each image whose version the registry has at another digest,
|
|
141
|
+
* before anything is copied; and `EOCITAG` of a copy crane cannot make.
|
|
142
|
+
*
|
|
143
|
+
* @param release - The images, the version and the tags that move, and where crane runs.
|
|
144
|
+
* @returns Each image, of the tags copied and skipped.
|
|
145
|
+
*/
|
|
146
|
+
export async function publishImages(release) {
|
|
147
|
+
const { context } = release;
|
|
148
|
+
const log = release.log ?? (() => undefined);
|
|
149
|
+
const tags = checkReleaseTags({ version: release.version, moving: release.moving });
|
|
150
|
+
const smoked = await smokeImages(release.images, context, release.platforms ?? []);
|
|
151
|
+
const errors = [];
|
|
152
|
+
const has = new Map();
|
|
153
|
+
for (const image of smoked) {
|
|
154
|
+
// oxlint-disable-next-line no-await-in-loop -- crane asks the registry one image at a time
|
|
155
|
+
const at = await digestOf(`${image.repository}:${tags.version}`, context);
|
|
156
|
+
has.set(image.repository, at);
|
|
157
|
+
if (at !== undefined && at !== image.digest)
|
|
158
|
+
errors.push(new OciError('EOCIRETAG', `${image.repository}:${tags.version} is ${at} already, not ${image.digest}, the tested image of the release.`, 'Release a new version: a released version is never moved. Delete the tag in the registry yourself only where nothing pulls it yet.'));
|
|
159
|
+
}
|
|
160
|
+
throwAll(errors);
|
|
161
|
+
const published = [];
|
|
162
|
+
for (const image of smoked) {
|
|
163
|
+
const skipped = has.get(image.repository) === image.digest ? [tags.version] : [];
|
|
164
|
+
const copy = skipped.length > 0 ? tags.moving : [tags.version, ...tags.moving];
|
|
165
|
+
for (const tag of copy) {
|
|
166
|
+
const target = `${image.repository}:${tag}`;
|
|
167
|
+
// oxlint-disable-next-line no-await-in-loop -- one copy at a time, the version's first
|
|
168
|
+
const { stderr, code } = await crane(['copy', `${image.source.repository}@${image.digest}`, target], context);
|
|
169
|
+
if (code !== 0)
|
|
170
|
+
throw new OciError('EOCITAG', `crane cannot copy ${image.source.repository}@${image.digest} to ${target}: ${stderr.trim() || `exit code ${code}`}`, 'Check that crane is logged in to the registry of a token that may write the repository, and run the release of the tag again: what is published is skipped.');
|
|
171
|
+
log(`Copied ${image.digest} to ${target}.`);
|
|
172
|
+
}
|
|
173
|
+
for (const tag of skipped)
|
|
174
|
+
log(`${image.repository}:${tag} is ${image.digest} already.`);
|
|
175
|
+
published.push({
|
|
176
|
+
...image,
|
|
177
|
+
version: tags.version,
|
|
178
|
+
tags: [tags.version, ...tags.moving],
|
|
179
|
+
skipped
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
return published;
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=publish.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publish.js","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AACrD,OAAO,EAAmB,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAEhE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AA0C5C,gEAAgE;AAChE,MAAM,SAAS,GAAG,CAAC,EAAE,UAAU,EAAE,GAAG,EA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AAC,MAAM,CAAC;YACpC,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page of an image in the container registry of GitLab ({@link registryPageOf}), which the
|
|
3
|
+
* GitLab release of a tag links each image by: the Container Registry API of the project lists its
|
|
4
|
+
* repositories, `GET /projects/<id>/registry/repositories`, each of its `location`, as
|
|
5
|
+
* `registry.gitlab.com/acme/images/base`, and its ID, whose page is
|
|
6
|
+
* `<project>/container_registry/<id>`. An image is linked where it lives, never uploaded.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { registryPageOf } from '@wtf/release-oci/registry'
|
|
10
|
+
* import { gitlabHeadersOf, gitlabProjectOf } from '@wtf/release-trains/gitlab'
|
|
11
|
+
*
|
|
12
|
+
* const env = { CI_PROJECT_PATH: 'acme/images', GITLAB_TOKEN: 'token' }
|
|
13
|
+
* export const page = await registryPageOf({
|
|
14
|
+
* fetch,
|
|
15
|
+
* project: gitlabProjectOf({}, env, undefined),
|
|
16
|
+
* repository: 'registry.gitlab.com/acme/images/base',
|
|
17
|
+
* headers: gitlabHeadersOf(env)
|
|
18
|
+
* })
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @packageDocumentation
|
|
22
|
+
* @module @wtf/release-oci/registry
|
|
23
|
+
*/
|
|
24
|
+
import type { GitLabProject, HttpFetch } from '@wtf/release-trains/gitlab';
|
|
25
|
+
/** What {@link registryPageOf} looks up. */
|
|
26
|
+
export interface RegistryQuery {
|
|
27
|
+
/** The `fetch` the request is made by. */
|
|
28
|
+
readonly fetch: HttpFetch;
|
|
29
|
+
/** The project whose container registry holds the image. */
|
|
30
|
+
readonly project: GitLabProject;
|
|
31
|
+
/** The repository of the image, as `registry.gitlab.com/acme/images/base`. */
|
|
32
|
+
readonly repository: string;
|
|
33
|
+
/** The headers the request authenticates by: none of a public project. */
|
|
34
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The page of the image `repository` in the container registry of `project`: the repository of its
|
|
38
|
+
* `location`, of the first page of a hundred, at `<project>/container_registry/<id>`. Throws
|
|
39
|
+
* `EOCILINK` of a request GitLab refuses or that cannot be made, and of a registry that lists no
|
|
40
|
+
* repository of the location.
|
|
41
|
+
*
|
|
42
|
+
* @param query - The `fetch`, the project, the repository and the headers.
|
|
43
|
+
* @returns The URL of the page of the image.
|
|
44
|
+
*/
|
|
45
|
+
export declare function registryPageOf(query: RegistryQuery): Promise<string>;
|
|
46
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAI1E,4CAA4C;AAC5C,MAAM,WAAW,aAAa;IAC5B,0CAA0C;IAC1C,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAA;IACzB,4DAA4D;IAC5D,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAA;IAC/B,8EAA8E;IAC9E,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,0EAA0E;IAC1E,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CACnD;AAQD;;;;;;;;GAQG;AACH,wBAAsB,cAAc,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CA+B1E"}
|
package/dist/registry.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { OciError } from "./errors.js";
|
|
2
|
+
/**
|
|
3
|
+
* The page of the image `repository` in the container registry of `project`: the repository of its
|
|
4
|
+
* `location`, of the first page of a hundred, at `<project>/container_registry/<id>`. Throws
|
|
5
|
+
* `EOCILINK` of a request GitLab refuses or that cannot be made, and of a registry that lists no
|
|
6
|
+
* repository of the location.
|
|
7
|
+
*
|
|
8
|
+
* @param query - The `fetch`, the project, the repository and the headers.
|
|
9
|
+
* @returns The URL of the page of the image.
|
|
10
|
+
*/
|
|
11
|
+
export async function registryPageOf(query) {
|
|
12
|
+
const { fetch, project, repository, headers } = query;
|
|
13
|
+
const url = `${project.api}/projects/${project.id}/registry/repositories?per_page=100`;
|
|
14
|
+
let text;
|
|
15
|
+
try {
|
|
16
|
+
const response = await fetch(url, { method: 'GET', headers: { ...headers } });
|
|
17
|
+
text = await response.text();
|
|
18
|
+
if (!response.ok)
|
|
19
|
+
throw new Error(`GitLab answered ${response.status}: ${text}`);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
throw new OciError('EOCILINK', `The container registry of ${project.path} cannot be asked for ${repository}, at ${url}: ${error.message}`, 'Give the run a token that may read the registry of the project, `GITLAB_TOKEN` of the `read_api` scope, and check the URL of GitLab.');
|
|
23
|
+
}
|
|
24
|
+
let listed;
|
|
25
|
+
try {
|
|
26
|
+
listed = JSON.parse(text);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
listed = undefined;
|
|
30
|
+
}
|
|
31
|
+
const found = (Array.isArray(listed) ? listed : []).find(({ location }) => location === repository);
|
|
32
|
+
if (found?.id === undefined)
|
|
33
|
+
throw new OciError('EOCILINK', `The container registry of ${project.path} lists no repository ${repository}.`, 'Publish the image to the registry of the project of the release, whose page the release links: its repository is `CI_REGISTRY_IMAGE`, of its folder.');
|
|
34
|
+
return `${project.url}/container_registry/${found.id}`;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,QAAQ,EAAE,MAAM,aA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AE,KAAK,SAAS;QACzB,MAAM,IAAI,QAAQ,CAChB,UAAU,EACV,6BAA6B,OAAO,CAAC,IAAI,wBAAwB,UAAU,GAAG,EAC9E,sJAAsJ,CACvJ,CAAA;IACH,OAAO,GAAG,OAAO,CAAC,GAAG,uBAAuB,KAAK,CAAC,EAAE,EAAE,CAAA;AACxD,CAAC"}
|
package/dist/tags.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** The tags of a release of an image: the one that names its version, and those that move. */
|
|
2
|
+
export interface ReleaseTags {
|
|
3
|
+
/** The tag of the version, as `1.4.2`, which a release never moves once it is published. */
|
|
4
|
+
readonly version: string;
|
|
5
|
+
/** The tags that move to each release of their line, as `1.4` and `1`: none of a prerelease. */
|
|
6
|
+
readonly moving: readonly string[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The tags of a release of `version`: the version, and of a release, its minor and its major, which
|
|
10
|
+
* move; of a release of the major `0`, its minor alone, as a minor of `0` breaks what the one before
|
|
11
|
+
* gave; of a prerelease, none that moves.
|
|
12
|
+
*
|
|
13
|
+
* @param version - The version of the release, as `1.4.2`.
|
|
14
|
+
* @param moving - Whether a release moves its minor and its major: `true` by default.
|
|
15
|
+
* @returns The tags.
|
|
16
|
+
* @throws `TypeError` of a version that is no semver.
|
|
17
|
+
*/
|
|
18
|
+
export declare function releaseTagsOf(version: string, moving?: boolean): ReleaseTags;
|
|
19
|
+
/**
|
|
20
|
+
* Every tag of a release of `version`, the version first (see {@link releaseTagsOf}).
|
|
21
|
+
*
|
|
22
|
+
* @param version - The version of the release, as `1.4.2`.
|
|
23
|
+
* @param moving - Whether a release moves its minor and its major: `true` by default.
|
|
24
|
+
* @returns The tags, as `['1.4.2', '1.4', '1']`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function tagsOfRelease(version: string, moving?: boolean): string[];
|
|
27
|
+
/**
|
|
28
|
+
* The tags of a release that its caller gives, as of a version that is no semver, checked: each a
|
|
29
|
+
* tag the OCI distribution spec takes, `[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}`, none twice, and the tag
|
|
30
|
+
* of the version not among those that move.
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { checkReleaseTags } from '@wtf/release-oci/tags'
|
|
34
|
+
*
|
|
35
|
+
* export const tags = checkReleaseTags({ version: '12.12-wtf.1', moving: ['12.12', 'latest'] })
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @param tags - The tag of the version, and those that move.
|
|
39
|
+
* @returns The same tags.
|
|
40
|
+
* @throws `TypeError` of a tag the spec does not take, or of a tag given twice.
|
|
41
|
+
*/
|
|
42
|
+
export declare function checkReleaseTags(tags: ReleaseTags): ReleaseTags;
|
|
43
|
+
//# sourceMappingURL=tags.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tags.d.ts","sourceRoot":"","sources":["../src/tags.ts"],"names":[],"mappings":"AAkBA,8FAA8F;AAC9F,MAAM,WAAW,WAAW;IAC1B,4FAA4F;IAC5F,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,gGAAgG;IAChG,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;CACnC;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAO,GAAG,WAAW,CASzE;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAO,GAAG,MAAM,EAAE,CAGtE;AAKD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW,GAAG,WAAW,CAa/D"}
|
package/dist/tags.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tags of a release of an image ({@link tagsOfRelease}): its version, and of a release, the
|
|
3
|
+
* minor and the major that move with each release of them, as `1.4` and `1` of `1.4.2`, which a
|
|
4
|
+
* consumer pins to take each fix of its line. A prerelease, as `2.0.0-next.1`, has its own tag
|
|
5
|
+
* alone, so no moving tag points at a version that is not released. A release of a version that is
|
|
6
|
+
* no semver, as `12.12-wtf.1`, gives its own tags, which {@link checkReleaseTags} checks.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { tagsOfRelease } from '@wtf/release-oci/tags'
|
|
10
|
+
*
|
|
11
|
+
* export const tags = tagsOfRelease('1.4.2') // ['1.4.2', '1.4', '1']
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @packageDocumentation
|
|
15
|
+
* @module @wtf/release-oci/tags
|
|
16
|
+
*/
|
|
17
|
+
import semver from 'semver';
|
|
18
|
+
/**
|
|
19
|
+
* The tags of a release of `version`: the version, and of a release, its minor and its major, which
|
|
20
|
+
* move; of a release of the major `0`, its minor alone, as a minor of `0` breaks what the one before
|
|
21
|
+
* gave; of a prerelease, none that moves.
|
|
22
|
+
*
|
|
23
|
+
* @param version - The version of the release, as `1.4.2`.
|
|
24
|
+
* @param moving - Whether a release moves its minor and its major: `true` by default.
|
|
25
|
+
* @returns The tags.
|
|
26
|
+
* @throws `TypeError` of a version that is no semver.
|
|
27
|
+
*/
|
|
28
|
+
export function releaseTagsOf(version, moving = true) {
|
|
29
|
+
const parsed = semver.parse(version);
|
|
30
|
+
if (parsed === null)
|
|
31
|
+
throw new TypeError(`${version} is no semver version.`);
|
|
32
|
+
if (!moving || parsed.prerelease.length > 0)
|
|
33
|
+
return { version: parsed.version, moving: [] };
|
|
34
|
+
const minor = `${parsed.major}.${parsed.minor}`;
|
|
35
|
+
return {
|
|
36
|
+
version: parsed.version,
|
|
37
|
+
moving: parsed.major === 0 ? [minor] : [minor, `${parsed.major}`]
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Every tag of a release of `version`, the version first (see {@link releaseTagsOf}).
|
|
42
|
+
*
|
|
43
|
+
* @param version - The version of the release, as `1.4.2`.
|
|
44
|
+
* @param moving - Whether a release moves its minor and its major: `true` by default.
|
|
45
|
+
* @returns The tags, as `['1.4.2', '1.4', '1']`.
|
|
46
|
+
*/
|
|
47
|
+
export function tagsOfRelease(version, moving = true) {
|
|
48
|
+
const tags = releaseTagsOf(version, moving);
|
|
49
|
+
return [tags.version, ...tags.moving];
|
|
50
|
+
}
|
|
51
|
+
/** A tag of an image, as the OCI distribution spec takes it: at most 128 characters. */
|
|
52
|
+
const TAG = /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}$/;
|
|
53
|
+
/**
|
|
54
|
+
* The tags of a release that its caller gives, as of a version that is no semver, checked: each a
|
|
55
|
+
* tag the OCI distribution spec takes, `[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}`, none twice, and the tag
|
|
56
|
+
* of the version not among those that move.
|
|
57
|
+
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { checkReleaseTags } from '@wtf/release-oci/tags'
|
|
60
|
+
*
|
|
61
|
+
* export const tags = checkReleaseTags({ version: '12.12-wtf.1', moving: ['12.12', 'latest'] })
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* @param tags - The tag of the version, and those that move.
|
|
65
|
+
* @returns The same tags.
|
|
66
|
+
* @throws `TypeError` of a tag the spec does not take, or of a tag given twice.
|
|
67
|
+
*/
|
|
68
|
+
export function checkReleaseTags(tags) {
|
|
69
|
+
const all = [tags.version, ...tags.moving];
|
|
70
|
+
const invalid = all.filter((tag) => !TAG.test(tag));
|
|
71
|
+
if (invalid.length > 0)
|
|
72
|
+
throw new TypeError(`${invalid.map((tag) => JSON.stringify(tag)).join(', ')} is no tag of an image: a tag is [A-Za-z0-9_][A-Za-z0-9_.-]{0,127}.`);
|
|
73
|
+
const twice = all.filter((tag, index) => all.indexOf(tag) !== index);
|
|
74
|
+
if (twice.length > 0)
|
|
75
|
+
throw new TypeError(`The tags of the release name ${[...new Set(twice)].join(', ')} twice: the tag of the version moves never, and each other tag once.`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