Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow multi container registry #316

Merged
merged 1 commit into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,27 @@ export const run = async (inputs: Inputs): Promise<void> => {
core.info(`Using builder: ${builder}`)

const nonLatestTags = inputs.tags.filter((tag) => !tag.endsWith(':latest'))
const latestTag = inputs.tags.find((tag) => tag.endsWith(':latest'))
const latestTags = inputs.tags.filter((tag) => tag.endsWith(':latest'))
for (const tag of nonLatestTags) {
const sourceManifests = getSourceManifests(tag, inputs.suffixes)
await pushManifest(tag, sourceManifests, builder)
core.info(`Pushed a manifest ${tag}`)
}

if (latestTag) {
if (latestTags.length !== 0) {
if (nonLatestTags.length === 0) {
throw new Error(`when latest tag is given, also non-latest tag must be given`)
}
const nonLatestTag = nonLatestTags[0]
const sourceManifests = getSourceManifests(nonLatestTag, inputs.suffixes)
await pushManifest(latestTag, sourceManifests, builder)
core.info(`Pushed a manifest ${latestTag}`)
for (const latestTag of latestTags) {
const image = latestTag.replace(/:latest$/, '')
const nonLatestTag = nonLatestTags.find((tag) => tag.startsWith(image))
if (!nonLatestTag) {
throw new Error(`when latest tag is given, also non-latest tag must be given`)
}
const sourceManifests = getSourceManifests(nonLatestTag, inputs.suffixes)
await pushManifest(latestTag, sourceManifests, builder)
core.info(`Pushed a manifest ${latestTag}`)
}
}
}

Expand Down
154 changes: 154 additions & 0 deletions tests/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,79 @@ describe('using buildx', () => {
'ghcr.io/int128/docker-manifest-create-action:latest',
])
})

test('multi container registry with latest', async () => {
await run({
tags: [
'int128/docker-manifest-create-action:v1.0.0',
'int128/docker-manifest-create-action:latest',
'ghcr.io/int128/docker-manifest-create-action:v1.0.0',
'ghcr.io/int128/docker-manifest-create-action:latest',
],
suffixes: ['-amd64'],
builder: 'auto',
})

// non-latest tag
expect(exec.exec).toHaveBeenCalledWith('docker', [
'buildx',
'imagetools',
'create',
'-t',
'int128/docker-manifest-create-action:v1.0.0',
'int128/docker-manifest-create-action:v1.0.0-amd64',
])
expect(exec.exec).toHaveBeenCalledWith('docker', [
'buildx',
'imagetools',
'inspect',
'int128/docker-manifest-create-action:v1.0.0',
])
expect(exec.exec).toHaveBeenCalledWith('docker', [
'buildx',
'imagetools',
'create',
'-t',
'ghcr.io/int128/docker-manifest-create-action:v1.0.0',
'ghcr.io/int128/docker-manifest-create-action:v1.0.0-amd64',
])
expect(exec.exec).toHaveBeenCalledWith('docker', [
'buildx',
'imagetools',
'inspect',
'ghcr.io/int128/docker-manifest-create-action:v1.0.0',
])

// latest tag
expect(exec.exec).toHaveBeenCalledWith('docker', [
'buildx',
'imagetools',
'create',
'-t',
'int128/docker-manifest-create-action:latest',
'int128/docker-manifest-create-action:v1.0.0-amd64',
])
expect(exec.exec).toHaveBeenCalledWith('docker', [
'buildx',
'imagetools',
'inspect',
'int128/docker-manifest-create-action:latest',
])
expect(exec.exec).toHaveBeenCalledWith('docker', [
'buildx',
'imagetools',
'create',
'-t',
'ghcr.io/int128/docker-manifest-create-action:latest',
'ghcr.io/int128/docker-manifest-create-action:v1.0.0-amd64',
])
expect(exec.exec).toHaveBeenCalledWith('docker', [
'buildx',
'imagetools',
'inspect',
'ghcr.io/int128/docker-manifest-create-action:latest',
])
})
})

describe('using docker', () => {
Expand Down Expand Up @@ -154,6 +227,87 @@ describe('using docker', () => {
'ghcr.io/int128/docker-manifest-create-action:latest',
])
})

test('multi container registry with latest', async () => {
await run({
tags: [
'int128/docker-manifest-create-action:v1.0.0',
'int128/docker-manifest-create-action:latest',
'ghcr.io/int128/docker-manifest-create-action:v1.0.0',
'ghcr.io/int128/docker-manifest-create-action:latest',
],
suffixes: ['-amd64'],
builder: 'auto',
})

// non-latest tag
expect(exec.exec).toHaveBeenCalledWith('docker', [
'manifest',
'create',
'int128/docker-manifest-create-action:v1.0.0',
'int128/docker-manifest-create-action:v1.0.0-amd64',
])
expect(exec.exec).toHaveBeenCalledWith('docker', [
'manifest',
'push',
'int128/docker-manifest-create-action:v1.0.0',
])
expect(exec.exec).toHaveBeenCalledWith('docker', [
'manifest',
'inspect',
'int128/docker-manifest-create-action:v1.0.0',
])
expect(exec.exec).toHaveBeenCalledWith('docker', [
'manifest',
'create',
'ghcr.io/int128/docker-manifest-create-action:latest',
'ghcr.io/int128/docker-manifest-create-action:v1.0.0-amd64',
])
expect(exec.exec).toHaveBeenCalledWith('docker', [
'manifest',
'push',
'ghcr.io/int128/docker-manifest-create-action:latest',
])
expect(exec.exec).toHaveBeenCalledWith('docker', [
'manifest',
'inspect',
'ghcr.io/int128/docker-manifest-create-action:latest',
])

// latest tag
expect(exec.exec).toHaveBeenCalledWith('docker', [
'manifest',
'create',
'int128/docker-manifest-create-action:latest',
'int128/docker-manifest-create-action:v1.0.0-amd64',
])
expect(exec.exec).toHaveBeenCalledWith('docker', [
'manifest',
'push',
'int128/docker-manifest-create-action:latest',
])
expect(exec.exec).toHaveBeenCalledWith('docker', [
'manifest',
'inspect',
'int128/docker-manifest-create-action:latest',
])
expect(exec.exec).toHaveBeenCalledWith('docker', [
'manifest',
'create',
'ghcr.io/int128/docker-manifest-create-action:v1.0.0',
'ghcr.io/int128/docker-manifest-create-action:v1.0.0-amd64',
])
expect(exec.exec).toHaveBeenCalledWith('docker', [
'manifest',
'push',
'ghcr.io/int128/docker-manifest-create-action:v1.0.0',
])
expect(exec.exec).toHaveBeenCalledWith('docker', [
'manifest',
'inspect',
'ghcr.io/int128/docker-manifest-create-action:v1.0.0',
])
})
})

describe('getSourceManifests', () => {
Expand Down
Loading