Part two of an N part series: My first steps into trying to compile an Android app via Jenkins in docker. Covers the initial set up of a Jenkins server on a QNAP NAS in docker and the realisation that this project can be so much more...
Step One: Creating and connecting the server to GitHub
To begin our journey, I knew that first I would need to head on over to the Docker hub and to find the official Jenkins image: https://hub.docker.com/r/jenkins/jenkins
This should have everything we need to set up some pipelines on my QNAP NAS in Container Station - and even better! There's a tag with the JDK already installed - this might be perfect for building an Android app no? (Spoiler, it wasn't!)
So let's get the jenkins/jenkins:lts-jdk17 image pulled locally to our NAS...
Okay, so far so good, now let's create a new volume for our Jenkins server's future home directory, so we don't lose any data between container restarts:
And finally, with the basics done, we can move on to the good stuff: Creating a container that will have a running server inside of it! First, let's tell Container Station that we want to use the image we just downloaded:
And then let's configure our container with a name & ensure that port 8080 is exposed (but not 50000 as we're not interested in allowing any Jenkins workers to connect to our main server in this setup)
And thinking of stuff we probably don't need... Full access to our RAM is likely overkill too - this is still a media server too after all - so let's try limiting it to 1GB for now to see how that handles the load:
And for the last step, let's configure the home directory to use that volume that we created earlier:
Once the initial setup wizard is taken care of, it's a simple case of creating our first pipeline! Let's just add the SSH key to clone my repo annnnnd oh. Okay, well, problems are normal and to be expected:
Let's see, Google, StackExchange - aha! Got you!
A bit of SSH magic later via a terminal inside of our container et voilà!
Let's try running against our script (stored in a Jenkinsfile inside of git of course!)...
pipeline {
agent any
stages {
stage('Example') {
steps {
echo 'Hello World'
sh './gradlew clean build'
}
}
}
}
And we are in business!
But oh. I should've seen this coming... Jenkins may have the JDK but it definitely doesn't have the Android SDK... So the build fails...
Well, this could be as simple as writing a new Dockerfile... But let's face it - this tutorial is much closer to what would actually be useful.
I started this project with a goal, but why should I build a one trick pony? A Jenkins server that can only build my Android apps? What if I write some TypeScript? .NET? ? Will I always restart my Jenkins server/make one big, complex, Dockerfile/image?
No. We can do better than that and should do better than that:
- Jenkins server running in a container - Done already ✔
- Builds running in ephemeral Jenkins container agents defined by Dockerfiles/images - I've done this before ✔
- Container with docker installed managing docker on the host - I've done this before too ✔
The result of this should be:
- A single Dockerfile that defines how to create my Jenkins server, that can be stored in git!
- A Dockerfile/Image reference per project, that can contain all of the tooling I need, stored in git!
Which when I consider the origins of this little project I think I'm sold! My own build system, almost entirely defined as & reproducible as code
Top comments (1)
Part three released: dev.to/dotdashnotdot/compiling-and...