Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions train/labs/docker-jenkins/description.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Name: docker and jenkins

Description: environment with both docker and jenkins installed

Prompt and install a specific version of Docker
19 changes: 19 additions & 0 deletions train/labs/docker-jenkins/instances.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ... instances ...
# ~~~~~~~~~~~~~~~~~

[[instance]]
COUNT = "PROMPT#:How many instances would you like to launch"
SCRIPT = "PRIMARY"
NAME = "PROMPT:Enter a custom AWS 'Name' tag"
AMI_KEY = "PRIMARY_OS"
ZONE = 1
INSTANCE_TYPE = "t2.medium"
SECURITY_GROUPS = ["default"]
ELASTIC_IP = false

[[instance.device]]
DEVICE = "/dev/sda1"
FILESYSTEM = "ext4"
MOUNT = "/"
SIZE = 10
DELETE_ON_TERMINATE = true
173 changes: 173 additions & 0 deletions train/labs/docker-jenkins/scripts/ubuntu-18.04.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys


import requests


# helper functions
def check_url(path, version):
"""Check for valid URL"""
print 'Checking URL: https://{0}/docker-{1}'.format(path, version)
return 'https://{0}/docker-{1}'.format(path, version)


def get_txt(path, version):
"""Custom Docker install text"""
txt = 'curl -sSL https://get.docker.com/ | sh\n'.format(path) + \
'mv /usr/bin/docker /usr/bin/docker.org\n' + \
'wget https://{0}/docker-{1} -O /usr/bin/docker\n'.format(path, version) + \
'chmod +x /usr/bin/docker\n'
return txt


def get_custom(prompt):
"""Prompt for custom Docker version"""

version = raw_input(prompt)
if 'rc' in version:
path = 'test.docker.com/builds/Linux/x86_64'
elif 'dev' in version:
path = 'master.dockerproject.org/linux/amd64'
else:
path = 'get.docker.com/builds/Linux/x86_64'

r = requests.head(check_url(path, version))
if r.status_code != 200:
print 'Unable to locate specified version.'
txt = get_custom('\nEnter a different version: ')
else:
txt = get_txt(path, version)

return txt


# prompts
os.system('clear')
docker = raw_input("""
Which version of Docker do you want to install?

- latest (default)
- cs
- rc
- experimental (nightly)
- master (github master branch)
- custom

Enter version (Press enter for default): """)

# example urls
#https://get.docker.com/builds/Linux/x86_64/docker-latest
#https://test.docker.com/builds/Linux/x86_64/docker-1.6.0-rc6
#https://master.dockerproject.com/linux/amd64/docker-1.5.0-dev

docker = docker.lower()
if docker == '' or docker =='latest':
txt = 'curl -sSL https://get.docker.com/ | sh'
elif docker == 'cs':
txt = "curl -s 'https://sks-keyservers.net/pks/lookup?op=get&search=0xee6d536cf7dc86e2d7d56f59a178ac6c6238f52e' | apt-key add --import\n" + \
'echo "deb https://packages.docker.com/1.13/apt/repo ubuntu-xenial main" | tee /etc/apt/sources.list.d/docker.list\n' + \
'apt-get update && apt-get install -y docker-engine\n'

elif docker == 'rc':
txt = 'curl -faSL https://test.docker.com/ | sh'
elif docker == 'experimental':
txt = 'curl -fsSL https://experimental.docker.com/ | sh'
elif docker == 'master':
r = requests.get('https://master.dockerproject.org/version')
txt = get_txt('master.dockerproject.org/linux/amd64', r.text)
elif docker == 'custom':
txt = get_custom('Enter version: ')
else:
print "ERROR: Not a valid option."
sys.exit()


# instance configs
PRIMARY_OS = 'Ubuntu-18.04'
PRIMARY = '''#!/bin/sh

FQDN="{{fqdn}}"

export DEBIAN_FRONTEND=noninteractive

# locale
locale-gen en_US.UTF-8

# hostname
hostnamectl set-hostname $FQDN
sed -i "1 c\\127.0.0.1 $FQDN localhost" /etc/hosts

# updates
apt-get update && apt-get install -y \
apt-transport-https \
git \
jq \
linux-image-extra-$(uname -r) \
linux-image-extra-virtual \
tree

# docker
{0}

systemctl start docker
sleep 15

usermod -aG docker ubuntu

# compose
sudo curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

sleep 15

# install java jre 8 to jenkins from
# http://www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html

sudo add-apt-repository ppa:webupd8team/java -y
sudo apt-get update
echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections
sudo apt install oracle-java8-installer -y

#install jenkins from
# https://www.digitalocean.com/community/tutorials/how-to-install-jenkins-on-ubuntu-18-04

wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt update
sudo apt install jenkins -y

sleep 5

sudo usermod -aG docker jenkins
sudo systemctl restart jenkins


{{dinfo}}
reboot
'''.format(txt)

# Script to use if launching from a custom lab AMI image
AMIBUILD = '''#!/bin/sh
#
FQDN="{{fqdn}}"

# hostname
hostnamectl set-hostname $FQDN
sed -i "1 c\\127.0.0.1 $FQDN localhost" /etc/hosts

{{dinfo}}
reboot
'''.format()


def pre_process():
"""Executed before launching instances in AWS"""
pass

def post_process():
"""Executed after launching instances in AWS"""
pass
11 changes: 10 additions & 1 deletion train/vpc/amis.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'Ubuntu-14.04': 'ami-5abca75b',
'Ubuntu-15.10': 'ami-3f3fd75e',
'Ubuntu-16.04': 'ami-5d38d93c',
'Ubuntu-18.04': 'ami-0ee0b7ac4daa15e1d',
}

AP_SOUTHEAST_1 = {
Expand All @@ -29,6 +30,7 @@
'Ubuntu-14.04': 'ami-36c6ec64',
'Ubuntu-15.10': 'ami-d466b6b7',
'Ubuntu-16.04': 'ami-a35284c0',
'Ubuntu-18.04': 'ami-0c6ef74bad2072c66',
}

AP_SOUTHEAST_2 = {
Expand All @@ -42,6 +44,7 @@
'Ubuntu-14.04': 'ami-e7eb9fdd',
'Ubuntu-15.10': 'ami-a9371eca',
'Ubuntu-16.04': 'ami-f4361997',
'Ubuntu-18.04': 'ami-0e6ce0687847cf41d',
}

EU_CENTRAL_1 = {
Expand All @@ -53,6 +56,7 @@
'Ubuntu-14.04': 'ami-4ec4f653',
'Ubuntu-15.10': 'ami-8ebe57e1',
'Ubuntu-16.04': 'ami-f9e30f96',
'Ubuntu-18.04': 'ami-0d9634d5c860a3200',
}

EU_WEST_1 = {
Expand All @@ -66,6 +70,7 @@
'Ubuntu-14.04': 'ami-f5810f82',
'Ubuntu-15.10': 'ami-2dbe225e',
'Ubuntu-16.04': 'ami-7a138709',
'Ubuntu-18.04': 'ami-0d137679f8243e9f8',
}

SA_EAST_1 = {
Expand All @@ -79,6 +84,7 @@
'Ubuntu-14.04': 'ami-55f14e48',
'Ubuntu-15.10': 'ami-ced75da2',
'Ubuntu-16.04': 'ami-0d5dd561',
'Ubuntu-18.04': 'ami-0647fa5bfc1359838',
}

US_EAST_1 = {
Expand All @@ -93,7 +99,8 @@
'Ubuntu-12.04': 'ami-427a392a',
'Ubuntu-14.04': 'ami-767a391e',
'Ubuntu-15.10': 'ami-5fbc4632',
'Ubuntu-16.04': 'ami-13be557e'
'Ubuntu-16.04': 'ami-13be557e',
'Ubuntu-18.04': 'ami-0b425589c7bb7663d'
}

US_WEST_1 = {
Expand All @@ -108,6 +115,7 @@
'Ubuntu-14.04': 'ami-8ebba3cb',
'Ubuntu-15.10': 'ami-610d4801',
'Ubuntu-16.04': 'ami-84423ae4',
'Ubuntu-18.04': 'ami-0926eb6fbfa35a8aa',
}

US_WEST_2 = {
Expand All @@ -123,4 +131,5 @@
'Ubuntu-15.10': 'ami-0af8026a',
'Ubuntu-16.04': 'ami-06b94666',
'JTU-LDAP': 'ami-25f83c45',
'Ubuntu-18.04': 'ami-944162ec',
}