Last active
April 27, 2023 05:55
-
-
Save viatcheslavmogilevsky/e5d82e7cc755f6d93a79a6cedf489719 to your computer and use it in GitHub Desktop.
ubuntu-shiftfs-sysbox-primer
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
# Usage: | |
# packer build -var region=us-west-1 -var ami_name=sysbox-$(date +%s) ubuntu-shiftfs-sysbox-primer.pkr.hcl | |
variable "ami_name" { | |
type = string | |
} | |
variable "region" { | |
type = string | |
} | |
source "amazon-ebs" "this" { | |
ami_name = "${var.ami_name}" | |
instance_type = "t2.medium" | |
region = "${var.region}" | |
source_ami_filter { | |
filters = { | |
name = "ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20210415" | |
root-device-type = "ebs" | |
virtualization-type = "hvm" | |
} | |
most_recent = true | |
owners = ["099720109477"] | |
} | |
launch_block_device_mappings { | |
device_name = "/dev/sda1" | |
volume_type = "gp2" | |
volume_size = 32 | |
delete_on_termination = true | |
} | |
ssh_username = "ubuntu" | |
ssh_interface = "session_manager" | |
communicator = "ssh" | |
temporary_iam_instance_profile_policy_document { | |
Version = "2012-10-17" | |
Statement { | |
Effect = "Allow" | |
Resource = ["*"] | |
Action = [ | |
"ssm:DescribeAssociation", | |
"ssm:GetDeployablePatchSnapshotForInstance", | |
"ssm:GetDocument", | |
"ssm:DescribeDocument", | |
"ssm:GetManifest", | |
"ssm:GetParameter", | |
"ssm:GetParameters", | |
"ssm:ListAssociations", | |
"ssm:ListInstanceAssociations", | |
"ssm:PutInventory", | |
"ssm:PutComplianceItems", | |
"ssm:PutConfigurePackageResult", | |
"ssm:UpdateAssociationStatus", | |
"ssm:UpdateInstanceAssociationStatus", | |
"ssm:UpdateInstanceInformation", | |
] | |
} | |
Statement { | |
Effect = "Allow" | |
Resource = ["*"] | |
Action = [ | |
"ssmmessages:CreateControlChannel", | |
"ssmmessages:CreateDataChannel", | |
"ssmmessages:OpenControlChannel", | |
"ssmmessages:OpenDataChannel", | |
] | |
} | |
Statement { | |
Effect = "Allow" | |
Resource = ["*"] | |
Action = [ | |
"ec2messages:AcknowledgeMessage", | |
"ec2messages:DeleteMessage", | |
"ec2messages:FailMessage", | |
"ec2messages:GetEndpoint", | |
"ec2messages:GetMessages", | |
"ec2messages:SendReply", | |
] | |
} | |
} | |
vpc_filter { | |
filters = { | |
"tag:Name": "some-private-vpc" | |
} | |
} | |
subnet_filter { | |
filters = { | |
"tag:Name": "some-private-subnet" | |
} | |
most_free = true | |
} | |
temporary_security_group_source_cidrs = ["10.0.0.0/8"] | |
} | |
# a build block invokes sources and runs provisioning steps on them. | |
build { | |
sources = ["source.amazon-ebs.this"] | |
# install prerequisites | |
provisioner "shell" { | |
execute_command = "sudo -S sh -c '{{ .Vars }} {{ .Path }}'" | |
inline = [ | |
"apt-get update -y", | |
"apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common dkms git", | |
] | |
} | |
# shiftfs installation | |
provisioner "shell" { | |
inline = [ | |
"cd ~", | |
"git clone --branch=k5.4 git://github.com/toby63/shiftfs-dkms.git shiftfs-dkms", | |
"cd shiftfs-dkms", | |
"sudo make -f Makefile.dkms", | |
"sudo find /lib/modules/$(uname -r)/ -iname \"*shiftf*\"", | |
"sudo modprobe shiftfs", | |
"lsmod | grep shiftfs", | |
"echo \"shiftfs\" | sudo tee /etc/modules-load.d/shiftfs.conf" | |
] | |
} | |
# docker & sysbox installation | |
provisioner "shell" { | |
execute_command = "sudo -S sh -c '{{ .Vars }} {{ .Path }}'" | |
inline = [ | |
"curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -", | |
"apt-key fingerprint 0EBFCD88", | |
"add-apt-repository \"deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable\"", | |
"apt-get install -y docker-ce docker-ce-cli containerd.io", | |
"cd /tmp", | |
"wget https://github.com/nestybox/sysbox/releases/download/v0.2.1/sysbox_0.2.1-0.ubuntu-focal_amd64.deb", | |
"sha256sum sysbox_0.2.1-0.ubuntu-focal_amd64.deb", | |
"DEBIAN_FRONTEND=noninteractive apt-get install ./sysbox_0.2.1-0.ubuntu-focal_amd64.deb -y", | |
"rm -f ./sysbox_0.2.1-0.ubuntu-focal_amd64.deb", | |
"groupadd -f docker", | |
"usermod -aG docker ubuntu" | |
] | |
} | |
} |
@bjorntheart Yeah, I know, I fixed it to k5.4
branch
Thanks for noticing
@bjorntheart I also update the filter for getting source AMI, because I had the compatibility issues with less strict filter (ubuntu-focal-20.04-amd64-server-*
)
@viatcheslavmogilevsky thanks! Sorry for the double post. Continuing the discussion here nestybox/sysbox#121
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
git checkout e4ddbb55b0cf804899b16058124ab39ec4747db0
is not working. Don't think that hash is available anmore