DEV Community

Jay Watson
Jay Watson

Posted on • Edited on

Serverless Jenkins: ECS on Fargate - Simple Setup

Are you ready to deploy serverless Jenkins to ECS on Fargate?

Before we get started, let's define some terms.

  • Serverless - You aren't managing the infrastructure. AWS is.
  • ECS - AWS container orchestration platform allowing you to deploy and manage containerized applications.
  • Fargate - Serverless compute engine (see above). You can run ECS on EC2s (AWS VMs) or Fargate. Choose serverless.
  • ECS Cluster - A logical group of tasks/services. You'll create this first when hosting an app in ECS.
  • ECS Task Definition - A blueprint for your application telling ECS how to run your container.
  • ECS Task - The instantiation of a task definition, meaning that you're running the container now.
  • ECS Service - Runs/maintains a specified number of task definitions simultaneously.
  • Container - A unit of software that packages needed code/dependencies for an app to run.
  • Image - Standalone file used to create the container.
  • Docker - The most popular container service provider.

Now, we're ready to get started. Let's do this thing!

First, create the ECS cluster. Use default settings. Don't overcomplicate things. Make sure AWS Fargate (serverless) is selected.

Screenshot of ECS cluster creation

Second, let's find our container image and test it locally (you'll need docker installed!). Go to dockerhub.com and search for Jenkins. Then, click on Jenkins/Jenkins and copy the command.

Screenshot of Jenkins in DockerHub

Use docker pull jenkins/jenkins to pull the image to your local machine.

To test it locally, create a directory for the Jenkins volume and then run the image.

mkdir jenkins_volume

docker run -p 8080:8080 -p 50000:50000 -v jenkins_volume:/var/jenkins_home jenkins/Jenkins

Jenkins Docker terminal

Grab the password from the terminal, open your browser, and visit localhost:8080. Put in the password and sweeeeeet! It works...hopefully. Now, go ahead and close it down (ctrl + c). That was to test things out.

Third, we need to create a task definition. Specify jenkins/jenkins as the image URL. ECS will know to pull it from DockerHub. Use 8080 for the container port.

Task defintion

Task definition screenshot 2

Click Create and you're gtg.

Fourth, go to your cluster and create a service. Use mostly default settings.

Screenshot of cluster service creation

Screenshot of service creation

Do specify that you want an Application Load Balancer (ALB). We'll just listen on port 80 for now. Of course, that should be 443.

Service creation - ALB

Click Create. Now, we wait. You can follow the progress by clicking View in CloudFormation, but who's that patient?

Get the password from the ECS logs, then go to EC2 -> Load Balancers -> your jenkins fargate load balancer to grab the URL. You'll put the password in just like you did when you ran docker locally.

Screenshot of logs

Screenshot of load balancer

Finished...whoops...not yet. We need to edit the ALB Target Group health check.

From the ALB, click on your ECS Fargate Target Group.

ALB target group

Edit your Target Group health check configuration to use port 8080 and path /login?from=%2F

Target Group health check configuration

Now, you're finished!! 🎉🎉🎉

Top comments (0)