Implemented working version of drone w/nginx https

This commit is contained in:
Bastian de Byl
2020-09-24 22:52:33 -04:00
parent e0abdbe506
commit 53f2868916
14 changed files with 93 additions and 50 deletions

1
.gitattributes vendored
View File

@@ -1 +1,2 @@
.pass.sh filter=git-crypt diff=git-crypt .pass.sh filter=git-crypt diff=git-crypt
ansible/vars/vault.yml filter=git-crypt diff=git-crypt

View File

@@ -10,9 +10,12 @@ VENV_BIN=.venv/bin
PIP=${VENV_BIN}/pip PIP=${VENV_BIN}/pip
ANSIBLE=${VENV_BIN}/ansible-playbook ANSIBLE=${VENV_BIN}/ansible-playbook
ANSIBLE_VAULT=${VENV_BIN}/ansible-vault ANSIBLE_VAULT=${VENV_BIN}/ansible-vault
LINT_ANSIBLE=${VENV_BIN}/ansible-lint LINT_ANSIBLE=${VENV_BIN}/ansible-lint
LINT_YAML=${VENV_BIN}/yamllint LINT_YAML=${VENV_BIN}/yamllint
VAULT_PASS_FILE=.ansible-vaultpass VAULT_PASS_FILE=.ansible-vaultpass
VAULT_FILE=ansible/vars/vault.yml
# Variables # Variables
ANSIBLE_INVENTORY=ansible/inventories/home/hosts.yml ANSIBLE_INVENTORY=ansible/inventories/home/hosts.yml
@@ -29,16 +32,19 @@ ${ANSIBLE} ${ANSIBLE_VAULT} ${LINT_YAML} ${LINT_ANSIBLE}: ${VENV} requirements.t
${VAULT_PASS_FILE}: ${ANSIBLE} ${VAULT_PASS_FILE}: ${ANSIBLE}
. ${PASS_SRC}; pass $$PASS_LOC > $@ . ${PASS_SRC}; pass $$PASS_LOC > $@
${VAULT_FILE}: ${VAULT_PASS_FILE}
${ANSIBLE_VAULT} create --vault-password-file ${VAULT_PASS_FILE} $@
# Targets # Targets
deploy: ${ANSIBLE} ${VAULT_PASS_FILE} deploy: ${ANSIBLE} ${VAULT_FILE}
${ANSIBLE} --diff --private-key ${SSH_KEY} -t ${TAGS} -i ${ANSIBLE_INVENTORY} --vault-password-file ${VAULT_PASS_FILE} ansible/deploy.yml ${ANSIBLE} --diff --private-key ${SSH_KEY} -t ${TAGS} -i ${ANSIBLE_INVENTORY} --vault-password-file ${VAULT_PASS_FILE} ansible/deploy.yml
check: ${ANSIBLE} ${VAULT_PASS_FILE} check: ${ANSIBLE} ${VAULT_FILE}
${ANSIBLE} --check --diff --private-key ${SSH_KEY} -t ${TAGS} -i ${ANSIBLE_INVENTORY} --vault-password-file ${VAULT_PASS_FILE} ansible/deploy.yml ${ANSIBLE} --check --diff --private-key ${SSH_KEY} -t ${TAGS} -i ${ANSIBLE_INVENTORY} --vault-password-file ${VAULT_PASS_FILE} ansible/deploy.yml
encrypt-string: ${ANSIBLE_VAULT} ${VAULT_PASS_FILE} vault: ${ANSIBLE_VAULT} ${VAULT_FILE}
${ANSIBLE_VAULT} encrypt_string --vault-password-file ${VAULT_PASS_FILE} ${ANSIBLE_VAULT} edit --vault-password-file ${VAULT_PASS_FILE} ${VAULT_FILE}
lint: ${LINT_YAML} ${LINT_ANSIBLE} lint: ${LINT_YAML} ${LINT_ANSIBLE}
@${LINT_YAML} ansible/ ${LINT_YAML} ansible/
@${LINT_ANSIBLE} ansible/ ${LINT_ANSIBLE} ansible/

View File

@@ -1,5 +1,8 @@
--- ---
- hosts: all - hosts: all
vars_files:
- vars/vault.yml
roles: roles:
- role: common - role: common
- role: http - role: http
- role: drone

View File

@@ -1,7 +1,8 @@
--- ---
deps: [ deps: [
docker, docker,
fail2ban fail2ban,
python-docker
] ]
fail2ban_jails: [ fail2ban_jails: [

View File

@@ -0,0 +1,3 @@
---
drone_server_proto: "https"
drone_runner_capacity: "1"

View File

@@ -1,17 +0,0 @@
---
- name: Create Drone CI container
community.general.docker_container:
name: drone
image: drone/drone
restart: true
restart_policy: on-failure
restart_retries: 3
env:
DRONE_GITHUB_CLIENT_ID: {{ drone_gh_client_id }}
DRONE_GITHUB_CLIENT_SECRET: {{ drone_gh_client_sec }}
DRONE_RPC_SECRET: {{ drone_rpc_secret }}
DRONE_SERVER_HOST: {{ ci_server_name }}
DRONE_SERVER_PROTO: {{ drone_server_proto }}
DRONE_GIT_ALWAYS_AUTH: 'true'
DRONE_USER_FILTER: {{ drone_user_filter }}

View File

@@ -0,0 +1,43 @@
---
- name: create drone-ci server container
diff: false
docker_container:
name: drone
image: drone/drone:latest
recreate: true
restart: true
restart_policy: on-failure
restart_retries: 3
env:
DRONE_GITHUB_CLIENT_ID: "{{ drone_gh_client_id }}"
DRONE_GITHUB_CLIENT_SECRET: "{{ drone_gh_client_sec }}"
DRONE_GIT_ALWAYS_AUTH: 'true'
DRONE_RPC_SECRET: "{{ drone_rpc_secret }}"
DRONE_SERVER_HOST: "{{ ci_server_name }}"
DRONE_SERVER_PROTO: "{{ drone_server_proto }}"
DRONE_USER_FILTER: "{{ drone_user_filter }}"
volumes:
- /var/lib/drone:/data
ports:
- "8080:80"
tags: drone
- name: create drone-ci worker container
diff: false
docker_container:
name: drone-runner
image: drone/drone-runner-docker:latest
recreate: true
restart: true
restart_policy: on-failure
restart_retries: 3
env:
DRONE_RPC_SECRET: "{{ drone_rpc_secret }}"
DRONE_RPC_HOST: "{{ ci_server_name }}"
DRONE_RPC_PROTO: "{{ drone_server_proto }}"
DRONE_RUNNER_CAPACITY: "{{ drone_runner_capacity }}"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
ports:
- "3000:3000"
tags: drone

View File

@@ -1,2 +1,2 @@
--- ---
- import_tasks: docker.yml - import_tasks: drone.yml

View File

@@ -4,6 +4,5 @@ ci_server_name: ci.bdebyl.net
deps: [ deps: [
certbot, certbot,
certbot-nginx,
nginx nginx
] ]

View File

@@ -32,5 +32,5 @@ http {
limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s; limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s;
include etc/nginx/sites-enabled/*.conf; include /etc/nginx/sites-enabled/*.conf;
} }

View File

@@ -1,10 +1,9 @@
--- ---
- cron: renew certbot ssl certificate weekly - name: renew certbot ssl certificates weekly
become: true
cron: cron:
name: ci_bdebyl_net_renewal name: certbot_renew
special_time: weekly special_time: weekly
job: | job: |
certbot --renew certonly --webroot --webroot-path=/srv/http \ certbot renew --pre-hook "systemctl stop nginx" --post-hook "systemctl start nginx"
-m {{ ci_server_email }} --agree-tos \ tags: cron
-d {{ ci_server_name }}
tags: never

View File

@@ -2,3 +2,4 @@
- import_tasks: deps.yml - import_tasks: deps.yml
- import_tasks: http.yml - import_tasks: http.yml
- import_tasks: ssl.yml - import_tasks: ssl.yml
- import_tasks: cron.yml

View File

@@ -1,35 +1,39 @@
upstream drone {
server 127.0.0.1:8080;
}
server { server {
listen 443 ssl http2; listen 443 ssl http2;
listen [::]:443 ssl http2; listen [::]:443 ssl http2;
server_name {{ ci_server_name }}; server_name {{ ci_server_name }};
add_header Strict-Transport-Security max-age=6307200; add_header Strict-Transport-Security max-age=6307200;
ssl_certificate /etc/letsencrypt/live/{{ ci_server_name }}/fullchain.pem; ssl_certificate /etc/letsencrypt/live/{{ ci_server_name }}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/{{ ci_server_name }}/privkey.pem; ssl_certificate_key /etc/letsencrypt/live/{{ ci_server_name }}/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/{{ ci_server_name }}/fullchain.pem; ssl_trusted_certificate /etc/letsencrypt/live/{{ ci_server_name }}/fullchain.pem;
ssl_dhparam /etc/ssl/certs/dhparam.pem; ssl_dhparam /etc/ssl/certs/dhparam.pem;
ssl_session_cache shared:SSL:10m; ssl_session_cache shared:SSL:10m;
ssl_session_timeout 1d; ssl_session_timeout 1d;
ssl_session_tickets off; ssl_session_tickets off;
ssl_stapling on; ssl_stapling on;
ssl_stapling_verify on; ssl_stapling_verify on;
ssl_protocols TLSv1.2 TLSv1.3; ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off; ssl_prefer_server_ciphers off;
location / { location / {
proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_post; proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:4242; proxy_pass http://drone;
proxy_redirect off; proxy_redirect off;
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_buffering off; proxy_buffering off;
chunked_transfer_encoding off; chunked_transfer_encoding off;
} }
} }

BIN
ansible/vars/vault.yml Normal file

Binary file not shown.