Last active
November 13, 2018 15:06
-
-
Save cjbottaro/394bcf05deb83892a6bb2a7f4914e227 to your computer and use it in GitHub Desktop.
Convert ECS Optimized AMI to use overlay/overlay2
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
set -e | |
# Stop the docker daemon | |
/etc/init.d/docker stop | |
# Configure ECS Agent | |
# http://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-agent-config.html | |
# http://docs.aws.amazon.com/AmazonECS/latest/developerguide/automated_image_cleanup.html | |
cat > /etc/ecs/ecs.config << "EOF" | |
ECS_ENGINE_TASK_CLEANUP_WAIT_DURATION=1h | |
ECS_NUM_IMAGES_DELETE_PER_CYCLE=100 | |
EOF | |
# Install some packages | |
yum update -y | |
yum install -y vim-enhanced curl wget epel-release | |
# Needed for docker's completion | |
yum install -y bash-completion --enablerepo=epel | |
# The current AMI uses 17.03.1-ce, so no need to upgrade anymore. | |
# Keeping this to show how to upgrade in the future. | |
# | |
# Upgrade to Docker 17.03.1-ce | |
# wget https://get.docker.com/builds/Linux/x86_64/docker-17.03.1-ce.tgz | |
# tar xzf docker-17.03.1-ce.tgz | |
# cp docker/docker* /usr/bin | |
# cp docker/completion/bash/docker /etc/bash_completion.d/ | |
# rm -rf docker* | |
# Use good ole port 4242 for ssh | |
sed -i 's/#Port 22/Port 4242/' /etc/ssh/sshd_config | |
# Get rid of devicemapper defs | |
dmsetup remove_all | |
# Reset the disk | |
dd if=/dev/zero of=/dev/xvdcz bs=512 count=128 | |
# Remove all docker data | |
rm -rf /var/lib/docker/* | |
# Remove ecs data | |
rm -rf /var/lib/ecs/data/* /var/cache/ecs/* | |
# Remove cloud-init stuff so that it runs again | |
rm -rf /var/lib/cloud/* | |
# Remove logs | |
rm -rf /var/log/cloud-init* /var/log/docker /var/log/ecs/* | |
# Don't need this | |
cat > /etc/sysconfig/docker-storage-setup << "EOF" | |
echo "Not needed with overlay, contents removed" | |
exit 1 | |
EOF | |
# Setup docker to use overlay | |
cat > /etc/sysconfig/docker-storage << "EOF" | |
DOCKER_STORAGE_OPTIONS="--storage-driver=overlay" | |
EOF | |
# Setup cloud init to prep disks for docker to use overlay | |
cat > /etc/cloud/cloud.cfg.d/90_ecs.cfg << "EOF" | |
#cloud-config | |
cloud_init_modules: | |
- bootcmd | |
cloud_config_modules: | |
- mounts | |
system_info: | |
default_user: | |
groups: [ "wheel", "docker" ] | |
bootcmd: | |
- [ cloud-init-per, once, docker_overlay_fs, mkfs, -t, ext4, -L, docker, -i, 4096, /dev/xvdcz ] | |
# This doesn't seem to work, hence using the bootcmd above instead. | |
# fs_setup: | |
# - label: docker | |
# filesystem: ext4 | |
# device: /dev/xvdcz | |
# partition: none | |
# cmd: mkfs -t %(FILESYSTEM)s -L %(LABEL)s -i 4096 %(DEVICE)s | |
mounts: | |
- [ /dev/xvdcz, /var/lib/docker/overlay ] | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment