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

Add aws image generation based of the raw image #338

Merged
merged 2 commits into from
Jun 29, 2021
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
4 changes: 2 additions & 2 deletions .github/build.yaml.gomplate
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ jobs:
brew install qemu
- name: Build QEMU Image 🔧
run: |
PACKER_ARGS="-var='accelerator=hvf' -var='feature=vagrant' -only qemu" make packer
PACKER_ARGS="-var='accelerator=hvf' -var='feature=vagrant' -only qemu.cos" make packer
- uses: actions/upload-artifact@v2
with:
name: cOS-{{{$subset}}}-{{{ $flavor }}}.qcow
Expand Down Expand Up @@ -249,7 +249,7 @@ jobs:
# brew install hashicorp/tap/packer
- name: Build VBox Image 🔧
run: |
PACKER_ARGS="-var='feature=vagrant' -only virtualbox-iso" make packer
PACKER_ARGS="-var='feature=vagrant' -only virtualbox-iso.cos" make packer
- uses: actions/upload-artifact@v2
with:
name: cOS-{{{$subset}}}-{{{ $flavor }}}.ova
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/build-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ jobs:
brew install qemu
- name: Build QEMU Image 🔧
run: |
PACKER_ARGS="-var='accelerator=hvf' -var='feature=vagrant' -only qemu" make packer
PACKER_ARGS="-var='accelerator=hvf' -var='feature=vagrant' -only qemu.cos" make packer
- uses: actions/upload-artifact@v2
with:
name: cOS-squashfs-opensuse.qcow
Expand Down Expand Up @@ -224,7 +224,7 @@ jobs:
# brew install hashicorp/tap/packer
- name: Build VBox Image 🔧
run: |
PACKER_ARGS="-var='feature=vagrant' -only virtualbox-iso" make packer
PACKER_ARGS="-var='feature=vagrant' -only virtualbox-iso.cos" make packer
- uses: actions/upload-artifact@v2
with:
name: cOS-squashfs-opensuse.ova
Expand Down Expand Up @@ -348,7 +348,7 @@ jobs:
brew install qemu
- name: Build QEMU Image 🔧
run: |
PACKER_ARGS="-var='accelerator=hvf' -var='feature=vagrant' -only qemu" make packer
PACKER_ARGS="-var='accelerator=hvf' -var='feature=vagrant' -only qemu.cos" make packer
- uses: actions/upload-artifact@v2
with:
name: cOS-nonsquashfs-opensuse.qcow
Expand Down Expand Up @@ -377,7 +377,7 @@ jobs:
# brew install hashicorp/tap/packer
- name: Build VBox Image 🔧
run: |
PACKER_ARGS="-var='feature=vagrant' -only virtualbox-iso" make packer
PACKER_ARGS="-var='feature=vagrant' -only virtualbox-iso.cos" make packer
- uses: actions/upload-artifact@v2
with:
name: cOS-nonsquashfs-opensuse.ova
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/build-nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ jobs:
brew install qemu
- name: Build QEMU Image 🔧
run: |
PACKER_ARGS="-var='accelerator=hvf' -var='feature=vagrant' -only qemu" make packer
PACKER_ARGS="-var='accelerator=hvf' -var='feature=vagrant' -only qemu.cos" make packer
- uses: actions/upload-artifact@v2
with:
name: cOS-squashfs-opensuse.qcow
Expand Down Expand Up @@ -203,7 +203,7 @@ jobs:
# brew install hashicorp/tap/packer
- name: Build VBox Image 🔧
run: |
PACKER_ARGS="-var='feature=vagrant' -only virtualbox-iso" make packer
PACKER_ARGS="-var='feature=vagrant' -only virtualbox-iso.cos" make packer
- uses: actions/upload-artifact@v2
with:
name: cOS-squashfs-opensuse.ova
Expand Down Expand Up @@ -327,7 +327,7 @@ jobs:
brew install qemu
- name: Build QEMU Image 🔧
run: |
PACKER_ARGS="-var='accelerator=hvf' -var='feature=vagrant' -only qemu" make packer
PACKER_ARGS="-var='accelerator=hvf' -var='feature=vagrant' -only qemu.cos" make packer
- uses: actions/upload-artifact@v2
with:
name: cOS-nonsquashfs-opensuse.qcow
Expand Down Expand Up @@ -356,7 +356,7 @@ jobs:
# brew install hashicorp/tap/packer
- name: Build VBox Image 🔧
run: |
PACKER_ARGS="-var='feature=vagrant' -only virtualbox-iso" make packer
PACKER_ARGS="-var='feature=vagrant' -only virtualbox-iso.cos" make packer
- uses: actions/upload-artifact@v2
with:
name: cOS-nonsquashfs-opensuse.ova
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/build-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ jobs:
brew install qemu
- name: Build QEMU Image 🔧
run: |
PACKER_ARGS="-var='accelerator=hvf' -var='feature=vagrant' -only qemu" make packer
PACKER_ARGS="-var='accelerator=hvf' -var='feature=vagrant' -only qemu.cos" make packer
- uses: actions/upload-artifact@v2
with:
name: cOS-squashfs-opensuse.qcow
Expand Down Expand Up @@ -209,7 +209,7 @@ jobs:
# brew install hashicorp/tap/packer
- name: Build VBox Image 🔧
run: |
PACKER_ARGS="-var='feature=vagrant' -only virtualbox-iso" make packer
PACKER_ARGS="-var='feature=vagrant' -only virtualbox-iso.cos" make packer
- uses: actions/upload-artifact@v2
with:
name: cOS-squashfs-opensuse.ova
Expand Down Expand Up @@ -333,7 +333,7 @@ jobs:
brew install qemu
- name: Build QEMU Image 🔧
run: |
PACKER_ARGS="-var='accelerator=hvf' -var='feature=vagrant' -only qemu" make packer
PACKER_ARGS="-var='accelerator=hvf' -var='feature=vagrant' -only qemu.cos" make packer
- uses: actions/upload-artifact@v2
with:
name: cOS-nonsquashfs-opensuse.qcow
Expand Down Expand Up @@ -362,7 +362,7 @@ jobs:
# brew install hashicorp/tap/packer
- name: Build VBox Image 🔧
run: |
PACKER_ARGS="-var='feature=vagrant' -only virtualbox-iso" make packer
PACKER_ARGS="-var='feature=vagrant' -only virtualbox-iso.cos" make packer
- uses: actions/upload-artifact@v2
with:
name: cOS-nonsquashfs-opensuse.ova
Expand Down
6 changes: 5 additions & 1 deletion make/Makefile.iso
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,8 @@ ifeq ("$(ISO)","")
@echo "Please run 'make iso' or 'make local-iso' first"
@exit 1
endif
cd $(ROOT_DIR)/packer && $(PACKER) build -var "iso=$(ISO)" $(PACKER_ARGS) images.json
cd $(ROOT_DIR)/packer && $(PACKER) build -var "iso=$(ISO)" $(PACKER_ARGS) .


packer-aws:
cd $(ROOT_DIR)/packer && $(PACKER) build -only amazon-ebs.cos .
29 changes: 29 additions & 0 deletions packer/aws/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# steps

- build cos (sudo make build)
- create repo (sudo make create-repo)
- create raw image (sudo make raw_disk)
- upload raw image to s3 (aws s3 cp IMAGE s3://cos-images/)
- import image as snapshot (aws ec2 import-snapshot --description "Cos raw import" --disk-container "file://containers.json")

containers.json:
```json
{
"Description": "Example image originally in raw format",
"Format": "raw",
"UserBucket": {
"S3Bucket": "cos-images",
"S3Key": "IMAGE_NAME"
}
}
```

- create ami from snapshot in aws console
- launch packer with aws image creation (make packer-aws)


# image creation

- Set proper disk partitions (aws/setup-disk.yaml)
- cos-deploy:
`cos-deploy --docker-image quay.io/costoolkit/releases-opensuse:cos-system-0.5.3-3`
13 changes: 13 additions & 0 deletions packer/aws/setup-disk.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: "Default deployment"
stages:
rootfs.after:
- name: "Repart image"
layout:
device:
label: COS_RECOVERY
add_partitions:
- fsLabel: COS_STATE
size: 9192
pLabel: state
- fsLabel: COS_PERSISTENT
pLabel: persistent
100 changes: 0 additions & 100 deletions packer/images.json

This file was deleted.

115 changes: 115 additions & 0 deletions packer/images.json.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
source "amazon-ebs" "cos" {
access_key = var.aws_access_key
ami_name = "cos-${var.cos_version}-${formatdate("DDMMYYYY", timestamp())}"
ami_description = "cos-${var.cos_version}-${formatdate("DDMMYYYY", timestamp())}"
instance_type = "t3.small"
region = var.aws_region
secret_key = var.aws_secret_key
ssh_password = "cos"
ssh_username = "root"
source_ami_filter {
filters = {
name = "*cos*recovery*"
Copy link
Contributor

Choose a reason for hiding this comment

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

Also probably this one too should be customizable, with a default (like this one)

root-device-type = "ebs"
virtualization-type = "hvm"
}
most_recent = true
owners = ["self"]
}
launch_block_device_mappings {
device_name = "/dev/sda1"
volume_size = 15
}
user_data_file = "aws/setup-disk.yaml"
tags = {
Name = "cOS"
Version = var.cos_version
Base_AMI_ID = "{{ .SourceAMI }}"
Base_AMI_Name = "{{ .SourceAMIName }}"
}
}

source "qemu" "cos" {
accelerator = "${var.accelerator}"
boot_wait = "${var.sleep}"
cpus = "${var.cpus}"
disk_interface = "ide"
disk_size = "${var.disk_size}"
format = "qcow2"
headless = true
iso_checksum = "none"
iso_url = "${var.iso}"
qemuargs = [["-m", "${var.memory}M"]]
shutdown_command = "shutdown -hP now"
ssh_handshake_attempts = "20"
ssh_password = "${var.root_password}"
ssh_timeout = "5m"
ssh_username = "${var.root_username}"
vm_name = "cOS"
}

source "virtualbox-iso" "cos" {
boot_wait = "${var.sleep}"
cpus = "${var.cpus}"
disk_size = "${var.disk_size}"
format = "ova"
guest_additions_mode = "disable"
guest_os_type = "cOS"
headless = true
iso_checksum = "none"
iso_url = "${var.iso}"
memory = "${var.memory}"
shutdown_command = "shutdown -hP now"
ssh_handshake_attempts = "20"
ssh_password = "${var.root_password}"
ssh_timeout = "5m"
ssh_username = "${var.root_username}"
vm_name = "cOS"
}

# a build block invokes sources and runs provisioning steps on them. The
# documentation for build blocks can be found here:
# https://www.packer.io/docs/templates/hcl_templates/blocks/build
build {
description = "cOS"

sources = ["source.amazon-ebs.cos", "source.qemu.cos", "source.virtualbox-iso.cos"]

provisioner "file" {
except = ["amazon-ebs.cos"]
destination = "/90_custom.yaml"
source = "config.yaml"
}

provisioner "file" {
except = ["amazon-ebs.cos"]
destination = "/vagrant.yaml"
source = "vagrant.yaml"
}

provisioner "shell" {
except = ["amazon-ebs.cos"]
inline = ["INTERACTIVE=false cos-installer --config /90_custom.yaml /dev/sda",
"if [ -n \"${var.feature}\" ]; then mount /dev/disk/by-label/COS_OEM /oem; cos-feature enable ${var.feature}; fi"
]
pause_after = "30s"
}

provisioner "shell" {
only = ["amazon-ebs.cos"]
inline = [
"${var.aws_cos_install_args}",
"sync"
]
pause_after = "30s"
}

post-processor "vagrant" {
only = ["virtualbox-iso.cos", "qemu.cos"]
output = "cOS_${var.build}_${var.arch}_${var.flavor}.box"
}
post-processor "compress" {
only = ["virtualbox-iso.cos", "qemu.cos"]
output = "cOS_${var.build}_${var.arch}_${var.flavor}.tar.gz"
}
}
Loading