Sanitize repo name when including in a layer title

These titles were previously including the filename as {org}/{repo}_{version} which means when clients download the layer they think it needs to be unwrapped into a folder called {org}.
This is not what we want, so we should instead rename the file as {org}-{repo}_{version}. e.g. from myorg/myrepo_myversion.zip to myorg-myrepo_myversion.zip
This commit is contained in:
Conor Sloan
2023-11-23 14:37:29 +00:00
parent 0461881066
commit 6c4739c768
3 changed files with 27 additions and 13 deletions
+6 -5
View File
@@ -4,7 +4,8 @@ import { FileMetadata } from '../src/fs-helper'
describe('createActionPackageManigest', () => { describe('createActionPackageManigest', () => {
it('creates a manifest containing the provided information', () => { it('creates a manifest containing the provided information', () => {
const date = new Date() const date = new Date()
const repo = 'test-repo' const repo = 'test-org/test-repo'
const sanitizedRepo = 'test-org-test-repo'
const version = '1.0.0' const version = '1.0.0'
const tarFile: FileMetadata = { const tarFile: FileMetadata = {
path: '/test/test/test', path: '/test/test/test',
@@ -43,7 +44,7 @@ describe('createActionPackageManigest', () => {
"size":${tarFile.size}, "size":${tarFile.size},
"digest":"${tarFile.sha256}", "digest":"${tarFile.sha256}",
"annotations":{ "annotations":{
"org.opencontainers.image.title":"${repo}-${version}.tar.gz" "org.opencontainers.image.title":"${sanitizedRepo}_${version}.tar.gz"
} }
}, },
{ {
@@ -51,7 +52,7 @@ describe('createActionPackageManigest', () => {
"size":${tarFile.size}, "size":${tarFile.size},
"digest":"${tarFile.sha256}", "digest":"${tarFile.sha256}",
"annotations":{ "annotations":{
"org.opencontainers.image.title":"${repo}-${version}.zip" "org.opencontainers.image.title":"${sanitizedRepo}_${version}.zip"
} }
} }
], ],
@@ -74,8 +75,8 @@ describe('createActionPackageManigest', () => {
size: 100, size: 100,
sha256: '1234567890' sha256: '1234567890'
}, },
'test-repo', repo,
'1.0.0', version,
date date
) )
Generated Vendored
+10 -4
View File
@@ -74819,8 +74819,9 @@ exports.createActionPackageManifest = void 0;
// Given a name and archive metadata, creates a manifest in the format expected by GHCR for an Actions Package. // Given a name and archive metadata, creates a manifest in the format expected by GHCR for an Actions Package.
function createActionPackageManifest(tarFile, zipFile, repository, version, created) { function createActionPackageManifest(tarFile, zipFile, repository, version, created) {
const configLayer = createConfigLayer(); const configLayer = createConfigLayer();
const tarLayer = createTarLayer(tarFile, repository, version); const sanitizedRepo = sanitizeRepository(repository);
const zipLayer = createZipLayer(zipFile, repository, version); const tarLayer = createTarLayer(tarFile, sanitizedRepo, version);
const zipLayer = createZipLayer(zipFile, sanitizedRepo, version);
const manifest = { const manifest = {
schemaVersion: 2, schemaVersion: 2,
mediaType: 'application/vnd.oci.image.manifest.v1+json', mediaType: 'application/vnd.oci.image.manifest.v1+json',
@@ -74855,7 +74856,7 @@ function createZipLayer(zipFile, repository, version) {
size: zipFile.size, size: zipFile.size,
digest: zipFile.sha256, digest: zipFile.sha256,
annotations: { annotations: {
'org.opencontainers.image.title': `${repository}-${version}.zip` 'org.opencontainers.image.title': `${repository}_${version}.zip`
} }
}; };
return zipLayer; return zipLayer;
@@ -74866,11 +74867,16 @@ function createTarLayer(tarFile, repository, version) {
size: tarFile.size, size: tarFile.size,
digest: tarFile.sha256, digest: tarFile.sha256,
annotations: { annotations: {
'org.opencontainers.image.title': `${repository}-${version}.tar.gz` 'org.opencontainers.image.title': `${repository}_${version}.tar.gz`
} }
}; };
return tarLayer; return tarLayer;
} }
// Remove slashes so we can use the repository in a filename
// repository usually includes the namespace too, e.g. my-org/my-repo
function sanitizeRepository(repository) {
return repository.replace('/', '-');
}
/***/ }), /***/ }),
+11 -4
View File
@@ -25,8 +25,9 @@ export function createActionPackageManifest(
created: Date created: Date
): Manifest { ): Manifest {
const configLayer = createConfigLayer() const configLayer = createConfigLayer()
const tarLayer = createTarLayer(tarFile, repository, version) const sanitizedRepo = sanitizeRepository(repository)
const zipLayer = createZipLayer(zipFile, repository, version) const tarLayer = createTarLayer(tarFile, sanitizedRepo, version)
const zipLayer = createZipLayer(zipFile, sanitizedRepo, version)
const manifest: Manifest = { const manifest: Manifest = {
schemaVersion: 2, schemaVersion: 2,
@@ -70,7 +71,7 @@ function createZipLayer(
size: zipFile.size, size: zipFile.size,
digest: zipFile.sha256, digest: zipFile.sha256,
annotations: { annotations: {
'org.opencontainers.image.title': `${repository}-${version}.zip` 'org.opencontainers.image.title': `${repository}_${version}.zip`
} }
} }
@@ -87,9 +88,15 @@ function createTarLayer(
size: tarFile.size, size: tarFile.size,
digest: tarFile.sha256, digest: tarFile.sha256,
annotations: { annotations: {
'org.opencontainers.image.title': `${repository}-${version}.tar.gz` 'org.opencontainers.image.title': `${repository}_${version}.tar.gz`
} }
} }
return tarLayer return tarLayer
} }
// Remove slashes so we can use the repository in a filename
// repository usually includes the namespace too, e.g. my-org/my-repo
function sanitizeRepository(repository: string): string {
return repository.replace('/', '-')
}