Compare commits

...

4 Commits

Author SHA1 Message Date
44b2c8813b .gitignore 2021-04-05 21:59:39 +02:00
87d8ab93a9 fill README.md with useful information 2021-04-05 21:59:39 +02:00
002a27ec1a add defaults 2021-04-05 21:59:39 +02:00
f3f226c811 initial 2021-04-05 21:59:39 +02:00
12 changed files with 385 additions and 2 deletions

94
.gitignore vendored Normal file
View File

@ -0,0 +1,94 @@
# Created by https://www.toptal.com/developers/gitignore/api/intellij+all
# Edit at https://www.toptal.com/developers/gitignore?templates=intellij+all
### Intellij+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
### Intellij+all Patch ###
# Ignores the whole .idea folder and all .iml files
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
.idea/
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
*.iml
modules.xml
.idea/misc.xml
*.ipr
# Sonarlint plugin
.idea/sonarlint
# End of https://www.toptal.com/developers/gitignore/api/intellij+all

View File

@ -1,3 +1,34 @@
# drone
Drone
=========
Ansible role for Drone.io
Docker based installation of Drone.io and Docker Drone Runner
Requirements
------------
Docker needs to be available on target machine.
Role Variables
--------------
| Variable | Description | Default |
| ------------------------------------- | --------------------------------------------------------------- | ----------------------- |
| `letsencrypt.staging` | Create staging certificate. | true |
| `letsencrypt.email` | Email address to declare when creating certificate. | "" |
| `drone_env.DRONE_GITEA_SERVER` | Gitea server to connect to. | https://git.example.com |
| `drone_env.DRONE_GITEA_CLIENT_ID` | Client ID for gitea server | no_valid_id |
| `drone_env.DRONE_GITEA_CLIENT_SECRET` | Client secret used to conntect to gitea server | very_secret |
| `drone_env.DRONE_RPC_SECRET` | Secret for drone runners to use when connecting to drone server | even_more_secret |
Example Playbook
----------------
- hosts: drone
roles:
- { role: drone, tags: [drone] }
License
-------
MIT

10
defaults/main.yml Normal file
View File

@ -0,0 +1,10 @@
---
letsencrypt:
staging: 1
email: "webadmin@example.com"
drone_env:
DRONE_GITEA_SERVER: https://git.example.com
DRONE_GITEA_CLIENT_ID: no_valid_id
DRONE_GITEA_CLIENT_SECRET: very_secret
DRONE_RPC_SECRET: even_more_secret

2
handlers/main.yml Normal file
View File

@ -0,0 +1,2 @@
---
# handlers file for drone

52
meta/main.yml Normal file
View File

@ -0,0 +1,52 @@
galaxy_info:
author: your name
description: your role description
company: your company (optional)
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)
min_ansible_version: 2.1
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

31
tasks/main.yml Normal file
View File

@ -0,0 +1,31 @@
---
# tasks file for drone
- name: Copy docker-compose.yml
ansible.builtin.template:
src: docker-compose.yml.j2
dest: docker-compose.yml
- name: Create directory data
file:
path: data/nginx
state: directory
- name: Create nginx.conf
ansible.builtin.template:
src: nginx.conf.j2
dest: data/nginx/nginx.conf
- name: Create init_letsencrypt.sh
ansible.builtin.template:
src: init_letsencrypt.sh
dest: init_letsencrypt.sh
mode: 0700
- name: Init letsencrypt and start
command: ./init_letsencrypt.sh
environment: "{{ drone_env }}"
- name: docker-compose up
command: docker-compose up -d
environment: "{{ drone_env }}"

View File

@ -0,0 +1,43 @@
version: '3'
services:
nginx:
image: nginx:1.15-alpine
restart: unless-stopped
volumes:
- ./data/nginx:/etc/nginx/conf.d
- ./data/certbot/conf:/etc/letsencrypt
- ./data/certbot/www:/var/www/certbot
ports:
- "80:80"
- "443:443"
command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
certbot:
image: certbot/certbot
restart: unless-stopped
volumes:
- ./data/certbot/conf:/etc/letsencrypt
- ./data/certbot/www:/var/www/certbot
entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
drone:
image: drone/drone:1
environment:
- DRONE_GITEA_SERVER=${DRONE_GITEA_SERVER}
- DRONE_GITEA_CLIENT_ID=${DRONE_GITEA_CLIENT_ID}
- DRONE_GITEA_CLIENT_SECRET=${DRONE_GITEA_CLIENT_SECRET}
- DRONE_RPC_SECRET=${DRONE_RPC_SECRET}
- DRONE_SERVER_HOST={{ inventory_hostname }}
- DRONE_SERVER_PROTO=https
restart: always
drone-runner:
image: drone/drone-runner-docker:1
environment:
- DRONE_RPC_PROTO=https
- DRONE_RPC_HOST={{ inventory_hostname }}
- DRONE_RPC_SECRET=${DRONE_RPC_SECRET}
- DRONE_RPC_SKIP_VERIFY=true
- DRONE_RUNNER_CAPACITY=2
- DRONE_RUNNER_NAME=drone-runner
volumes:
- /var/run/docker.sock:/var/run/docker.sock
restart: always

View File

@ -0,0 +1,80 @@
#!/bin/bash
if ! [ -x "$(command -v docker-compose)" ]; then
echo 'Error: docker-compose is not installed.' >&2
exit 1
fi
domains=({{ inventory_hostname }})
rsa_key_size=4096
data_path="./data/certbot"
email="{{ letsencrypt.email }}"
staging="{{ letsencrypt.staging }}" # Set to 1 if you're testing your setup to avoid hitting request limits
if [ -d "$data_path" ]; then
echo "Existing data found for $domains. Keeping existing certificate" decision
exit
fi
if [ ! -e "$data_path/conf/options-ssl-nginx.conf" ] || [ ! -e "$data_path/conf/ssl-dhparams.pem" ]; then
echo "### Downloading recommended TLS parameters ..."
mkdir -p "$data_path/conf"
curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot-nginx/certbot_nginx/_internal/tls_configs/options-ssl-nginx.conf > "$data_path/conf/options-ssl-nginx.conf"
curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot/certbot/ssl-dhparams.pem > "$data_path/conf/ssl-dhparams.pem"
echo
fi
echo "### Creating dummy certificate for $domains ..."
path="/etc/letsencrypt/live/$domains"
mkdir -p "$data_path/conf/live/$domains"
docker-compose run --rm --entrypoint "\
openssl req -x509 -nodes -newkey rsa:$rsa_key_size -days 1\
-keyout '$path/privkey.pem' \
-out '$path/fullchain.pem' \
-subj '/CN=localhost'" certbot
echo
echo "### Starting nginx ..."
docker-compose up --force-recreate -d nginx
echo
echo "### Deleting dummy certificate for $domains ..."
docker-compose run --rm --entrypoint "\
rm -Rf /etc/letsencrypt/live/$domains && \
rm -Rf /etc/letsencrypt/archive/$domains && \
rm -Rf /etc/letsencrypt/renewal/$domains.conf" certbot
echo
echo "### Requesting Let's Encrypt certificate for $domains ..."
#Join $domains to -d args
domain_args=""
for domain in "${domains[@]}"; do
domain_args="$domain_args -d $domain"
done
# Select appropriate email arg
case "$email" in
"") email_arg="--register-unsafely-without-email" ;;
*) email_arg="--email $email" ;;
esac
# Enable staging mode if needed
if [ $staging != "0" ]; then staging_arg="--staging"; fi
mkdir -p $data_path/certbot/www
docker-compose run --rm --entrypoint "\
certbot certonly --webroot -w /var/www/certbot \
$staging_arg \
$email_arg \
$domain_args \
--rsa-key-size $rsa_key_size \
--agree-tos \
--force-renewal" certbot
echo
echo "### Reloading nginx ..."
docker-compose exec nginx nginx -s reload

31
templates/nginx.conf.j2 Normal file
View File

@ -0,0 +1,31 @@
server {
listen 80;
server_name example.org;
server_tokens off;
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name {{ inventory_hostname }};
server_tokens off;
ssl_certificate /etc/letsencrypt/live/{{ inventory_hostname }}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/{{ inventory_hostname }}/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
location / {
proxy_pass http://drone:80;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}

2
tests/inventory Normal file
View File

@ -0,0 +1,2 @@
localhost

5
tests/test.yml Normal file
View File

@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- drone

2
vars/main.yml Normal file
View File

@ -0,0 +1,2 @@
---
# vars file for drone