Skip to content

Instantly share code, notes, and snippets.

@haskins-io
Last active March 3, 2017 20:33
Show Gist options
  • Save haskins-io/9264cda49c22b25511aaffeda1da3017 to your computer and use it in GitHub Desktop.
Save haskins-io/9264cda49c22b25511aaffeda1da3017 to your computer and use it in GitHub Desktop.
Attach EBS Volume to Beanstalk Docker
commands:
01clear-if-unmounted:
command: if ! mount | grep /media/nexus-data-ebs > /dev/nul; then rm -rf /media/nexus-data-ebs; fi
02attach-volume:
command: aws ec2 attach-volume --region eu-west-1 --volume-id vol-xxxxxxxx --instance-id $(curl -s http://169.254.169.254/latest/meta-data/instance-id) --device /dev/sdh
ignoreErrors: true
03wait:
command: sleep 10
04trymount:
command: |
mkdir /media/nexus-data-ebs
mount /dev/sdh /media/nexus-data-ebs
ignoreErrors: true
05format-if-not-already:
command: if find /media/nexus-data-ebs -maxdepth 0 -empty | read v; then mkfs -t ext3 /dev/sdh; fi
06mount-volume:
command: |
mkdir /media/nexus-data-ebs
mount /dev/sdh /media/nexus-data-ebs
ignoreErrors: true
07restart-docker:
command: service docker restart # We must restart Docker daemon or it wont' see the new mount

Create a Beanstalk Application / Environment that uses Docker.

Zip up both the files above and create a new Application Version.

Deploy the version to an environment. Within x minutes Nexus will be up and running

{
"AWSEBDockerrunVersion": "1",
"Image": {
"Name": "sonatype/nexus3",
"Update": "true"
},
"Ports": [
{
"ContainerPort": "8081"
}
],
"Volumes": [
{
"HostDirectory": "/media/nexus-data-ebs",
"ContainerDirectory": "/nexus-data"
}
],
"Logging": "/var/log/nexus"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment