Skip to content

Commit

Permalink
Get the Jenkins worker image working (#178)
Browse files Browse the repository at this point in the history
* Get the Jenkins worker image working

This image hadn't been touched in years, and wasn't working.

The original base image was using an unsupported version of
Debian, so also switch to a more recent base image.

Also use this opportunity to update Docker and AWS CLI tool.

* Update README with latest version for jenkins-worker

---------

Co-authored-by: MartinWheelerMT <[email protected]>
  • Loading branch information
adrianclay and MartinWheelerMT authored Aug 15, 2024
1 parent 3f0cb75 commit affec6f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 50 deletions.
18 changes: 9 additions & 9 deletions pipeline/packer/jenkins-worker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM jenkins/jnlp-slave:latest
FROM jenkins/jnlp-slave:4.13.3-1

# Need to be root to install packages
USER root
Expand All @@ -7,7 +7,8 @@ USER root
RUN rm -rf /var/lib/apt/lists/* && apt update

# Install Packer
RUN wget -O packer.zip https://releases.hashicorp.com/packer/1.4.2/packer_1.4.2_linux_amd64.zip && \
RUN apt-get install wget unzip && \
wget -O packer.zip https://releases.hashicorp.com/packer/1.4.2/packer_1.4.2_linux_amd64.zip && \
unzip packer.zip -d /usr/bin/ && \
rm packer.zip

Expand All @@ -17,7 +18,7 @@ RUN wget -O terraform.zip https://releases.hashicorp.com/terraform/0.12.31/terra
rm terraform.zip

# Install Python 3.9
RUN apt-get update && apt-get install -y build-essential checkinstall libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev libgdbm-dev libc6-dev libbz2-dev uuid-dev zlib1g-dev libffi-dev swig pkg-config && \
RUN apt-get update && apt-get install -y build-essential libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev libgdbm-dev libc6-dev libbz2-dev uuid-dev zlib1g-dev libffi-dev swig pkg-config && \
wget -O python.tgz https://www.python.org/ftp/python/3.9.19/Python-3.9.19.tgz && \
tar -xf python.tgz && rm python.tgz && \
cd Python-3.9.19 && \
Expand All @@ -44,18 +45,17 @@ RUN apt-get update && \
apt-key fingerprint 0EBFCD88 && \
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" && \
apt-get update && \
apt-get install -qq -y --no-install-recommends docker-ce=5:19.03.6~3-0~debian-stretch && \
curl -L https://github.com/docker/compose/releases/download/1.27.4/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose && \
chmod +x /usr/local/bin/docker-compose
apt-get install -qq -y --no-install-recommends docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin && \
echo 'docker compose --compatibility "$@"' > /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose

# Install curl and libSSL, so Tornado can use the CURL HTTP client.
RUN apt-get update && apt-get install -y libcurl4-openssl-dev libssl-dev

# Install awscli
ENV AWS_CLI_VERSION="1.16.312"
RUN curl https://s3.amazonaws.com/aws-cli/awscli-bundle-${AWS_CLI_VERSION}.zip -o awscli-bundle.zip && \
ENV AWS_CLI_VERSION="2.17.27"
RUN curl https://awscli.amazonaws.com/awscli-exe-linux-x86_64-${AWS_CLI_VERSION}.zip -o awscli-bundle.zip && \
unzip awscli-bundle.zip && \
./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws && \
./aws/install && \
rm -rf aws*

# Cleanup
Expand Down
24 changes: 18 additions & 6 deletions pipeline/packer/jenkins-worker/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
# Jenkins worker image

The files in this folder are used to create the image of a Jenkins worker for the Jenkin [amazon-ecs plugin](https://wiki.jenkins.io/display/JENKINS/Amazon+EC2+Container+Service+Plugin).
The files in this folder are used to create the image of a Jenkins worker for the Jenkins [amazon-ecs plugin].

[amazon-ecs plugin]: https://wiki.jenkins.io/display/JENKINS/Amazon+EC2+Container+Service+Plugin

Usage:
1. Make sure you're logged into AWS with the appropriate credentials on your computer.
2. Run these commands:
```bash
docker build -t temporary/jenkins-worker:latest .
DOCKER_REGISTRY=nameOfDockerRegistry BUILD_TAG=buildTag packer build jenkins-worker.json
```
2. Find out what the latest version of the jenkins-worker is by searching inside the `jenkins-worker` ECR registry.
3. You can either replace the current build, if your change is low-risk, or create a new version allowing you
the ability to rollback.
4. Run these commands, specifying the version you wish to publish as.
```shell
VERSION=0.6
REGISTRY="$(aws sts get-caller-identity --query 'Account' --output text).dkr.ecr.eu-west-2.amazonaws.com"
aws ecr get-login-password --region eu-west-2 | docker login -u AWS --password-stdin $REGISTRY
docker buildx build --platform linux/amd64 --tag $REGISTRY/jenkins-worker:$VERSION --push .
```
5. If you have specified a new version, you'll need to generate a new ECS Task Definition revision pointing to
that image label.
You can then specify that revision within Jenkins -> Configure System -> ECS agent template -> Task Definition Override,
All subsequent Jenkins builds will use that new worker image, and if you want to rollback the previous revision
can be placed within the Task Definition Overview box.
35 changes: 0 additions & 35 deletions pipeline/packer/jenkins-worker/jenkins-worker.json

This file was deleted.

0 comments on commit affec6f

Please sign in to comment.