- Run Jenkins in Docker -
./jenkins-docker/controllerand./docker-compose.ci.yml- Attach build nodes as seperate containers -
./jenkins-docker/agent
- Attach build nodes as seperate containers -
- Run Jenkinsfile pipeline on our app -
./src- pylint, pytest, etc. -
./Jenkinsfile - Build image of our app and push to custom registry -
./Dockerfile.app
- pylint, pytest, etc. -
- Run custom Docker Registry -
./docker-compose.registry.yml
You may need DOCKER_BUILDKIT=0 to complete this pipeline.
# start local docker registry at localhost:5000
docker-compose -f ./docker-compose.registry.yml upThen we need jenkins-controller and jenkins-agent images in our custom registry.
# build Jenkins controller image and push to local registry
pushd jenkins-docker/controller
docker build -t jenkins-controller .
docker tag jenkins-controller:latest localhost:5000/jenkins-controller:latest
docker push localhost:5000/jenkins-controller:latest
popd# build Jenkins agent image and push to local registry
pushd jenkins-docker/agent
docker build -t jenkins-agent .
docker tag jenkins-agent:latest localhost:5000/jenkins-agent:latest
docker push localhost:5000/jenkins-agent:latest
popd# pull local controller and agent images and run
docker-compose -f ./docker-compose.ci.yml upWhen Jenkins is ready, visit http://localhost:8080/ to setup your first job. The default admin credentials are admin:admin. Create a "Pipeline" with any name. Configure your Jenkinsfile to pull from your SCM (or this repo) and provide credentials if necessary.
The jenkins-agent we built & ran before will already be connected to jenkins-controller
as a build node by this point. Visit http://localhost:8080/manage/computer/ to manage
connected nodes.
Once your Pipeline is setup, press the "Build Now" action in the sidebar to kick off the
first build process. It will begin executing steps from within Jenkinsfile which is
currently configured to lint code, run unit tests, build an image from Dockerfile.app
and then push that image to our local registry as demo-app:$BUILD_NUMBER.
You can confirm the entire pipeline completed by checking http://localhost:5000/v2/_catalog
to confirm that demo-app, jenkins-controller, and jenkins-agent are available in the
local registry.
Integrating this demo with your project shouldn't be too hard as most everything is automated and (currently) up-to-date. Here are my recommendations:
- Modify the
agent/Dockerfileto fit your Jenkins pipeline. This is currently setup with theubuntu:18.04base image,python3.9andpip3.9 - Move the
Jenkinsfileinto a seperate repo with thesrc/folder containing your app's code- Move
Dockerfile.appand.dockerignoretoo
- Move
- Use the remaining files as your CI repository