Przejdź do głównej zawartości

Jenkins

Instalacja Jenkinsa w Docker

Docker

Tworzenie nowego interfejsu sieciowego

docker network create jenkins

Instalacja obrazu ( bez VPN)

docker run \

--name jenkins-docker \

--rm \

--detach \

--privileged \

--network jenkins \

--network-alias docker \

--env DOCKER_TLS_CERTDIR=/certs \

--volume jenkins-docker-certs:/certs/client \

--volume jenkins-data:/var/jenkins_home \

--publish 2376:2376 \

docker:dind \

--storage-driver overlay2

Uruchomienie Jenkins + Nginx z HTTPS w Dokerze

Struktura katalogów

projekt/
├── docker-compose.yml
├── nginx/
│ ├── nginx.conf
│ └── certs/
│ ├── cert.pem
│ └── key.pem

docker-compose.yml

version: "3.8"

services:
jenkins:
image: jenkins/jenkins:lts
container_name: jenkins
ports:
- "8080:8080"
volumes:
- jenkins_home:/var/jenkins_home
networks:
- jenkins_net

nginx:
image: nginx:latest
container_name: nginx_proxy
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
- ./nginx/certs:/etc/nginx/certs:ro
depends_on:
- jenkins
networks:
- jenkins_net

volumes:
jenkins_home:

networks:
jenkins_net:
driver: bridge

nginx.conf

events {}

http {
server {
listen 80;
server_name localhost;

return 301 https://$host$request_uri;
}

server {
listen 443 ssl;
server_name localhost;

ssl_certificate /etc/nginx/certs/cert.pem;
ssl_certificate_key /etc/nginx/certs/key.pem;

location / {
proxy_pass http://jenkins:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}

Tworzenie certyfikatu testowego (samopodpisanego)

mkdir -p nginx/certs
openssl req -x509 -nodes -days 365 \
-newkey rsa:2048 \
-keyout nginx/certs/key.pem \
-out nginx/certs/cert.pem \
-subj "/CN=localhost"

Uruchomienie kontenera

W katalogu z docker-compose.yml:

docker compose up -d

Po uruchomieniu wejdź w przeglądarce: https://localhost

Odczyt hasła admina

docker exec -it nazwakontenera bash
lub
docker exec -it nazwakontenera sh

Instalacja na linux

Aktualizacja systemu

sudo apt update && sudo apt upgrade -y
sudo apt install fontconfig openjdk-17-jre -y

Dodanie repozytorium Jenkins

Pobierz klucz GPG:

wget -q -O - https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null

Dodaj repozytorium Jenkins:

echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian binary/" | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null

Zaktualizuj listę pakietów:

sudo apt update

Instalacja Jenkins

sudo apt install jenkins -y

Uruchomienie i automatyczne uruchamianie Jenkins

sudo systemctl start jenkins
sudo systemctl enable jenkins

Sprawdź status usługi:

sudo systemctl status jenkins

Konfiguracja Jenkins:

Dostęp do panelu Jenkins

http://IP_SERWERA:8080

Uzyskanie hasła administratora

sudo cat /var/lib/jenkins/secrets/initialAdminPassword