Skip manifest creation if single arch/platform is provided (#88)

Signed-off-by: divyansh42 <diagrawa@redhat.com>
This commit is contained in:
Divyanshu Agrawal 2021-11-24 10:38:34 +05:30 committed by GitHub
parent 72b90216e8
commit 5ca1dab81f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 19 deletions

View file

@ -56,8 +56,8 @@ jobs:
uses: ./buildah-build/ uses: ./buildah-build/
with: with:
image: ${{ env.IMAGE_NAME }} image: ${{ env.IMAGE_NAME }}
tags: ${{ env.IMAGE_TAG }} tags: latest v1
archs: amd64, ppc64le, arm64 archs: amd64 # Single arch testcase
containerfiles: | containerfiles: |
./Containerfile ./Containerfile
@ -80,10 +80,6 @@ jobs:
run: | run: |
podman run --rm ${{ steps.build_image_multiarch.outputs.image }}:${{ env.IMAGE_TAG }} podman run --rm ${{ steps.build_image_multiarch.outputs.image }}:${{ env.IMAGE_TAG }}
- name: Check manifest
run: |
buildah manifest inspect ${{ steps.build_image_multiarch.outputs.image }}:${{ env.IMAGE_TAG }}
build-multiplatform-containerfile: build-multiplatform-containerfile:
name: Build multi-platform image using Containerfile name: Build multi-platform image using Containerfile
env: env:

View file

@ -205,7 +205,7 @@ There is a simple example [in this issue](https://github.com/redhat-actions/buil
### Creating a Multi-Arch Image List ### Creating a Multi-Arch Image List
Input `archs` and `platforms` is provided to build the multi architecture images. If one of these input is provided then a [manifest](https://github.com/containers/buildah/blob/main/docs/buildah-manifest.1.md) is built with the multiple architecture images. Name of the manifest is taken from the inputs `image` and `tags`. Input `archs` and `platforms` is provided to build the multi architecture images. If one of these input is provided with the multiple archs or platforms then a [manifest](https://github.com/containers/buildah/blob/main/docs/buildah-manifest.1.md) is built with the multiple architecture images. Name of the manifest is taken from the inputs `image` and `tags`.
Incase multiple tags are provided then multiple manifest is created based on the provided tags. Incase multiple tags are provided then multiple manifest is created based on the provided tags.
Use the `archs` and `platforms` inputs to build multi-architecture images. The name of the manifest is determined by the image and tags inputs. Use the `archs` and `platforms` inputs to build multi-architecture images. The name of the manifest is determined by the image and tags inputs.

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -74,7 +74,7 @@ export async function run(): Promise<void> {
builtImage.push(...await doBuildFromScratch(cli, newImage, useOCI, archs, labelsList)); builtImage.push(...await doBuildFromScratch(cli, newImage, useOCI, archs, labelsList));
} }
if ((archs.length > 0) || (platforms.length > 0)) { if ((archs.length > 1) || (platforms.length > 1)) {
core.info(`Creating manifest with tag${tagsList.length !== 1 ? "s" : ""} "${tagsList.join(", ")}"`); core.info(`Creating manifest with tag${tagsList.length !== 1 ? "s" : ""} "${tagsList.join(", ")}"`);
const builtManifest = []; const builtManifest = [];
for (const tag of tagsList) { for (const tag of tagsList) {
@ -137,23 +137,39 @@ async function doBuildUsingContainerFiles(
// therefore, appending arch/platform in the tag // therefore, appending arch/platform in the tag
if (archs.length > 0 || platforms.length > 0) { if (archs.length > 0 || platforms.length > 0) {
for (const arch of archs) { for (const arch of archs) {
const tagSuffix = removeIllegalCharacters(arch); // handling it seperately as, there is no need of
// tagSuffix if only one image has to be built
let tagSuffix = "";
if (archs.length > 1) {
tagSuffix = `-${removeIllegalCharacters(arch)}`;
}
await cli.buildUsingDocker( await cli.buildUsingDocker(
`${newImage}-${tagSuffix}`, context, containerFileAbsPaths, buildArgs, `${newImage}${tagSuffix}`, context, containerFileAbsPaths, buildArgs,
useOCI, labels, layers, buildahBudExtraArgs, arch, undefined useOCI, labels, layers, buildahBudExtraArgs, arch, undefined
); );
builtImage.push(`${newImage}-${tagSuffix}`); builtImage.push(`${newImage}${tagSuffix}`);
} }
for (const platform of platforms) { for (const platform of platforms) {
const tagSuffix = removeIllegalCharacters(platform); let tagSuffix = "";
if (platforms.length > 1) {
tagSuffix = `-${removeIllegalCharacters(platform)}`;
}
await cli.buildUsingDocker( await cli.buildUsingDocker(
`${newImage}-${tagSuffix}`, context, containerFileAbsPaths, buildArgs, `${newImage}${tagSuffix}`, context, containerFileAbsPaths, buildArgs,
useOCI, labels, layers, buildahBudExtraArgs, undefined, platform useOCI, labels, layers, buildahBudExtraArgs, undefined, platform
); );
builtImage.push(`${newImage}-${tagSuffix}`); builtImage.push(`${newImage}${tagSuffix}`);
} }
} }
else if (archs.length === 1 || platforms.length === 1) {
await cli.buildUsingDocker(
newImage, context, containerFileAbsPaths, buildArgs,
useOCI, labels, layers, buildahBudExtraArgs, archs[0], platforms[0]
);
builtImage.push(newImage);
}
else { else {
await cli.buildUsingDocker( await cli.buildUsingDocker(
newImage, context, containerFileAbsPaths, buildArgs, newImage, context, containerFileAbsPaths, buildArgs,
@ -183,7 +199,10 @@ async function doBuildFromScratch(
const builtImage = []; const builtImage = [];
if (archs.length > 0) { if (archs.length > 0) {
for (const arch of archs) { for (const arch of archs) {
const tagSuffix = removeIllegalCharacters(arch); let tagSuffix = "";
if (archs.length > 1) {
tagSuffix = `-${removeIllegalCharacters(arch)}`;
}
const newImageConfig: BuildahConfigSettings = { const newImageConfig: BuildahConfigSettings = {
entrypoint, entrypoint,
port, port,
@ -194,8 +213,8 @@ async function doBuildFromScratch(
}; };
await cli.config(containerId, newImageConfig); await cli.config(containerId, newImageConfig);
await cli.copy(containerId, content); await cli.copy(containerId, content);
await cli.commit(containerId, `${newImage}-${tagSuffix}`, useOCI); await cli.commit(containerId, `${newImage}${tagSuffix}`, useOCI);
builtImage.push(`${newImage}-${tagSuffix}`); builtImage.push(`${newImage}${tagSuffix}`);
} }
} }
else { else {