Forked from fancyremarker/.bash_login.jenkins
Last active
September 21, 2017 11:50
-
-
Save eoin-obrien/cdba8f2784ba71530034a40d4d24ecf3 to your computer and use it in GitHub Desktop.
Jenkins slave setup scripes
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
# if running bash | |
if [ -n "$BASH_VERSION" ]; then | |
# include .bashrc if it exists | |
if [ -f "$HOME/.bashrc" ]; then | |
. "$HOME/.bashrc" | |
fi | |
fi |
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
#!/usr/bin/env bash | |
# As root ( via `sudo su -` ): | |
# Initialize ephemeral storage | |
curl https://gist.githubusercontent.com/eoin-obrien/cdba8f2784ba71530034a40d4d24ecf3/raw/ephemeral > /etc/init.d/ephemeral | |
chmod +x /etc/init.d/ephemeral | |
ln -s ../init.d/ephemeral /etc/rcS.d/S10ephemeral | |
/etc/init.d/ephemeral | |
ln -s /mnt/jenkins /var/jenkins | |
ln -s /mnt/mongodb /var/lib/mongodb | |
ln -s /mnt/tmp /tmp | |
# Set logrotate to keep only one unit (day or week) of each log | |
for f in /etc/logrotate.d/* /etc/logrotate.conf ; do | |
sed -i 's/rotate [0-9]*$/rotate 1/' $f | |
done | |
apt-get update | |
apt-get install -y git build-essential openssl curl | |
# Jenkins spot request setup | |
apt-get install -y openjdk-8-jre wget python | |
# Install MongoDB | |
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6 | |
echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list | |
apt-get update -y | |
apt-get install -y mongodb-org | |
chown -R mongodb:mongodb /mnt/mongodb | |
service mongod start | |
# Set up Jenkins spot instance callbacks | |
curl https://gist.githubusercontent.com/eoin-obrien/cdba8f2784ba71530034a40d4d24ecf3/raw/jenkins-spot-setup.py >> /usr/local/bin/jenkins-spot-setup.py | |
chmod +x /usr/local/bin/jenkins-spot-setup.py | |
sed -i 's/^exit 0$/sudo -i -u jenkins python \/usr\/local\/bin\/jenkins-spot-setup.py\n&/' /etc/rc.local | |
# Set up Redis | |
apt-get install -y redis-server | |
# User-level setup | |
useradd -k /etc/skel -m -s /bin/bash jenkins | |
mkdir /home/jenkins/.ssh | |
cp /home/ubuntu/.ssh/authorized_keys /home/jenkins/.ssh/authorized_keys | |
chown -R jenkins:jenkins /home/jenkins/.ssh | |
chmod 700 /home/jenkins/.ssh | |
chmod 600 /home/jenkins/.ssh/authorized_keys | |
curl https://gist.githubusercontent.com/eoin-obrien/cdba8f2784ba71530034a40d4d24ecf3/raw/sudoers.wheel >> /etc/sudoers | |
groupadd wheel | |
usermod -G wheel jenkins | |
mkdir -p /var/jenkins/workspace | |
chown -R jenkins:jenkins /var/jenkins |
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 | |
# As user jenkins ( via `sudo su - jenkins` ): | |
sudo su -l jenkins | |
ssh-keygen -q -t rsa -N "" -f .ssh/id_rsa | |
# Install Node.js with nvm | |
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.4/install.sh | bash | |
export NVM_DIR="$HOME/.nvm" | |
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm | |
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion | |
nvm install v8 | |
nvm alias default v8 | |
nvm use v8 | |
# Install Gulp | |
npm install -g gulp-cli | |
# Bash config | |
curl https://gist.githubusercontent.com/eoin-obrien/cdba8f2784ba71530034a40d4d24ecf3/raw/.bash_login.jenkins > /home/jenkins/.bash_login | |
curl https://gist.githubusercontent.com/eoin-obrien/cdba8f2784ba71530034a40d4d24ecf3/raw/ssh_config >> /home/jenkins/.ssh/config |
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
#!/usr/bin/env bash | |
# Initialize ephemeral storage on /mnt | |
mkdir -p /mnt/jenkins/workspace | |
chown -R jenkins:jenkins /mnt/jenkins | |
mkdir -p /mnt/mongodb | |
chown mongodb:mongodb /mnt/mongodb | |
mkdir -p /mnt/tmp | |
chmod 1777 /mnt/tmp |
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
#!/usr/bin/env python | |
import os | |
import httplib | |
import string | |
import base64 | |
conn = httplib.HTTPConnection("169.254.169.254") | |
conn.request("GET", "/latest/user-data") | |
response = conn.getresponse() | |
userdata = response.read() | |
args = string.split(userdata, "&") | |
jenkinsUrl = "" | |
jenkinsAuth = "" | |
slaveName = "" | |
for arg in args: | |
if arg.split("=")[0] == "JENKINS_URL": | |
jenkinsUrl = arg.split("=")[1] | |
if arg.split("=", 1)[0] == "USER_DATA": | |
subarg = base64.b64decode(arg.split("=", 1)[1]) | |
if subarg.split("=")[0] == "JENKINS_AUTH": | |
jenkinsAuth = subarg.split("=")[1] | |
if arg.split("=")[0] == "SLAVE_NAME": | |
slaveName = arg.split("=")[1] | |
os.system("wget " + jenkinsUrl + "jnlpJars/slave.jar -O slave.jar") | |
os.system("java -jar slave.jar -jnlpCredentials " + jenkinsAuth + " -jnlpUrl " + jenkinsUrl + "computer/" + slaveName + "/slave-agent.jnlp") |
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
#!/usr/bin/env bash | |
curl -L https://gist.githubusercontent.com/eoin-obrien/cdba8f2784ba71530034a40d4d24ecf3/raw/_base-setup.sh | sudo bash -s | |
sudo su -l jenkins | |
curl -L https://gist.githubusercontent.com/eoin-obrien/cdba8f2784ba71530034a40d4d24ecf3/raw/_jenkins-user-setup.sh | bash -s |
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
Host github.com | |
StrictHostKeyChecking no | |
Host heroku.com | |
StrictHostKeyChecking no | |
Host * | |
ServerAliveInterval 15 |
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
%wheel ALL=(ALL) NOPASSWD: ALL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment