-
Notifications
You must be signed in to change notification settings - Fork 7
Add image creator #258
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
Merged
Merged
Add image creator #258
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
// Tool to create and install images | ||
|
||
package main | ||
|
||
import ( | ||
"log" | ||
"maps" | ||
"strings" | ||
|
||
"github.com/alecthomas/kong" | ||
"github.com/microsoft/azurelinux/toolkit/tools/imagecustomizerapi" | ||
"github.com/microsoft/azurelinux/toolkit/tools/internal/exekong" | ||
"github.com/microsoft/azurelinux/toolkit/tools/internal/logger" | ||
"github.com/microsoft/azurelinux/toolkit/tools/internal/ptrutils" | ||
"github.com/microsoft/azurelinux/toolkit/tools/pkg/imagecreatorlib" | ||
"github.com/microsoft/azurelinux/toolkit/tools/pkg/imagecustomizerlib" | ||
) | ||
|
||
type ImageCreatorCmd struct { | ||
BuildDir string `name:"build-dir" help:"Directory to run build out of." required:""` | ||
ConfigFile string `name:"config-file" help:"Path of the image creator config file." required:""` | ||
RpmSources []string `name:"rpm-source" help:"Path to a RPM repo config file or a directory containing RPMs." required:""` | ||
ToolsTar string `name:"tools-file" help:"Path to tdnf worker tarball" required:""` | ||
OutputImageFile string `name:"output-image-file" help:"Path to write the customized image to."` | ||
OutputImageFormat string `name:"output-image-format" placeholder:"(vhd|vhd-fixed|vhdx|qcow2|raw)" help:"Format of output image." enum:"${imageformat}" default:""` | ||
exekong.LogFlags | ||
} | ||
|
||
func main() { | ||
cli := &ImageCreatorCmd{} | ||
|
||
vars := kong.Vars{ | ||
"imageformat": strings.Join(imagecustomizerapi.SupportedImageFormatTypesImageCreator(), ",") + ",", | ||
"version": imagecustomizerlib.ToolVersion, | ||
} | ||
maps.Copy(vars, exekong.KongVars) | ||
|
||
_ = kong.Parse(cli, | ||
vars, | ||
kong.HelpOptions{ | ||
Compact: true, | ||
FlagsLast: true, | ||
}, | ||
kong.UsageOnError()) | ||
|
||
logger.InitBestEffort(ptrutils.PtrTo(cli.LogFlags.AsLoggerFlags())) | ||
|
||
err := imagecreatorlib.CreateImageWithConfigFile(cli.BuildDir, cli.ConfigFile, cli.RpmSources, cli.ToolsTar, cli.OutputImageFile, cli.OutputImageFormat) | ||
if err != nil { | ||
log.Fatalf("image creation failed:\n%v", err) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
toolkit/tools/internal/testutils/testrpms/create-tools-file.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
CONTAINER_IMAGE="$1" | ||
TOOLS_FILE="$2" | ||
|
||
if [[ -z "$CONTAINER_IMAGE" || -z "$TOOLS_FILE" ]]; then | ||
echo "Usage: $0 <container_image> <tools_file>" | ||
exit 1 | ||
fi | ||
|
||
docker create --name temp-container "$CONTAINER_IMAGE" | ||
docker export temp-container | gzip > "$TOOLS_FILE" | ||
docker rm temp-container |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
toolkit/tools/internal/testutils/testrpms/download-test-utils.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env bash | ||
set -eu | ||
|
||
SCRIPT_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" | ||
|
||
AZURELINUX_2_CONTAINER_IMAGE="mcr.microsoft.com/cbl-mariner/base/core:2.0" | ||
AZURELINUX_3_CONTAINER_IMAGE="mcr.microsoft.com/azurelinux/base/core:3.0" | ||
|
||
IMAGE_VERSION="2.0" | ||
|
||
IMAGE_CREATOR="false" | ||
TOOLS_FILE="$SCRIPT_DIR/tools.tar.gz" | ||
|
||
|
||
while getopts "s:t:" flag | ||
do | ||
case "${flag}" in | ||
s) IMAGE_CREATOR="$OPTARG";; | ||
t) IMAGE_VERSION="$OPTARG";; | ||
h) ;;& | ||
?) | ||
echo "Usage: download-test-utils.sh [-t IMAGE_VERSION] [-s IMAGE_CREATOR]" | ||
echo "" | ||
echo "Args:" | ||
echo " -t IMAGE_VERSION The Azure Image version to download the RPMs for." | ||
echo " -s IMAGE_CREATOR If set to true, the script will create a tar.gz file with the tools and download the rpms needed to test imagecreator." | ||
echo " -h Show help" | ||
exit 1;; | ||
esac | ||
done | ||
|
||
|
||
case "${IMAGE_VERSION}" in | ||
3.0) | ||
CONTAINER_IMAGE="$AZURELINUX_3_CONTAINER_IMAGE" | ||
;; | ||
2.0) | ||
CONTAINER_IMAGE="$AZURELINUX_2_CONTAINER_IMAGE" | ||
;; | ||
*) | ||
echo "error: unsupported Azure Linux version: $IMAGE_VERSION" | ||
exit 1;; | ||
esac | ||
|
||
set -x | ||
|
||
# call the script to create the tools file if requested | ||
if [ "$IMAGE_CREATOR" = "true" ]; then | ||
echo "Creating tools file: $TOOLS_FILE" | ||
$SCRIPT_DIR/create-tools-file.sh "$CONTAINER_IMAGE" "$TOOLS_FILE" | ||
echo "Tools file created successfully." | ||
else | ||
echo "Skipping tools file creation." | ||
fi | ||
|
||
# call the script to download the rpms | ||
echo "Downloading test rpms for Azure Linux version: $IMAGE_VERSION" | ||
$SCRIPT_DIR/download-test-rpms.sh "$CONTAINER_IMAGE" "$IMAGE_CREATOR" | ||
echo "Test rpms downloaded successfully." |
24 changes: 24 additions & 0 deletions
24
toolkit/tools/internal/testutils/testrpms/downloader/Dockerfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
ARG baseimage | ||
FROM ${baseimage} | ||
ARG imagecreator | ||
himaja-kesari marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
RUN tdnf update -y && \ | ||
tdnf install -y dnf dnf-plugins-core createrepo_c | ||
|
||
RUN dnf download -y --resolve --alldeps --destdir /downloadedrpms \ | ||
jq golang | ||
|
||
RUN if [ "${imagecreator}" = "true" ]; then \ | ||
|
||
dnf download -y --resolve --alldeps --destdir /downloadedrpms \ | ||
azurelinux-release \ | ||
azurelinux-repos azurelinux-rpm-macros bash dbus dracut-hostonly e2fsprogs filesystem \ | ||
grub2 grub2-efi-binary iana-etc iproute iputils irqbalance \ | ||
ncurses-libs openssl rpm rpm-libs shadow-utils shim sudo \ | ||
systemd systemd-networkd systemd-resolved systemd-udev tdnf \ | ||
tdnf-plugin-repogpgcheck util-linux zlib kernel initramfs ; \ | ||
|
||
fi | ||
|
||
# Add repo metadata, so that the directory can be used in a .repo file. | ||
RUN createrepo --compatibility --update /downloadedrpms |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.