Skip to content

Instantly share code, notes, and snippets.

@ejlp12
Last active September 18, 2019 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ejlp12/2de4c657c83274a97dc37ec6a4352fe9 to your computer and use it in GitHub Desktop.
Save ejlp12/2de4c657c83274a97dc37ec6a4352fe9 to your computer and use it in GitHub Desktop.
Install Artifactory & Jenkins (with aws cli) using docker

Install Docker

sudo yum update -y
sudo amazon-linux-extras install docker
sudo service docker start
sudo systemctl enable docker
sudo usermod -a -G docker ec2-user
docker info

Install Artifactory

docker pull docker.bintray.io/jfrog/artifactory-oss:latest
#docker volume create --name artifactory5_data
mkdir -p $HOME/artifactory
sudo useradd -u 1030 artifactory
sudo chown artifactory $HOME/artifactory
docker run \
 --ulimit nofile="32000:32000" \
 --name artifactory -d --rm \
 -v $HOME/artifactory:/var/opt/jfrog/artifactory \
 -p 8081:8081 \
 docker.bintray.io/jfrog/artifactory-oss:latest

Login using username: admin password: password

Install Jenkins

mkdir -p $HOME/docker
cat > Dockerfile << __EOF__
FROM jenkinsci/blueocean

LABEL "description"="Image contain latest awscli on top on official Jenkins image."

COPY plugins.txt /usr/share/jenkins/plugins.txt
RUN /usr/local/bin/plugins.sh /usr/share/jenkins/plugins.txt

USER root
RUN apk add --no-cache --update \
    python \
    py-pip \
    build-base \
    && pip install awscli \
    && rm -rf /var/cache/apk/*

# Make sure you install the correct version: https://docs.aws.amazon.com/eks/latest/userguide/install-kubectl.html
RUN curl -o kubectl https://amazon-eks.s3-us-west-2.amazonaws.com/1.14.6/2019-08-22/bin/linux/amd64/kubectl \
    && curl -o kubectl.sha256 https://amazon-eks.s3-us-west-2.amazonaws.com/1.14.6/2019-08-22/bin/linux/amd64/kubectl.sha256 \
    && chmod +x ./kubectl \
    && cp kubectl /usr/local/bin/kubectl

# Check for newer version here: https://docs.aws.amazon.com/eks/latest/userguide/install-aws-iam-authenticator.html
RUN curl -o aws-iam-authenticator https://amazon-eks.s3-us-west-2.amazonaws.com/1.14.6/2019-08-22/bin/linux/amd64/aws-iam-authenticator \
    && curl -o curl -o aws-iam-authenticator.sha256 https://amazon-eks.s3-us-west-2.amazonaws.com/1.14.6/2019-08-22/bin/linux/amd64/aws-iam-authenticator.sha256 \
    && chmod +x ./aws-iam-authenticator \
    && cp aws-iam-authenticator /usr/local/bin/aws-iam-authenticator
    
USER jenkins
__EOF__

cat > plugins.txt << __EOF__
git:2.4.4
github-api:1.90
slack:2.0.1
bitbucket:1.1.5
amazon-ecs:1.22
gradle:1.24
terraform:1.0.4
amazon-ecr:1.6
__EOF__

sudo docker build -t jenkins-aws .

mkdir -p $HOME/jenkins
docker run \
  -u root \
  --rm \
  -d \
  -p 8080:8080 \
  -p 50000:50000 \
  -v $HOME/jenkins:/var/jenkins_home \
  -v /var/run/docker.sock:/var/run/docker.sock \
  jenkins-aws

Run this command to get the first password:

docker exec <CONTAINER_ID> sh -c "cat /var/jenkins_home/secrets/initialAdminPassword"

Test:

curl localhost:8080

If you'are using Cloud9, click "Preview > Preview Running Application" then click button "Pop Out Into New Window" Login using inital admin password, update plugin, then create Admin user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment