diff --git a/Jenkinsfile b/Jenkinsfile index 70c19d7..c8d20a6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,9 +1,15 @@ pipeline { agent any + options { + buildDiscarder logRotator ( + numToKeepStr: '5', + daysToKeepStr: '7', + artifactNumToKeepStr: '10', + artifactDaysToKeepStr: '7' + ) + } parameters { string(name: "target_host", defaultValue: "", trim: true, description: "Target host") - string(name: "username", defaultValue: "", trim: true, description: "Ansible user") - password(name: "password", defaultValue: "", description: "Ansible password") booleanParam(name: "rproxy_install", defaultValue: true, description: "Install Rproxy") base64File(name: "rootca", description: "RootCA (only for 'Install Rproxy')") base64File(name: "rootca_key", description: "RootCA key (only for 'Install Rproxy')") @@ -11,7 +17,6 @@ pipeline { string(name: "rproxy_service_name", defaultValue: "", trim: true, description: "Service name (for 'Add config' job only)") string(name: "rproxy_service_port", defaultValue: "", trim: true, description: "Service port (for 'Add config' job only)") string(name: "rproxy_service_address", defaultValue: "", trim: true, description: "Service address (for 'Add config' job only)") - } stages { stage('Save certs') { @@ -37,8 +42,13 @@ pipeline { } steps { script { - wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[password: params.password]]]) { - sh 'ansible-playbook rproxy.yml -i ${target_host}, -t install -u ${username} -e "ansible_password=${password} rproxy_service_name=${rproxy_service_name} rproxy_service_port=${rproxy_service_port} rproxy_service_address=${rproxy_service_address}"' + withCredentials([ + sshUserPrivateKey(credentialsId: 'JENKINS_DEPLOYER_KEY', keyFileVariable: 'SSH_KEY'), + usernamePassword(credentialsId:'JENKINS_DEPLOYER_PASS', usernameVariable: 'username', passwordVariable: 'password') + ]) { + wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[password: env.password]]]) { + sh 'ansible-playbook rproxy.yml -i ${target_host}, -t install --private-key ${SSH_KEY} -u ${username} -e "ansible_password=${password} rproxy_service_name=${rproxy_service_name} rproxy_service_port=${rproxy_service_port} rproxy_service_address=${rproxy_service_address}"' + } } } } @@ -51,8 +61,13 @@ pipeline { } steps { script { - wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[password: params.password]]]) { - sh 'ansible-playbook rproxy.yml -i ${target_host}, -t add_config -u ${username} -e "ansible_password=${password} rproxy_service_name=${rproxy_service_name} rproxy_service_port=${rproxy_service_port} rproxy_service_address=${rproxy_service_address}"' + withCredentials([ + sshUserPrivateKey(credentialsId: 'JENKINS_DEPLOYER_KEY', keyFileVariable: 'SSH_KEY'), + usernamePassword(credentialsId:'JENKINS_DEPLOYER_PASS', usernameVariable: 'username', passwordVariable: 'password') + ]) { + wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[password: env.password]]]) { + sh 'ansible-playbook rproxy.yml -i ${target_host}, -t add_config --private-key ${SSH_KEY} -u ${username} -e "ansible_password=${password} rproxy_service_name=${rproxy_service_name} rproxy_service_port=${rproxy_service_port} rproxy_service_address=${rproxy_service_address}"' + } } } } diff --git a/roles/rproxy/files/repo.conf b/roles/rproxy/files/repo.conf new file mode 100644 index 0000000..9bca367 --- /dev/null +++ b/roles/rproxy/files/repo.conf @@ -0,0 +1,14 @@ +server { + listen 9000; + server_name _; + root /repo; + + location / { + charset utf-8; + autoindex on; + autoindex_exact_size off; + autoindex_localtime on; + # auth_basic "Needs to auth"; + # auth_basic_user_file /etc/nginx/.htpasswd; + } +} diff --git a/roles/rproxy/tasks/main.yml b/roles/rproxy/tasks/main.yml index 6fc787c..8e705dc 100644 --- a/roles/rproxy/tasks/main.yml +++ b/roles/rproxy/tasks/main.yml @@ -51,6 +51,12 @@ path: "{{ rproxy_dir }}/sites" state: directory + - name: Create repo dir + ansible.builtin.file: + path: "{{ rproxy_dir }}/repo" + state: directory + mode: 0777 + - name: Create certs dir ansible.builtin.file: path: "{{ rproxy_dir }}/certs" @@ -66,6 +72,11 @@ src: files/nginx.conf dest: "{{ rproxy_dir }}/nginx.conf" + - name: Copy repo.conf + ansible.builtin.copy: + src: files/repo.conf + dest: "{{ rproxy_dir }}/sites/repo.conf" + - name: Copy RootCA certificate ansible.builtin.copy: src: files/RootCA.crt diff --git a/roles/rproxy/templates/docker-compose.yml.j2 b/roles/rproxy/templates/docker-compose.yml.j2 index c424260..c589e87 100644 --- a/roles/rproxy/templates/docker-compose.yml.j2 +++ b/roles/rproxy/templates/docker-compose.yml.j2 @@ -9,6 +9,8 @@ services: - {{ rproxy_dir }}/nginx.conf:/etc/nginx/nginx.conf - {{ rproxy_dir }}/sites:/etc/nginx/sites - {{ rproxy_dir }}/certs:/etc/nginx/certs + - {{ rproxy_dir }}/repo:/repo ports: - 443:443 - - 80:80 \ No newline at end of file + - 80:80 + - 9000:9000 \ No newline at end of file