Skip to content

Build: Add convert-to-ami and Multi container image build#4

Merged
yureutaejin merged 30 commits intomainfrom
build/convert-to-ami
Oct 24, 2025
Merged

Build: Add convert-to-ami and Multi container image build#4
yureutaejin merged 30 commits intomainfrom
build/convert-to-ami

Conversation

@charlie3965
Copy link
Collaborator

@charlie3965 charlie3965 commented Oct 8, 2025

Changes

Tests

(Misc) Prerequisites for AMI build

Refer to Cloud uploaders section in BIB

@charlie3965
Copy link
Collaborator Author

charlie3965 commented Oct 8, 2025

  • The way of creating vmimport using AWS cli is as below.
# trust-policy.json
{
   "Version":"2012-10-17",		 	 	 
   "Statement": [
      {
         "Effect": "Allow",
         "Principal": { "Service": "vmie.amazonaws.com" },
         "Action": "sts:AssumeRole",
         "Condition": {
            "StringEquals":{
               "sts:Externalid": "vmimport"
            }
         }
      }
   ]
}
aws iam create-role --role-name vmimport --assume-role-policy-document "file://{YOUR_DIRECTORY}/trust-policy.json"
# role-policy.json
{
   "Version":"2012-10-17",		 	 	 
   "Statement":[
      {
         "Effect": "Allow",
         "Action": [
            "s3:GetBucketLocation",
            "s3:GetObject",
            "s3:ListBucket",
            "s3:PutObject",
            "s3:GetBucketAcl",
            "s3:ListAllMyBuckets",
            "s3:DeleteObject"
         ],
         "Resource": [
            "arn:aws:s3:::{YOUR_BUCKET}",
            "arn:aws:s3:::{YOUR_BUCKET}/*"
         ]
      },
      {
         "Effect": "Allow",
         "Action": [
            "ec2:ModifySnapshotAttribute",
            "ec2:CopySnapshot",
            "ec2:RegisterImage",
            "ec2:Describe*"
         ],
         "Resource": "*"
      }
   ]
}
aws iam put-role-policy --role-name vmimport --policy-name vmimport --policy-document "file://{YOUR_DIRECTORY}/role-policy.json"
  • All process must be done after
    1. You have made your own S3 bucket to upload ami
    2. You have installed and inserted access/secret keys to your aws cli
  • Theoratically, this process can be done on GUI console, but I recommend using aws cli - my attempt using GUI console have occurred bunch of permission errors

@yureutaejin yureutaejin changed the title Dev: Adding convert-to-ami in Makefile Build: Add convert-to-ami command in Makefile Oct 8, 2025
@yureutaejin yureutaejin self-requested a review October 8, 2025 09:28
@yureutaejin yureutaejin force-pushed the build/convert-to-ami branch from f76aa38 to 6b2bd32 Compare October 9, 2025 08:17
@yureutaejin yureutaejin force-pushed the build/convert-to-ami branch from 143d77d to bc3b834 Compare October 9, 2025 10:11
@yureutaejin yureutaejin marked this pull request as draft October 9, 2025 10:29
Copy link
Owner

@yureutaejin yureutaejin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@charlie3965

  • I added some suggestions and left a few self-reviews.

  • I just defined belows with dummy values in repository for future ami workflow test

    • secrets.AWS_SECRET_ACCESS_KEY
    • vars.AWS_ACCESS_KEY_ID
    • vars.AWS_REGION

Request

  1. Could you test convert-to-ami with this Makefile in your local environment, and report the result?

  2. Please fix the README.md with your ami set up. (No need to write too much detail)

Makefile Outdated
Comment on lines 16 to 18
AWS_AMI_NAME ?= immutable-os-bootc-$(GIT_COMMIT_HASH:0:8)
AWS_S3_BUCKET ?= immutable-os-bootc
AWS_REGION ?= us-east-1
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add dummy values

Makefile Outdated
Comment on lines 69 to 84
.PHONY: convert-to-ami
convert-to-ami:
sudo podman load -i image-${GIT_COMMIT_HASH:0:8}.tar
sudo docker run --rm \
--privileged \
--security-opt label=type:unconfined_t \
-v /var/lib/containers/storage:/var/lib/containers/storage \
--env AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} \
--env AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} \
${BIB_CONTAINER} \
--type ${DISK_FORMAT} \
--rootfs ${ROOTFS} \
--aws-ami-name ${AWS_AMI_NAME} \
--aws-bucket ${AWS_S3_BUCKET} \
--aws-region ${AWS_REGION} \
${OCI_REGISTRY}/${OCI_IMAGE_REPO}:${OCI_IMAGE_TAG}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@charlie3965
(Please make sure to write a code carefully considering how it works.)

I just removed lines regarding config.toml file
According to official README.md, config.toml is just for anaconda installer

@yureutaejin yureutaejin force-pushed the build/convert-to-ami branch 5 times, most recently from 2506e3c to bb29364 Compare October 16, 2025 08:35
Copy link
Owner

@yureutaejin yureutaejin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self reviews

Comment on lines +96 to +97
- name: Push bootc image to registry
if: ${{ github.event_name == 'workflow_dispatch' }}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prevent pushing OCI registry when merge queue or status checks works

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just made user run single make subcommand.
No need to define/install/fix something except Makefile

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File for {ami, qcow2,...}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +61 to +125
.PHONY: convert-to-iso
convert-to-iso: bib-dind-down bib-dind-up
cp -rf template-iso.toml config.toml
sed -i "s|{DEFAULT_DISK}|${DEFAULT_DISK}|g" config.toml
sed -i "s|{DEFAULT_USER_NAME}|${DEFAULT_USER_NAME}|g" config.toml && \
sed -i "s|{DEFAULT_USER_PASSWD}|${DEFAULT_USER_PASSWD}|g" config.toml && \
sudo docker run --rm \
--privileged \
--security-opt label=type:unconfined_t \
-v ./image-builder-output:/output \
-v /var/lib/containers/storage:/var/lib/containers/storage \
-v ./config.toml:/config.toml:ro \
$(BIB_CONTAINER) \
--type $(DISK_FORMAT) \
--use-librepo=True \
--rootfs $(ROOTFS) \
$(OCI_REGISTRY)/$(OCI_IMAGE_REPO):${OCI_IMAGE_TAG}
sed -i "s|{DEFAULT_USER_NAME}|${DEFAULT_USER_NAME}|g" config.toml
sed -i "s|{DEFAULT_USER_PASSWD}|${DEFAULT_USER_PASSWD}|g" config.toml
docker cp config.toml bib-dind:/config.toml
[[ "${TARGET_INTERFACE}" == "all" ]] && TARGETS="core desktop" || TARGETS="${TARGET_INTERFACE}"; \
for target in $${TARGETS}; do \
mkdir -p image-builder-output/$${target}; \
docker exec bib-dind /bin/bash -c " \
podman load -i container-tarbells/image-${SHORT_COMMIT_HASH}-$${target}.tar.gz; \
podman run --rm \
--privileged \
--security-opt label=type:unconfined_t \
-v ./image-builder-output/$${target}:/output \
-v /var/lib/containers/storage:/var/lib/containers/storage \
-v ./config.toml:/config.toml:ro \
${BIB_CONTAINER} \
--type iso \
--use-librepo=True \
--rootfs ${ROOTFS} \
${OCI_REGISTRY}/${OCI_IMAGE_REPO}:${OCI_IMAGE_TAG}-$${target}"; \
done
$(MAKE) bib-dind-down

# See https://github.com/osbuild/bootc-image-builder?tab=readme-ov-file#amazon-machine-images-amis
.PHONY: convert-to-ami
convert-to-ami: bib-dind-down bib-dind-up
cp -rf template-ami.toml config.toml
sed -i "s|{DEFAULT_USER_NAME}|${DEFAULT_USER_NAME}|g" config.toml
sed -i "s|{DEFAULT_USER_PASSWD}|${DEFAULT_USER_PASSWD}|g" config.toml
docker cp config.toml bib-dind:/config.toml
AWS_AMI_NAME=${SHORT_COMMIT_HASH}-core; \
docker exec bib-dind /bin/bash -c " \
podman load -i container-tarbells/image-${SHORT_COMMIT_HASH}-core.tar.gz; \
podman run --rm \
--privileged \
--security-opt label=type:unconfined_t \
-v /var/lib/containers/storage:/var/lib/containers/storage \
-v ./config.toml:/config.toml:ro \
--env AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} \
--env AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} \
${BIB_CONTAINER} \
--type ami \
--rootfs ${ROOTFS} \
--aws-ami-name $${AWS_AMI_NAME} \
--aws-bucket ${AWS_S3_BUCKET} \
--aws-region ${AWS_REGION} \
${OCI_REGISTRY}/${OCI_IMAGE_REPO}:${OCI_IMAGE_TAG}-core"
$(MAKE) bib-dind-down

.PHONY: bib-dind-up
bib-dind-up:
docker run \
-itd \
--privileged \
--name bib-dind \
-v ./container-tarbells:/container-tarbells \
-v ./image-builder-output:/image-builder-output \
quay.io/containers/podman:latest

.PHONY: bib-dind-down
bib-dind-down:
docker rm -f bib-dind || true
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BIB requires /var/lib/containers which podman, buildah usually uses.

So I resolved the issues using quay.io/containers/podman container with DinD.

Now we don't need to require user to install podman/buildah for prerequisites

Additional Info

You might want to read additional comments about SELinux errors

Changed SELinux default state to permissive, not disabled.

It might be helpful to read belows

yureutaejin
yureutaejin previously approved these changes Oct 24, 2025
Copy link
Owner

@yureutaejin yureutaejin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final self review

Comment on lines 112 to +128
- name: Convert OCI image into specified disk format
run: |
echo "::group::Convert OCI image into specified disk format:"
make convert-to-disk-image
make convert-to-${DISK_FORMAT}
echo "::endgroup::"
env:
OCI_REGISTRY: ${{ inputs.oci_registry }}
OCI_IMAGE_REPO: ${{ inputs.oci_image_repo }}
OCI_IMAGE_TAG: ${{ inputs.oci_image_tag }}
TARGET_INTERFACE: ${{ inputs.target-interface }}
DISK_FORMAT: ${{ inputs.disk_format }}
DEFAULT_DISK: ${{ inputs.default_disk }}
DEFAULT_USER_NAME: ${{ secrets.DEFAULT_USER_NAME }}
DEFAULT_USER_PASSWD: ${{ secrets.DEFAULT_USER_PASSWD }}
ROOTFS: ${{ inputs.rootfs }}
AWS_S3_BUCKET: ${{ inputs.aws_s3_bucket }}
AWS_REGION: ${{ vars.AWS_REGION }}
AWS_ACCESS_KEY_ID: ${{ vars.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yureutaejin yureutaejin dismissed their stale review October 24, 2025 07:35

The merge-base changed after approval.

Repository owner deleted a comment from github-actions bot Oct 24, 2025
Repository owner deleted a comment from github-actions bot Oct 24, 2025
Repository owner deleted a comment from github-actions bot Oct 24, 2025
Repository owner deleted a comment from github-actions bot Oct 24, 2025
@yureutaejin yureutaejin marked this pull request as ready for review October 24, 2025 08:26
@yureutaejin yureutaejin marked this pull request as draft October 24, 2025 08:29
@yureutaejin yureutaejin marked this pull request as ready for review October 24, 2025 08:29
@github-actions
Copy link

Dockerfile Lint Result

commit hash : 2bc6267

[
  {
    "code": "DL3041",
    "column": 1,
    "file": "./Dockerfile",
    "level": "info",
    "line": 7,
    "message": "Specify version with `dnf install -y <package>-<version>`."
  },
  {
    "code": "DL3059",
    "column": 1,
    "file": "./Dockerfile",
    "level": "info",
    "line": 35,
    "message": "Multiple consecutive `RUN` instructions. Consider consolidation."
  },
  {
    "code": "DL3040",
    "column": 1,
    "file": "./Dockerfile",
    "level": "info",
    "line": 41,
    "message": "`dnf clean all` missing after dnf command."
  },
  {
    "code": "DL3041",
    "column": 1,
    "file": "./Dockerfile",
    "level": "info",
    "line": 46,
    "message": "Specify version with `dnf install -y <package>-<version>`."
  },
  {
    "code": "DL3041",
    "column": 1,
    "file": "./Dockerfile",
    "level": "info",
    "line": 101,
    "message": "Specify version with `dnf install -y <package>-<version>`."
  },
  {
    "code": "DL3059",
    "column": 1,
    "file": "./Dockerfile",
    "level": "info",
    "line": 111,
    "message": "Multiple consecutive `RUN` instructions. Consider consolidation."
  }
]

Repository owner deleted a comment from github-actions bot Oct 24, 2025
@yureutaejin yureutaejin merged commit 55d6113 into main Oct 24, 2025
4 checks passed
@yureutaejin yureutaejin deleted the build/convert-to-ami branch October 24, 2025 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants