first commit

This commit is contained in:
Jens Timmerman 2020-10-25 02:31:36 +02:00
commit 7dc1aeb6f5
11 changed files with 335 additions and 0 deletions

50
README.md Normal file
View File

@ -0,0 +1,50 @@
Role Name
=========
This role installs drone without docker
Requirements
------------
This role requires a database server to to be present where drone can connect to
Role Variables
--------------
- drone_postgress_user: default "{{ inventory_hostname}}"
- drone_postgress_db: default "{{ inventory_hostname}}"
- drone_server_host: url where drone will be reachable
- drone_rpc_secret: something secret
- drone_integration: 'gitea'
- drone_gitea_server: url to gitea server
- drone_gitea_client_id: client id for gitea oauth application
- drone_gitea_client_secret: client secret for gitea oauth application
- drone_posgress_data_dir: "/run/postgresql/"
Dependencies
------------
None
Example Playbook
----------------
```yaml
- name: "Install im pantry app"
hosts: im
roles:
- ansible-role-im
vars:
- drone_gitea_server: "gitea.example.com"
# more vars here
```
License
-------
GPL-v3
Author Information
------------------
Jens (gitea.caret.be)

15
defaults/main.yml Normal file
View File

@ -0,0 +1,15 @@
---
# defaults file for im
drone_home: /home/drone
drone_rpc_secret: "{{ lookup('password', im_home + '/.dronesecretfile chars=ascii_letters length=56') }}"
drone_postgress_user: "{{ inventory_hostname}}"
drone_postgress_db: "{{ inventory_hostname}}"
drone_integration: 'gitea'
drone_posgress_data_dir: "/run/postgresql/"
drone_postgress_user: "drone"
drone_postgress_db: "drone"
drone_user: "drone"
drone_server_proto: "https"
drone_server_host: "localhost"
drone_logs_debug: "true"

13
handlers/main.yml Normal file
View File

@ -0,0 +1,13 @@
---
# handlers file for im
- name: "Restart drone"
service:
name: "drone"
state: "restarted"
when: ansible_service_mgr == "systemd"
- name: "Reload systemd"
systemd:
daemon_reload: true
when: ansible_service_mgr == "systemd"

30
meta/main.yml Normal file
View File

@ -0,0 +1,30 @@
galaxy_info:
role_name: ansible_role_drone
author: Jens Timmerman
description: This role installs drone ci p (https://github.com/drone/drone)
issue_tracker_url: https://gitea.caret.be/jens/ansible-role-drone/issues
# - GPL-3.0-only
license: GPL-3.0-only
min_ansible_version: 2.9
#
# 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:
- 32
- name: CentOs
versions:
- 8
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

59
tasks/main.yml Normal file
View File

@ -0,0 +1,59 @@
---
# tasks file for drone
- name: 'install dependencies'
package:
name:
- 'git'
- 'golang'
state: 'present'
- name: 'Create drone user'
user:
name: "{{ drone_user }}"
comment: "drone user"
home: "{{ drone_home }}"
shell: "/bin/false"
- name: 'download latest drone'
git:
dest: "{{drone_home}}/drone"
repo: https://github.com/drone/drone.git
become: true
become_user : "{{drone_user}}"
- name: "Setup systemd service"
template:
src: drone.service.j2
dest: /lib/systemd/system/drone.service
owner: root
group: root
mode: 0644
notify:
- "Reload systemd"
- "Restart drone"
when: ansible_service_mgr == "systemd"
- name: "build drone"
command: 'go build'
become: true
become_user : "{{drone_user}}"
notify: "Restart drone"
args:
chdir: "{{drone_home}}/drone/cmd/drone-server"
- name: "Configure drone"
template:
src: "rundrone.sh.j2"
dest: "{{drone_home}}/rundrone.sh"
owner: "{{ drone_user }}"
mode: 0700
notify: "Restart drone"
- name: "Service drone"
service:
name: "drone"
state: "started"
enabled: true
when: ansible_service_mgr == "systemd"

View File

@ -0,0 +1,13 @@
[Unit]
Description=drone ci
After=network.target
[Service]
User={{drone_user}}
WorkingDirectory={{ drone_home }}
ExecStart={{drone_home}}/rundrone.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target

14
templates/rundrone.sh.j2 Normal file
View File

@ -0,0 +1,14 @@
#!/bin/bash
# scrip to run drone ci
export DRONE_GITEA_SERVER="{{drone_gitea_server}}"
export DRONE_GITEA_CLIENT_ID="{{drone_gitea_client_id}}"
export DRONE_GITEA_CLIENT_SECRET="{{drone_gitea_client_secret}}"
export DRONE_RPC_SECRET="{{drone_rpc_secret}}"
export DRONE_SERVER_HOST="{{drone_server_host}}"
export DRONE_SERVER_PROTO="{{drone_server_proto}}"
export DRONE_LOGS_DEBUG="{{drone_logs_debug}}"
export DRONE_POSTGRESS_DB="{{ drone_postgress_db }}"
export DRONE_POSTGRESS_USER="{{ drone_postgress_user }}"
./drone/cmd/drone-server/drone-server

131
templates/settings.py.j2 Normal file
View File

@ -0,0 +1,131 @@
"""
Django settings for im project.
Generated by 'django-admin startproject' using Django 2.1.1.
For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '{{im_secret_key}}'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = [
'{{im_domain}}'
]
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'inventory.apps.InventoryConfig',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'im.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'im.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': '{{im_db_name}}',
'USER': '{{im_db_user}}',
'PASSWORD': '{{im_db_password}}',
'HOST': '{{im_db_server}}',
'PORT': '{{im_db_port}}',
}
}
# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/
# http://whitenoise.evans.io/en/stable/django.html
STATIC_URL = '/static/'
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

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:
- ansible-role-drone

3
vars/main.yml Normal file
View File

@ -0,0 +1,3 @@
---
# vars file for ansible-role-drone