From d2760cc3e3a6324596fceeb1ef7245a93e2997c7 Mon Sep 17 00:00:00 2001 From: Vector Nguyen Date: Tue, 2 Jan 2024 14:16:40 +0700 Subject: [PATCH] CICD with Jenkins --- Jenkinsfile | 21 +++++++++++++++++++ jenkins/README.md | 40 +++++++++++++++++++++++++++++++++++++ jenkins/docker-compose.yaml | 15 ++++++++++++++ jenkins/run_env/.gitkeep | 0 4 files changed, 76 insertions(+) create mode 100644 Jenkinsfile create mode 100644 jenkins/README.md create mode 100644 jenkins/docker-compose.yaml create mode 100644 jenkins/run_env/.gitkeep diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..e895c92 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,21 @@ +pipeline { + agent any + + stages { + stage('Build') { + steps { + echo 'Building something..' + } + } + stage('Test') { + steps { + echo 'Testing something..' + } + } + stage('Deploy') { + steps { + echo 'Deploying something..' + } + } + } +} diff --git a/jenkins/README.md b/jenkins/README.md new file mode 100644 index 0000000..156e5a7 --- /dev/null +++ b/jenkins/README.md @@ -0,0 +1,40 @@ +# Official Jenkins Docker image + +[![Docker Stars](https://img.shields.io/docker/stars/jenkins/jenkins.svg)](https://hub.docker.com/r/jenkins/jenkins/) +[![Docker Pulls](https://img.shields.io/docker/pulls/jenkins/jenkins.svg)](https://hub.docker.com/r/jenkins/jenkins/) +[![Join the chat at https://gitter.im/jenkinsci/docker](https://badges.gitter.im/jenkinsci/docker.svg)](https://gitter.im/jenkinsci/docker?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + +The Jenkins Continuous Integration and Delivery server [available on Docker Hub](https://hub.docker.com/r/jenkins/jenkins). + +This is a fully functional Jenkins server. +[https://jenkins.io/](https://jenkins.io/). + + + +# Usage + +``` +docker run -p 8080:8080 -p 50000:50000 --restart=on-failure jenkins/jenkins:lts-jdk17 +``` + +NOTE: read the section [_Connecting agents_](#connecting-agents) below for the role of the `50000` port mapping. + +This will store the workspace in `/var/jenkins_home`. +All Jenkins data lives in there - including plugins and configuration. +You will probably want to make that an explicit volume so you can manage it and attach to another container for upgrades : + +``` +docker run -p 8080:8080 -p 50000:50000 --restart=on-failure -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts-jdk17 +``` + +This will automatically create a 'jenkins_home' [docker volume](https://docs.docker.com/storage/volumes/) on the host machine. +Docker volumes retain their content even when the container is stopped, started, or deleted. + +NOTE: Avoid using a [bind mount](https://docs.docker.com/storage/bind-mounts/) from a folder on the host machine into `/var/jenkins_home`, as this might result in file permission issues (the user used inside the container might not have rights to the folder on the host machine). +If you _really_ need to bind mount jenkins_home, ensure that the directory on the host is accessible by the jenkins user inside the container (jenkins user - uid 1000) or use `-u some_other_user` parameter with `docker run`. + +``` +docker run -d -v jenkins_home:/var/jenkins_home -p 8080:8080 -p 50000:50000 --restart=on-failure jenkins/jenkins:lts-jdk17 +``` + +This will run Jenkins in detached mode with port forwarding and volume added. You can access logs with command 'docker logs CONTAINER_ID' in order to check first login token. ID of container will be returned from output of command above. diff --git a/jenkins/docker-compose.yaml b/jenkins/docker-compose.yaml new file mode 100644 index 0000000..337b62c --- /dev/null +++ b/jenkins/docker-compose.yaml @@ -0,0 +1,15 @@ +version: "3.7" +services: + jenkins: + image: jenkins/jenkins:lts + privileged: true + user: root + ports: + - 8081:8080 + - 50000:50000 + container_name: jenkins + volumes: + - ./run_env/jenkins_home:/var/jenkins_home + - /var/run/docker.sock:/var/run/docker.sock + - /usr/bin/docker:/usr/bin/docker + - /usr/local/bin/docker-compose:/usr/bin/docker-compose diff --git a/jenkins/run_env/.gitkeep b/jenkins/run_env/.gitkeep new file mode 100644 index 0000000..e69de29