Skip to content

Commit

Permalink
Merge pull request #353 from cradle8810/341_jenkins_mirror
Browse files Browse the repository at this point in the history
Jenins debファイルダウンロード用コンテナと、リバプロをdocker-composeで立てる
  • Loading branch information
cradle8810 authored Oct 30, 2024
2 parents a989a52 + 4dd5da5 commit 9cab0ad
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exclude_paths:
- templates/
- .ansible-lint
21 changes: 18 additions & 3 deletions dockerservice.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
become: true

vars_files:
- inventories/host_vars/docker_service.yml
- inventories/host_vars/dockerservice.yml
- inventories/host_vars/networks.yml

handlers:
Expand All @@ -21,6 +21,10 @@
ansible.builtin.import_tasks:
file: tasks/all/main.yml

- name: Mount docker
ansible.builtin.import_tasks:
file: tasks/dockerservice/mount_docker.yml

- name: Install Docker(ce)
ansible.builtin.import_role:
name: geerlingguy.docker
Expand All @@ -34,9 +38,20 @@
docker_users:
- hayato

- name: Mount skylark
- name: Put Docker config
ansible.builtin.template:
src: templates/dockerservice/etc/docker/daemon.json.j2
dest: /etc/docker/daemon.json
owner: root
group: root
mode: '0644'
notify: "Restart docker"

- name: "Predefined docker-compose up"
ansible.builtin.import_tasks:
file: tasks/dockerservice/mount_docker.yml
file: tasks/dockerservice/docker_compose_exec.yml
tags:
- docker

- name: Install/Config Zramswap
ansible.builtin.import_tasks:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ services_start:
dockerdir:
UUID: "6db90b73-6dbd-4c00-9b13-724f0cb4e636"

docker_network:
base: "172.18.0.0/12"
size: "24"

firewall:
policy: deny
allow_rules:
Expand Down
2 changes: 1 addition & 1 deletion inventories/host_vars/jenkins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jenkins:
hostname: jenkins.hayaworld.home
http_port: 8080
java_options: "-Djenkins.install.runSetupWizard=false"
pkg_url: "https://ftp.yz.yamagata-u.ac.jp/pub/misc/jenkins/debian"
pkg_url: "http://jenkins-deb.hayaworld.home/"
plugins:
- build-timeout
- discord-notifier
Expand Down
4 changes: 4 additions & 0 deletions inventories/host_vars/rui/CNAME.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
cname:
- name: jenkins-deb.hayaworld.home
real: dockerservice.hayaworld.home
1 change: 1 addition & 0 deletions requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ roles:

collections:
- name: ansible.posix
- name: community.docker
- name: community.general
1 change: 1 addition & 0 deletions rui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

vars_files:
- inventories/host_vars/rui/NXDOMAIN.yml
- inventories/host_vars/rui/CNAME.yml
- inventories/host_vars/rui.yml
- inventories/host_vars/networks.yml

Expand Down
27 changes: 27 additions & 0 deletions tasks/dockerservice/docker_compose_exec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
- name: "Install docker python module"
ansible.builtin.pip:
name: "docker"
break_system_packages: true
extra_args: "--upgrade"

- name: "Copy docker-compose.yml to homedir"
ansible.builtin.copy:
src: templates/dockerservice/home/hayato/compose
dest: /home/hayato/
owner: hayato
group: hayato
directory_mode: '0755'
mode: '0644'

- name: "Create a reverse-proxy network"
community.docker.docker_network:
name: reverse-proxy

- name: "Up Jenkins deb repository containers"
community.docker.docker_compose_v2:
project_src: "/home/hayato/compose/jenkins-deb/"

- name: "Up Reverse Proxy containers"
community.docker.docker_compose_v2:
project_src: "/home/hayato/compose/reverseproxy/"
9 changes: 9 additions & 0 deletions tasks/rui/dnsmasq.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
mode: '0644'
notify: "Restart dnsmasq"

- name: Add CNAME config
ansible.builtin.template:
src: templates/rui/etc/dnsmasq.d/cname.conf.j2
dest: /etc/dnsmasq.d/cname.conf.j2
owner: root
group: root
mode: '0644'
notify: "Restart dnsmasq"

- name: Add hosts(5)
ansible.builtin.template:
src: templates/rui/etc/hosts.j2
Expand Down
8 changes: 8 additions & 0 deletions templates/dockerservice/etc/docker/daemon.json.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"default-address-pools" : [
{
"base" : "{{ docker_network.base }}",
"size" : {{ docker_network.size }}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
services:
jenkins-deb-container:
container_name: jenkins-deb-container
image: nginx:latest
restart: always
stdin_open: true
tty: true
networks:
- reverse-proxy
volumes:
- jenkins_deb:/usr/share/nginx/html

volumes:
jenkins_deb:

networks:
reverse-proxy:
external: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
services:
reverseProxy:
container_name: reverse-proxy
image: nginx:latest
restart: always
stdin_open: true
tty: true
ports:
- 80:80
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
networks:
- reverse-proxy

networks:
reverse-proxy:
external: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

user nginx;
worker_processes auto;

error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
keepalive_timeout 65;

server {
server_name jenkins-deb.hayaworld.home;
proxy_set_header Host $host;
listen 80;
location / {
proxy_pass http://jenkins-deb-container/;
}
}
}
3 changes: 3 additions & 0 deletions templates/rui/etc/dnsmasq.d/cname.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% for item in cname %}
cname={{ item.name }},{{ item.real }}
{% endfor %}

0 comments on commit 9cab0ad

Please sign in to comment.