Created
October 26, 2016 23:30
-
-
Save dm0-/458b3c1100079dfbe2f9a08419af53ff to your computer and use it in GitHub Desktop.
Build an Azure agent ACI using CentOS 7 (WIP)
This file contains 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
#!/bin/bash -e | |
# Build a CentOS system with the configuration file from CoreOS. | |
config_url='https://raw.githubusercontent.com/coreos/coreos-overlay/master/app-emulation/wa-linux-agent/files/waagent.conf' | |
mirrorlist='http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os' | |
mirror=$( | |
IFS=$'\n' urls=($(curl --location --silent "$mirrorlist")) | |
echo "${urls[$((RANDOM % ${#urls[@]}))]}" | |
) | |
# Note where dependencies are actually used. | |
dependencies=( | |
e2fsprogs net-tools openssl parted util-linux # waagent | |
bind-utils hostname # CustomScriptForLinux | |
rsyslog tar which yum # LinuxDiagnostic | |
) | |
# Ensure there are no previously written files that get in the way. | |
sudo rm -fr manifest rootfs WALinuxAgent | |
# Install the system with all the dependencies known so far. | |
sudo dnf --disablerepo='*' --installroot="$PWD/rootfs" \ | |
--repofrompath=centos,"$mirror" --enablerepo=centos \ | |
-y install "${dependencies[@]}" | |
# Take out some directories that are not useful. | |
sudo rm -fr \ | |
rootfs/usr/lib/locale/locale-archive \ | |
rootfs/usr/share/{doc,info,man} \ | |
rootfs/var/{cache,lib}/dnf | |
# Fake an init system for the OMI stuff. | |
sudo tee rootfs/etc/init.d/functions << 'EOF' > /dev/null | |
daemon() { ("$@" &)& } | |
echo_success() { echo OK ; } | |
echo_failure() { echo FAILURE ; } | |
status() { echo "Don't care" ; } | |
EOF | |
sudo tee rootfs/usr/sbin/invoke-rc.d << 'EOF' > /dev/null | |
#!/bin/sh -e | |
[ $# -ge 2 ] # There should be args: <service> <action> | |
exec /etc/init.d/"$@" | |
EOF | |
sudo chmod 0755 rootfs/usr/sbin/invoke-rc.d | |
# Add in the latest agent code (or checkout a specific commit first). | |
git clone https://github.com/Azure/WALinuxAgent.git | |
sudo install -pm 0755 -t rootfs/usr/bin \ | |
WALinuxAgent/bin/waagent \ | |
WALinuxAgent/bin/waagent2.0 | |
sudo cp -rt rootfs/usr/lib/python2.7/site-packages \ | |
WALinuxAgent/azurelinuxagent | |
# Download an agent configuration file into place. | |
sudo curl --location --silent --output rootfs/etc/waagent.conf "$config_url" | |
# Update the manifest for the ACI. | |
sudo tee manifest << EOF > /dev/null | |
{ | |
"acKind": "ImageManifest", | |
"acVersion": "0.8.6", | |
"name": "coreos.com/oem-azure", | |
"labels": [ | |
{"name": "arch", "value": "amd64"}, | |
{"name": "os", "value": "linux"}, | |
{"name": "version", "value": "7+$(date '+%Y-%m-%d-%H%M')"} | |
], | |
"app": { | |
"exec": ["/usr/bin/python", "-u", "/usr/bin/waagent", "-daemon"], | |
"user": "0", | |
"group": "0", | |
"environment": [ | |
{ | |
"name": "PYTHONPATH", | |
"value": "/usr/bin" | |
} | |
], | |
"mountPoints": [ | |
{ | |
"name": "modules", | |
"path": "/lib/modules", | |
"readOnly": true | |
} | |
] | |
} | |
} | |
EOF | |
# Write the ACI. | |
sudo tar -czf centos.aci manifest rootfs |
This file contains 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
#!/bin/sh -e | |
sudo rkt --insecure-options=image run \ | |
--stage1-path=/usr/lib/rkt/stage1-images/stage1-fly.aci \ | |
--volume=modules,kind=host,source=/lib/modules,readOnly=true \ | |
--dns=host \ | |
--hosts-entry=host \ | |
--net=host \ | |
centos.aci "$@" | |
sudo rkt gc --grace-period=0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment