Update README.md
This commit is contained in:
+44
-42
@@ -1,13 +1,15 @@
|
|||||||
# Jenkins (Controller + Docker Agent) Setup (Docker Compose)
|
# Jenkins Controller + Docker Agent (Docker Compose)
|
||||||
|
|
||||||
This directory contains a minimal Jenkins setup using a dedicated **controller** and a separate inbound **agent** intended for Docker-based workloads.
|
This directory contains a minimal Jenkins setup running as Docker containers:
|
||||||
|
- `jenkins-controller`: Jenkins UI + configuration (no builds should run here).
|
||||||
|
- `jenkins-agent-docker`: inbound agent used for Docker-based pipelines (label: `docker-agent`).
|
||||||
|
|
||||||
The goal is to keep the controller responsible for orchestration and configuration, while all builds run on the agent labeled `docker`.
|
The goal is to keep the controller responsible for orchestration/configuration while all CI jobs run on the dedicated agent.
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
- Docker Engine installed on the host
|
- Docker Engine installed on the host.
|
||||||
- Docker Compose available as `docker compose`
|
- Docker Compose available as `docker compose`.
|
||||||
- A host directory `/opt/shagram` (used by pipelines as a shared location for source code and deployment files)
|
- A host directory `/opt/shagram` (used by pipelines as a shared location for source code and deployment files).
|
||||||
|
|
||||||
## Start Jenkins
|
## Start Jenkins
|
||||||
From the repository root:
|
From the repository root:
|
||||||
@@ -20,59 +22,59 @@ docker compose ps
|
|||||||
|
|
||||||
Jenkins UI will be available at:
|
Jenkins UI will be available at:
|
||||||
|
|
||||||
- http://<server-ip>:8080
|
```text
|
||||||
|
http://<server-ip>:8080
|
||||||
### Initial admin password
|
|
||||||
Retrieve the initial password with:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
docker exec -it jenkins-controller cat /var/jenkins_home/secrets/initialAdminPassword
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Disable builds on the built-in node (Executors = 0)
|
## Initial admin password
|
||||||
|
Retrieve the initial password:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker exec -it jenkins-controller \
|
||||||
|
cat /var/jenkins_home/secrets/initialAdminPassword
|
||||||
|
```
|
||||||
|
|
||||||
|
## Disable builds on the controller
|
||||||
To ensure builds do not run on the controller:
|
To ensure builds do not run on the controller:
|
||||||
|
1. Open Jenkins UI.
|
||||||
|
2. Go to: `Manage Jenkins` → `Manage Nodes and Clouds`.
|
||||||
|
3. Open: `Built-In Node` → `Configure`.
|
||||||
|
4. Set **Number of executors** to `0`.
|
||||||
|
5. Save.
|
||||||
|
|
||||||
1. Open Jenkins UI
|
## Configure the inbound agent node
|
||||||
2. Go to: **Manage Jenkins → Manage Nodes and Clouds**
|
|
||||||
3. Open **Built-In Node → Configure**
|
|
||||||
4. Set **Number of executors** to `0`
|
|
||||||
5. Save
|
|
||||||
|
|
||||||
## Create an inbound agent node (docker-agent)
|
|
||||||
Create a dedicated node for running pipelines:
|
Create a dedicated node for running pipelines:
|
||||||
|
1. `Manage Jenkins` → `Manage Nodes and Clouds` → `New Node`.
|
||||||
1. Go to: **Manage Jenkins → Manage Nodes and Clouds → New Node**
|
|
||||||
2. Set:
|
2. Set:
|
||||||
- **Node name**: `docker-agent`
|
- Node name: `docker-agent`
|
||||||
- **Type**: Permanent Agent
|
- Type: `Permanent Agent`
|
||||||
- **Remote root directory**: `/home/jenkins/agent`
|
- Remote root directory: `/home/jenkins/agent`
|
||||||
- **Labels**: `docker`
|
- Labels: `docker-agent` (must match your Jenkinsfile `agent { label ... }`)
|
||||||
- **Usage**: Only build jobs with label expressions matching this node
|
- Usage: “Only build jobs with label expressions matching this node”
|
||||||
3. Save
|
3. Save.
|
||||||
|
|
||||||
After saving, open the agent page:
|
After saving, open the agent page:
|
||||||
|
- `Manage Nodes and Clouds` → `docker-agent`
|
||||||
|
|
||||||
- **Manage Nodes and Clouds → docker-agent**
|
On that page Jenkins will show the inbound connection details, including the **secret** required by the inbound agent container.
|
||||||
|
|
||||||
On that page, Jenkins provides the inbound connection details, including the **secret** required by the inbound agent container.
|
## Set agent secret in Compose
|
||||||
|
Edit `infra/jenkins/compose.yaml` and replace the placeholder with the real secret value shown on the `docker-agent` node page:
|
||||||
|
|
||||||
## Configure the agent secret in Compose
|
- `JENKINS_SECRET=PASTE_ME`
|
||||||
Edit `infra/jenkins/compose.yaml` and replace:
|
|
||||||
|
|
||||||
- `JENKINS_SECRET=__PASTE_ME__`
|
Then restart only the agent container:
|
||||||
|
|
||||||
with the real secret value shown on the `docker-agent` node page.
|
|
||||||
|
|
||||||
Restart only the agent container:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker compose up -d --force-recreate jenkins-agent-docker
|
docker compose up -d --force-recreate jenkins-agent-docker
|
||||||
docker logs -f jenkins-agent-docker
|
docker logs -f jenkins-agent-docker
|
||||||
```
|
```
|
||||||
|
|
||||||
## Verification
|
Verification:
|
||||||
- In Jenkins UI: **Manage Nodes and Clouds**, the node `docker-agent` should be **Online**
|
- In Jenkins UI, the node `docker-agent` should become **Online**.
|
||||||
- Any pipeline using `agent { label 'docker' }` should execute on this agent
|
- Any pipeline using `agent { label 'docker-agent' }` should execute on this agent.
|
||||||
|
|
||||||
## Security note
|
## Security note
|
||||||
The Docker agent container mounts `/var/run/docker.sock`, which effectively grants high-level control over the Docker host. Use this setup only in trusted environments and limit access to Jenkins accordingly.
|
The Docker agent mounts `/var/run/docker.sock`, which effectively grants high-level control over the Docker host.
|
||||||
|
|
||||||
|
Use this setup only in trusted environments and limit access to Jenkins accordingly.
|
||||||
|
|||||||
Reference in New Issue
Block a user