Skip to content

Commit e8f6405

Browse files
committed
Add new jenkins_docker_expose_port var
1 parent af663de commit e8f6405

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ jenkins_plugins:
8383
jenkins_custom_plugins: []
8484

8585
# Configs specific to the "docker" method of running jenkins
86+
# The name of the jenkins container
8687
jenkins_docker_container_name: jenkins
88+
# Default, if true, the port will be exposed on the host (using "port")
89+
# If set to false, the port will only be exposed to other containers (using "expose")
90+
jenkins_docker_expose_port: true
8791
```
8892
8993
Example Playbook
@@ -123,6 +127,10 @@ This gives you more flexibility and better separation of concerns. See
123127
the documentation in those projects for more details on how to deploy
124128
the proxies and configure HTTPS.
125129
130+
If using a reverse proxy in front of the jenkins instance you probably
131+
want to set the `jenkins_docker_expose_port` var to false so that the
132+
port is not exposed on the host, only to the reverse proxy.
133+
126134
Jenkins Configs
127135
---------------
128136

defaults/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,9 @@ jenkins_plugins:
4545
jenkins_custom_plugins: []
4646

4747
# Configs specific to the "docker" method of running jenkins
48+
# The name of the jenkins container
4849
jenkins_docker_container_name: jenkins
50+
51+
# Default, if true, the port will be exposed on the host (using "port")
52+
# If set to false, the port will only be exposed to other containers (using "expose")
53+
jenkins_docker_expose_port: true

tasks/docker/install.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
group: "{{ jenkins_config_group }}"
99
state: directory
1010

11-
- name: Container is running
11+
- name: Container is running (with ingress port)
1212
docker_container:
1313
name: "{{ jenkins_docker_container_name }}"
1414
image: "jenkins:{{ jenkins_version }}"
@@ -19,6 +19,19 @@
1919
env:
2020
JAVA_OPTS: "{{ jenkins_java_opts }}"
2121
register: container_result
22+
when: jenkins_docker_expose_port
23+
24+
- name: Container is running (without ingress port)
25+
docker_container:
26+
name: "{{ jenkins_docker_container_name }}"
27+
image: "jenkins:{{ jenkins_version }}"
28+
expose: "8080"
29+
volumes:
30+
- "{{ jenkins_home }}:/var/jenkins_home"
31+
env:
32+
JAVA_OPTS: "{{ jenkins_java_opts }}"
33+
register: container_result
34+
when: not jenkins_docker_expose_port
2235

2336
- pause:
2437
seconds: 45

0 commit comments

Comments
 (0)