Skip to content

Commit

Permalink
Support Docker 25 and AL2023 by removing instance store Docker volume…
Browse files Browse the repository at this point in the history
… initialization 'magic'

The plugin previously had some userdata/cloud-init magic to utilise any special NVMe instance stores for Docker
storage by creating a new logical volume group and restarting Docker on this volume. This would work "magically" on 'd'
instances (e.g c6id). Additionally changes to ECS and cloud-init makes the previous approach to installing various packages
not work any longer due to changes within ECS/AL2023, so the volume tools need additional work to get in the right state.

This is broken on Docker 25 and thus AL2023 because it relied on the docker device-mapper storage driver which is
no longer available, and there was no way to opt out of it. In any case, this no longer seems necessary, as for the
purposes of this image it seems regular EBS GP3 style volumes should probably be sufficient for use within the GoCD
build agent containers being run.

If there is a need to add this back, we'll add this back based on user feedback and assistance, but right now this seems to be doing more harm than good, so will remove the support.
  • Loading branch information
chadlwilson committed Dec 9, 2024
1 parent ae847fb commit 5376ec2
Show file tree
Hide file tree
Showing 12 changed files with 1 addition and 705 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ group = 'com.thoughtworks.gocd'

gocdPlugin {
id = 'com.thoughtworks.gocd.elastic-agent.ecs'
pluginVersion = '7.4.1'
pluginVersion = '8.0.0'
goCdVersion = '21.4.0'
name = 'GoCD Elastic Agent Plugin for Amazon ECS'
description = 'GoCD Elastic Agent Plugin for Amazon Elastic Container Service allow for more efficient use of instances'
Expand Down
64 changes: 0 additions & 64 deletions src/main/resources/userdata.template
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config"

#cloud-config
package_update: true
packages:
- lvm2
- nfs-utils
- nfs-common
cloud_final_modules:
- [scripts-user, always]

Expand All @@ -35,62 +30,3 @@ CUSTOM_USER_DATA_SCRIPT
log "Finished executing user specified user data script."

--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="initialize_instance_store"

#!/bin/bash
exec > >(tee /var/log/initialize_instance_store.log | logger -t user-data -s 2>/dev/console) 2>&1
function log() {
echo "[$(date "+%Y-%m-%d %H:%M:%S")] - $1" >> /var/log/initialize_instance_store.log
}

function try() {
$@
return 0
}

log "Starting to setup instance store for the docker."
INSTANCE_STORES=$(ls /dev/disk/by-id/*EC2_NVMe_Instance_Storage*-ns-1)

if [ -z "${INSTANCE_STORES}" ]; then
log "No instance store detected."
fi

VOLUMES="$INSTANCE_STORES"
if [ -e "/dev/xvdcz" ]; then
log "Instance has /dev/xvdcz EBS volume. Using it for docker logical volume group."
VOLUMES="$VOLUMES /dev/xvdcz"
fi

if [ -z "${VOLUMES}" ]; then
log "No addition volumes. Using box standard docker setup."
else
log "Available instance stores: ${VOLUMES}."
log "Setting up the docker logical volume group."

service docker stop
rm -rf /var/lib/docker/*
dmsetup remove_all

VOLUME_GROUP=docker
LOGICAL_VOLUME=docker-pool

try vgremove -y "${VOLUME_GROUP}"
try lvremove -y "${LOGICAL_VOLUME}"

vgcreate -y "${VOLUME_GROUP}" ${VOLUMES}
sleep 2
lvcreate -y -l 5%VG -n ${LOGICAL_VOLUME}\meta ${VOLUME_GROUP}
lvcreate -y -l 90%VG -n ${LOGICAL_VOLUME} ${VOLUME_GROUP}
sleep 2
lvconvert -y --zero n --thinpool ${VOLUME_GROUP}/${LOGICAL_VOLUME} --poolmetadata ${VOLUME_GROUP}/${LOGICAL_VOLUME}\meta
echo 'DOCKER_STORAGE_OPTIONS="OVERRIDE_STORAGE_OPTION --storage-driver devicemapper --storage-opt dm.thinpooldev=/dev/mapper/docker-docker--pool --storage-opt dm.use_deferred_removal=true --storage-opt dm.use_deferred_deletion=true --storage-opt dm.fs=ext4 --storage-opt dm.use_deferred_deletion=true"' > /etc/sysconfig/docker-storage
test -f /bin/systemctl && systemctl reset-failed docker.service
service docker restart
test -f /bin/systemctl && systemctl enable --no-block --now ecs
fi

log "Setup completed."
--//
64 changes: 0 additions & 64 deletions src/test/resources/userdata/full-userdata.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config"

#cloud-config
package_update: true
packages:
- lvm2
- nfs-utils
- nfs-common
cloud_final_modules:
- [scripts-user, always]

Expand Down Expand Up @@ -45,62 +40,3 @@ some-script
log "Finished executing user specified user data script."

--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="initialize_instance_store"

#!/bin/bash
exec > >(tee /var/log/initialize_instance_store.log | logger -t user-data -s 2>/dev/console) 2>&1
function log() {
echo "[$(date "+%Y-%m-%d %H:%M:%S")] - $1" >> /var/log/initialize_instance_store.log
}

function try() {
$@
return 0
}

log "Starting to setup instance store for the docker."
INSTANCE_STORES=$(ls /dev/disk/by-id/*EC2_NVMe_Instance_Storage*-ns-1)

if [ -z "${INSTANCE_STORES}" ]; then
log "No instance store detected."
fi

VOLUMES="$INSTANCE_STORES"
if [ -e "/dev/xvdcz" ]; then
log "Instance has /dev/xvdcz EBS volume. Using it for docker logical volume group."
VOLUMES="$VOLUMES /dev/xvdcz"
fi

if [ -z "${VOLUMES}" ]; then
log "No addition volumes. Using box standard docker setup."
else
log "Available instance stores: ${VOLUMES}."
log "Setting up the docker logical volume group."

service docker stop
rm -rf /var/lib/docker/*
dmsetup remove_all

VOLUME_GROUP=docker
LOGICAL_VOLUME=docker-pool

try vgremove -y "${VOLUME_GROUP}"
try lvremove -y "${LOGICAL_VOLUME}"

vgcreate -y "${VOLUME_GROUP}" ${VOLUMES}
sleep 2
lvcreate -y -l 5%VG -n ${LOGICAL_VOLUME}\meta ${VOLUME_GROUP}
lvcreate -y -l 90%VG -n ${LOGICAL_VOLUME} ${VOLUME_GROUP}
sleep 2
lvconvert -y --zero n --thinpool ${VOLUME_GROUP}/${LOGICAL_VOLUME} --poolmetadata ${VOLUME_GROUP}/${LOGICAL_VOLUME}\meta
echo 'DOCKER_STORAGE_OPTIONS="--storage-opt foo=bsfds --storage-driver devicemapper --storage-opt dm.thinpooldev=/dev/mapper/docker-docker--pool --storage-opt dm.use_deferred_removal=true --storage-opt dm.use_deferred_deletion=true --storage-opt dm.fs=ext4 --storage-opt dm.use_deferred_deletion=true"' > /etc/sysconfig/docker-storage
test -f /bin/systemctl && systemctl reset-failed docker.service
service docker restart
test -f /bin/systemctl && systemctl enable --no-block --now ecs
fi

log "Setup completed."
--//
64 changes: 0 additions & 64 deletions src/test/resources/userdata/linux-default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config"

#cloud-config
package_update: true
packages:
- lvm2
- nfs-utils
- nfs-common
cloud_final_modules:
- [scripts-user, always]

Expand All @@ -35,62 +30,3 @@ log "Finished executing GoCD's user data script, now executing custom user data
log "Finished executing user specified user data script."

--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="initialize_instance_store"

#!/bin/bash
exec > >(tee /var/log/initialize_instance_store.log | logger -t user-data -s 2>/dev/console) 2>&1
function log() {
echo "[$(date "+%Y-%m-%d %H:%M:%S")] - $1" >> /var/log/initialize_instance_store.log
}

function try() {
$@
return 0
}

log "Starting to setup instance store for the docker."
INSTANCE_STORES=$(ls /dev/disk/by-id/*EC2_NVMe_Instance_Storage*-ns-1)

if [ -z "${INSTANCE_STORES}" ]; then
log "No instance store detected."
fi

VOLUMES="$INSTANCE_STORES"
if [ -e "/dev/xvdcz" ]; then
log "Instance has /dev/xvdcz EBS volume. Using it for docker logical volume group."
VOLUMES="$VOLUMES /dev/xvdcz"
fi

if [ -z "${VOLUMES}" ]; then
log "No addition volumes. Using box standard docker setup."
else
log "Available instance stores: ${VOLUMES}."
log "Setting up the docker logical volume group."

service docker stop
rm -rf /var/lib/docker/*
dmsetup remove_all

VOLUME_GROUP=docker
LOGICAL_VOLUME=docker-pool

try vgremove -y "${VOLUME_GROUP}"
try lvremove -y "${LOGICAL_VOLUME}"

vgcreate -y "${VOLUME_GROUP}" ${VOLUMES}
sleep 2
lvcreate -y -l 5%VG -n ${LOGICAL_VOLUME}\meta ${VOLUME_GROUP}
lvcreate -y -l 90%VG -n ${LOGICAL_VOLUME} ${VOLUME_GROUP}
sleep 2
lvconvert -y --zero n --thinpool ${VOLUME_GROUP}/${LOGICAL_VOLUME} --poolmetadata ${VOLUME_GROUP}/${LOGICAL_VOLUME}\meta
echo 'DOCKER_STORAGE_OPTIONS=" --storage-driver devicemapper --storage-opt dm.thinpooldev=/dev/mapper/docker-docker--pool --storage-opt dm.use_deferred_removal=true --storage-opt dm.use_deferred_deletion=true --storage-opt dm.fs=ext4 --storage-opt dm.use_deferred_deletion=true"' > /etc/sysconfig/docker-storage
test -f /bin/systemctl && systemctl reset-failed docker.service
service docker restart
test -f /bin/systemctl && systemctl enable --no-block --now ecs
fi

log "Setup completed."
--//
64 changes: 0 additions & 64 deletions src/test/resources/userdata/linux-with-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config"

#cloud-config
package_update: true
packages:
- lvm2
- nfs-utils
- nfs-common
cloud_final_modules:
- [scripts-user, always]

Expand All @@ -39,62 +34,3 @@ log "Finished executing GoCD's user data script, now executing custom user data
log "Finished executing user specified user data script."

--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="initialize_instance_store"

#!/bin/bash
exec > >(tee /var/log/initialize_instance_store.log | logger -t user-data -s 2>/dev/console) 2>&1
function log() {
echo "[$(date "+%Y-%m-%d %H:%M:%S")] - $1" >> /var/log/initialize_instance_store.log
}

function try() {
$@
return 0
}

log "Starting to setup instance store for the docker."
INSTANCE_STORES=$(ls /dev/disk/by-id/*EC2_NVMe_Instance_Storage*-ns-1)

if [ -z "${INSTANCE_STORES}" ]; then
log "No instance store detected."
fi

VOLUMES="$INSTANCE_STORES"
if [ -e "/dev/xvdcz" ]; then
log "Instance has /dev/xvdcz EBS volume. Using it for docker logical volume group."
VOLUMES="$VOLUMES /dev/xvdcz"
fi

if [ -z "${VOLUMES}" ]; then
log "No addition volumes. Using box standard docker setup."
else
log "Available instance stores: ${VOLUMES}."
log "Setting up the docker logical volume group."

service docker stop
rm -rf /var/lib/docker/*
dmsetup remove_all

VOLUME_GROUP=docker
LOGICAL_VOLUME=docker-pool

try vgremove -y "${VOLUME_GROUP}"
try lvremove -y "${LOGICAL_VOLUME}"

vgcreate -y "${VOLUME_GROUP}" ${VOLUMES}
sleep 2
lvcreate -y -l 5%VG -n ${LOGICAL_VOLUME}\meta ${VOLUME_GROUP}
lvcreate -y -l 90%VG -n ${LOGICAL_VOLUME} ${VOLUME_GROUP}
sleep 2
lvconvert -y --zero n --thinpool ${VOLUME_GROUP}/${LOGICAL_VOLUME} --poolmetadata ${VOLUME_GROUP}/${LOGICAL_VOLUME}\meta
echo 'DOCKER_STORAGE_OPTIONS=" --storage-driver devicemapper --storage-opt dm.thinpooldev=/dev/mapper/docker-docker--pool --storage-opt dm.use_deferred_removal=true --storage-opt dm.use_deferred_deletion=true --storage-opt dm.fs=ext4 --storage-opt dm.use_deferred_deletion=true"' > /etc/sysconfig/docker-storage
test -f /bin/systemctl && systemctl reset-failed docker.service
service docker restart
test -f /bin/systemctl && systemctl enable --no-block --now ecs
fi

log "Setup completed."
--//
64 changes: 0 additions & 64 deletions src/test/resources/userdata/linux-with-docker-registry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config"

#cloud-config
package_update: true
packages:
- lvm2
- nfs-utils
- nfs-common
cloud_final_modules:
- [scripts-user, always]

Expand Down Expand Up @@ -40,62 +35,3 @@ log "Finished executing GoCD's user data script, now executing custom user data
log "Finished executing user specified user data script."

--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="initialize_instance_store"

#!/bin/bash
exec > >(tee /var/log/initialize_instance_store.log | logger -t user-data -s 2>/dev/console) 2>&1
function log() {
echo "[$(date "+%Y-%m-%d %H:%M:%S")] - $1" >> /var/log/initialize_instance_store.log
}

function try() {
$@
return 0
}

log "Starting to setup instance store for the docker."
INSTANCE_STORES=$(ls /dev/disk/by-id/*EC2_NVMe_Instance_Storage*-ns-1)

if [ -z "${INSTANCE_STORES}" ]; then
log "No instance store detected."
fi

VOLUMES="$INSTANCE_STORES"
if [ -e "/dev/xvdcz" ]; then
log "Instance has /dev/xvdcz EBS volume. Using it for docker logical volume group."
VOLUMES="$VOLUMES /dev/xvdcz"
fi

if [ -z "${VOLUMES}" ]; then
log "No addition volumes. Using box standard docker setup."
else
log "Available instance stores: ${VOLUMES}."
log "Setting up the docker logical volume group."

service docker stop
rm -rf /var/lib/docker/*
dmsetup remove_all

VOLUME_GROUP=docker
LOGICAL_VOLUME=docker-pool

try vgremove -y "${VOLUME_GROUP}"
try lvremove -y "${LOGICAL_VOLUME}"

vgcreate -y "${VOLUME_GROUP}" ${VOLUMES}
sleep 2
lvcreate -y -l 5%VG -n ${LOGICAL_VOLUME}\meta ${VOLUME_GROUP}
lvcreate -y -l 90%VG -n ${LOGICAL_VOLUME} ${VOLUME_GROUP}
sleep 2
lvconvert -y --zero n --thinpool ${VOLUME_GROUP}/${LOGICAL_VOLUME} --poolmetadata ${VOLUME_GROUP}/${LOGICAL_VOLUME}\meta
echo 'DOCKER_STORAGE_OPTIONS=" --storage-driver devicemapper --storage-opt dm.thinpooldev=/dev/mapper/docker-docker--pool --storage-opt dm.use_deferred_removal=true --storage-opt dm.use_deferred_deletion=true --storage-opt dm.fs=ext4 --storage-opt dm.use_deferred_deletion=true"' > /etc/sysconfig/docker-storage
test -f /bin/systemctl && systemctl reset-failed docker.service
service docker restart
test -f /bin/systemctl && systemctl enable --no-block --now ecs
fi

log "Setup completed."
--//
Loading

0 comments on commit 5376ec2

Please sign in to comment.