initial commit

This commit is contained in:
Robert Kaussow 2020-09-30 21:56:00 +02:00
commit 6896943e38
No known key found for this signature in database
GPG Key ID: 65362AE74AF98B61
22 changed files with 819 additions and 0 deletions

154
.drone.jsonnet Normal file
View File

@ -0,0 +1,154 @@
local PipelineLinting = {
kind: 'pipeline',
name: 'linting',
platform: {
os: 'linux',
arch: 'amd64',
},
steps: [
{
name: 'ansible-later',
image: 'xoxys/ansible-later',
commands: [
'ansible-later',
],
},
],
trigger: {
ref: ['refs/heads/master', 'refs/tags/**', 'refs/pull/**'],
},
};
local PipelineDeployment(scenario='centos7') = {
kind: 'pipeline',
name: 'testing-' + scenario,
platform: {
os: 'linux',
arch: 'amd64',
},
concurrency: {
limit: 1,
},
workspace: {
base: '/drone/src',
path: '${DRONE_REPO_NAME}',
},
steps: [
{
name: 'ansible-molecule',
image: 'xoxys/molecule:3',
environment: {
DO_API_KEY: { from_secret: 'do_api_key' },
MOLECULE_CUSTOM_MODULES_REPO: 'https://gitea.rknet.org/ansible/custom_modules',
MOLECULE_CUSTOM_FILTERS_REPO: 'https://gitea.rknet.org/ansible/custom_filters',
},
commands: [
'molecule test -s' + scenario,
],
},
],
depends_on: [
'linting',
],
trigger: {
ref: ['refs/heads/master', 'refs/tags/**'],
},
};
local PipelineDocumentation = {
kind: 'pipeline',
name: 'documentation',
platform: {
os: 'linux',
arch: 'amd64',
},
steps: [
{
name: 'generate',
image: 'xoxys/ansible-doctor',
environment: {
ANSIBLE_DOCTOR_LOG_LEVEL: 'INFO',
ANSIBLE_DOCTOR_FORCE_OVERWRITE: true,
ANSIBLE_DOCTOR_EXCLUDE_FILES: 'molecule/',
ANSIBLE_DOCTOR_TEMPLATE: 'hugo-book',
ANSIBLE_DOCTOR_ROLE_NAME: '${DRONE_REPO_NAME#*.}',
ANSIBLE_DOCTOR_OUTPUT_DIR: '_docs/',
},
},
{
name: 'publish',
image: 'plugins/gh-pages',
settings: {
remote_url: 'https://gitea.rknet.org/ansible/${DRONE_REPO_NAME}',
netrc_machine: 'gitea.rknet.org',
username: { from_secret: 'gitea_username' },
password: { from_secret: 'gitea_token' },
pages_directory: '_docs/',
target_branch: 'docs',
},
when: {
ref: ['refs/heads/master'],
},
},
{
name: 'trigger',
image: 'plugins/downstream',
settings: {
server: 'https://drone.rknet.org',
token: { from_secret: 'drone_token' },
fork: true,
repositories: [
'ansible/ansible-galaxy',
],
},
when: {
ref: ['refs/heads/master'],
},
},
],
trigger: {
ref: ['refs/heads/master', 'refs/tags/**', 'refs/pull/**'],
},
depends_on: [
'testing-centos7',
],
};
local PipelineNotification = {
kind: 'pipeline',
name: 'notification',
platform: {
os: 'linux',
arch: 'amd64',
},
clone: {
disable: true,
},
steps: [
{
name: 'matrix',
image: 'plugins/matrix',
settings: {
homeserver: { from_secret: 'matrix_homeserver' },
roomid: { from_secret: 'matrix_roomid' },
template: 'Status: **{{ build.status }}**<br/> Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}<br/> Message: {{ build.message }}',
username: { from_secret: 'matrix_username' },
password: { from_secret: 'matrix_password' },
},
},
],
depends_on: [
'documentation',
],
trigger: {
status: ['success', 'failure'],
ref: ['refs/heads/master', 'refs/tags/**'],
},
};
[
PipelineLinting,
PipelineDeployment(scenario='centos7'),
PipelineDocumentation,
PipelineNotification,
]

5
.flake8 Normal file
View File

@ -0,0 +1,5 @@
[flake8]
ignore = D101, D102, D103, D105, D107, E402, W503
max-line-length = 99
inline-quotes = double
exclude = .git,.tox,__pycache__,build,dist,tests,*.pyc,*.egg-info,.cache,.eggs,env*

11
.gitignore vendored Normal file
View File

@ -0,0 +1,11 @@
# ---> Ansible
*.retry
plugins
library
# ---> Python
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

18
.later.yml Normal file
View File

@ -0,0 +1,18 @@
---
ansible:
custom_modules:
- iptables_raw
- openssl_pkcs12
- proxmox_kvm2
- ucr
- yum_versionlock
rules:
exclude_files:
- molecule/
- "LICENSE*"
- "**/*.md"
- "**/*.ini"
exclude_filter:
- LINT0009

1
.prettierignore Normal file
View File

@ -0,0 +1 @@
.drone*

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 Robert Kaussow <mail@thegeeklab.de>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

16
README.md Normal file
View File

@ -0,0 +1,16 @@
# xoxys.droneci_autoscaler
[![Build Status](https://img.shields.io/drone/build/ansible/xoxys.droneci_autoscaler?logo=drone&server=https%3A%2F%2Fdrone.rknet.org)](https://drone.rknet.org/ansible/xoxys.droneci_autoscaler)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?label=license)](LICENSE)
Setup [Drone CI autoscaler](https://autoscale.drone.io/).
You can find the full documentation at [https://galaxy.geekdocs.de](https://galaxy.geekdocs.de/roles/cloud/droneci_autoscaler/).
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Maintainers and Contributors
[Robert Kaussow](https://gitea.rknet.org/xoxys)

116
defaults/main.yml Normal file
View File

@ -0,0 +1,116 @@
---
droneci_autoscaler_version: latest
droneci_autoscaler_image: "drone/autoscaler:latest"
droneci_autoscaler_service_directory: /var/lib/docker/services/droneci_autoscaler
droneci_autoscaler_container_name: droneci_autoscaler
droneci_autoscaler_restart_policy: always
droneci_autoscaler_service_stopped: False
# @var droneci_autoscaler_sshkey:description: >
# SSH private key that will by used by the autoscaler to connect to the agents.
# If you dont provide a private key, a keypair will be generated automatically.
# @end
# @var droneci_autoscaler_sshkey: $ "_unset_"
droneci_autoscaler_interval: 1m
droneci_autoscaler_logs_color: False
droneci_autoscaler_logs_pretty: True
droneci_autoscaler_logs_debug: False
droneci_autoscaler_watchtower_enabled: False
droneci_autoscaler_gc_enabled: False
droneci_autoscaler_pool_min: 0
droneci_autoscaler_pool_max: 1
droneci_autoscaler_pool_ttl: 50m
droneci_autoscaler_server_host: droneci
droneci_autoscaler_server_proto: http
droneci_autoscaler_server_token: myveryownsecret
# @var droneci_autoscaler_db_type:description: >
# Database type to use (default sqlite). All other DB variable will ony be used
# it DB type is **not** sqlite.
droneci_autoscaler_db_type: sqlite
# @var droneci_autoscaler_db_server:exaple: $ "localhost"
# @var droneci_autoscaler_db_port:exaple: $ "5432"
# @var droneci_autoscaler_db_name:exaple: $ "droneci_autoscaler"
# @var droneci_autoscaler_db_user:exaple: $ "pgdroneci"
# @var droneci_autoscaler_db_password:exaple: $ "secure"
# @var droneci_autoscaler_db_ssl_mode:exaple: $ "disable"
droneci_autoscaler_agent_token: myveryownsecret
droneci_autoscaler_agent_image: drone/drone-runner-docker:1.5
droneci_autoscaler_agent_concurrency: 2
droneci_autoscaler_agent_os: linux
droneci_autoscaler_agent_architecture: amd64
droneci_autoscaler_agent_volumes: []
droneci_autoscaler_agent_package_upgrade: False
droneci_autoscaler_instances: []
# @var droneci_autoscaler_instances:example: >
# droneci_autoscaler_instances:
# - name: scaler-amd64
# pool_max: 50
# pool_ttl: 120m
# agent_concurrency: 15
# agent_architecture: amd64
# sshkey: "dummy"
# provider_config:
# - name: DRONE_HETZNERCLOUD_DATACENTER
# value: fsn1
# - name: DRONE_HETZNERCLOUD_TOKEN
# value: abc123
# - name: DRONE_HETZNERCLOUD_IMAGE
# value: ubuntu-18.04
# - name: DRONE_HETZNERCLOUD_TYPE
# value:
# # SSH key id from hcloud API
# - name: DRONE_HETZNERCLOUD_SSHKEY
# value:
# - name: DRONE_HETZNERCLOUD_USERDATA_FILE
# value: /etc/scaler/userdata.yml
# @end
droneci_autoscaler_runner_volumes: []
droneci_autoscaler_runner_privileged: []
# @var droneci_autoscaler_volumes:description: >
# Define required docker volumes. If you don't use sqlite you could remove the default volume.
# @end
# @var droneci_autoscaler_volumes:example: >
# droneci_autoscaler_volumes:
# # Instead of the name you could specify a path on the container host system,
# # but you also have to enable bind mount for this volume
# - name: data
# # target location inside the container
# dest: /var/lib/drone_autoscaler
# # enable bind mount, if false volume will be configured as named volume
# # keep in mind you MUST set bind in any case
# bind: True
# @end
droneci_autoscaler_volumes:
- name: data
dest: /var/lib/drone_autoscaler
bind: False
# @var droneci_autoscaler_memory_limit:example: $ "512m"
# @var droneci_autoscaler_memory_limit: $ "_unset_"
# @var droneci_autoscaler_memory_reservation:example: $ "256m"
# @var droneci_autoscaler_memory_reservation: $ "_unset_"
# @var droneci_autoscaler_networks:example: >
# droneci_autoscaler_networks:
# - name: default
# # optional network driver, defaults to 'bride'
# driver: host
# @end
droneci_autoscaler_networks:
- name: droneci_default
external: True
droneci_autoscaler_networks_applied:
- droneci_default

24
meta/main.yml Normal file
View File

@ -0,0 +1,24 @@
# Standards: 0.1
---
galaxy_info:
# @meta author:value: [Robert Kaussow](https://gitea.rknet.org/xoxys)
author: "Robert Kaussow <mail@thegeeklab.de>"
# @meta description: >
# [![Source Code](https://img.shields.io/badge/gitea-source%20code-blue?logo=gitea&logoColor=white)](https://gitea.rknet.org/ansible/xoxys.droneci_autoscaler)
# [![Build Status](https://img.shields.io/drone/build/ansible/xoxys.droneci_autoscaler?logo=drone&server=https%3A%2F%2Fdrone.rknet.org)](https://drone.rknet.org/ansible/xoxys.droneci_autoscaler)
# [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?label=license)](LICENSE)
#
# Setup [Drone CI autoscaler](https://autoscale.drone.io/).
# @end
description: Setup Drone CI autoscaler
license: MIT
min_ansible_version: 2.8
platforms:
- name: EL
versions:
- 7
galaxy_tags:
dependencies: []
collections:
- community.general
- community.crypto

View File

@ -0,0 +1,36 @@
---
- name: Converge
hosts: all
environment:
PYTHONPATH: /opt/python2/ansible-deps/lib/python2.7/site-packages
vars:
dockerengine_packages_extra:
- epel-release
- python-pip
- python-virtualenv
dockerengine_networks:
- name: droneci_default
droneci_autoscaler_service_stopped: True
droneci_autoscaler_instances:
- name: scaler-amd64
pool_max: 50
pool_ttl: 120m
agent_concurrency: 15
agent_architecture: amd64
provider_config:
- name: DRONE_HETZNERCLOUD_DATACENTER
value: fsn1
- name: DRONE_HETZNERCLOUD_TOKEN
value: mytoken
- name: DRONE_HETZNERCLOUD_IMAGE
value: ubuntu-18.04
- name: DRONE_HETZNERCLOUD_TYPE
value: cx11
- name: DRONE_HETZNERCLOUD_SSHKEY
value: keyid1
- name: DRONE_HETZNERCLOUD_USERDATA_FILE
value: /etc/scaler/userdata.yml
roles:
- role: xoxys.docker_engine
- role: xoxys.droneci_autoscaler

View File

@ -0,0 +1,89 @@
---
- name: Create
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ molecule_no_log }}"
vars:
ssh_user: root
ssh_port: 22
keypair_name: molecule_key
keypair_path: "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}/ssh_key"
tasks:
- name: Create local keypair
user:
name: "{{ lookup('env', 'USER') }}"
generate_ssh_key: true
ssh_key_file: "{{ keypair_path }}"
register: local_keypair
- name: Create remote keypair
digital_ocean_sshkey:
name: "{{ keypair_name }}"
ssh_pub_key: "{{ local_keypair.ssh_public_key }}"
state: present
register: remote_keypair
- name: Create molecule instance(s)
digital_ocean_droplet:
name: "{{ item.name }}"
unique_name: true
region: "{{ item.region_id }}"
image: "{{ item.image_id }}"
size: "{{ item.size_id }}"
ssh_keys: "{{ remote_keypair.data.ssh_key.id }}"
wait: true
wait_timeout: 300
state: present
register: server
loop: "{{ molecule_yml.platforms }}"
async: 7200
poll: 0
- name: Wait for instance(s) creation to complete
async_status:
jid: "{{ item.ansible_job_id }}"
register: digitalocean_jobs
until: digitalocean_jobs.finished
retries: 300
loop: "{{ server.results }}"
# Mandatory configuration for Molecule to function.
- name: Populate instance config dict
set_fact:
instance_conf_dict: {
'instance': "{{ item.data.droplet.name }}",
'address': "{{ item.data.ip_address }}",
'user': "{{ ssh_user }}",
'port': "{{ ssh_port }}",
'identity_file': "{{ keypair_path }}",
'droplet_id': "{{ item.data.droplet.id }}",
'ssh_key_id': "{{ remote_keypair.data.ssh_key.id }}",
}
loop: "{{ digitalocean_jobs.results }}"
register: instance_config_dict
when: server.changed | bool
- name: Convert instance config dict to a list
set_fact:
instance_conf: "{{ instance_config_dict.results | map(attribute='ansible_facts.instance_conf_dict') | list }}"
when: server.changed | bool
- name: Dump instance config
copy:
content: "{{ instance_conf | to_json | from_json | molecule_to_yaml | molecule_header }}"
dest: "{{ molecule_instance_config }}"
when: server.changed | bool
- name: Wait for SSH
wait_for:
port: "{{ ssh_port }}"
host: "{{ item.address }}"
search_regex: SSH
delay: 10
timeout: 320
loop: "{{ lookup('file', molecule_instance_config) | molecule_from_yaml }}"

View File

@ -0,0 +1,56 @@
---
- name: Destroy
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ molecule_no_log }}"
tasks:
- block:
- name: Populate instance config
set_fact:
instance_conf: "{{ lookup('file', molecule_instance_config) | molecule_from_yaml }}"
skip_instances: false
rescue:
- name: Populate instance config when file missing
set_fact:
instance_conf: {}
skip_instances: true
- name: Destroy molecule instance(s)
digital_ocean_droplet:
name: "{{ item.instance }}"
id: "{{ item.droplet_id }}"
state: absent
register: server
loop: "{{ instance_conf | flatten(levels=1) }}"
when: not skip_instances
async: 7200
poll: 0
- name: Wait for instance(s) deletion to complete
async_status:
jid: "{{ item.ansible_job_id }}"
register: digitalocean_jobs
until: digitalocean_jobs.finished
retries: 300
loop: "{{ server.results }}"
- name: Delete remote keypair
digital_ocean_sshkey:
fingerprint: "{{ item.ssh_key_id }}"
state: absent
loop: "{{ instance_conf | flatten(levels=1) }}"
# Mandatory configuration for Molecule to function.
- name: Populate instance config
set_fact:
instance_conf: {}
- name: Dump instance config
copy:
content: "{{ instance_conf | molecule_to_yaml | molecule_header }}"
dest: "{{ molecule_instance_config }}"
when: server.changed | bool

View File

@ -0,0 +1,22 @@
---
dependency:
name: galaxy
options:
role-file: molecule/requirements.yml
requirements-file: molecule/requirements.yml
driver:
name: delegated
platforms:
- name: centos7-droneci-autoscaler
region_id: fra1
image_id: centos-7-x64
size_id: s-1vcpu-1gb
lint: |
/usr/local/bin/flake8
provisioner:
name: ansible
env:
ANSIBLE_FILTER_PLUGINS: ${ANSIBLE_FILTER_PLUGINS:-./plugins/filter}
ANSIBLE_LIBRARY: ${ANSIBLE_LIBRARY:-./library}
verifier:
name: testinfra

View File

@ -0,0 +1,9 @@
---
- name: Prepare
hosts: all
gather_facts: false
tasks:
- name: Install python for Ansible
raw: test -e /usr/bin/python || (dnf -y install python3 && alternatives --set python /usr/bin/python3)
become: true
changed_when: false

View File

@ -0,0 +1,15 @@
import os
import testinfra.utils.ansible_runner
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
def test_droneci_compose_file(host):
f = host.file(
'/var/lib/docker/services/droneci_autoscaler_amd64/docker-compose.yml')
assert f.exists

1
molecule/default Symbolic link
View File

@ -0,0 +1 @@
centos7

3
molecule/pytest.ini Normal file
View File

@ -0,0 +1,3 @@
[pytest]
filterwarnings =
ignore::DeprecationWarning

11
molecule/requirements.yml Normal file
View File

@ -0,0 +1,11 @@
---
collections:
- name: https://gitea.rknet.org/ansible/xoxys.general/releases/download/v1.2.0/xoxys-general-1.2.0.tar.gz
- name: community.general
- name: community.crypto
roles:
- src: https://gitea.rknet.org/ansible/xoxys.docker_engine.git
name: xoxys.docker_engine
scm: git
version: master

6
tasks/main.yml Normal file
View File

@ -0,0 +1,6 @@
---
- include_tasks:
file: setup.yml
loop: "{{ droneci_autoscaler_instances }}"
loop_control:
loop_var: inst

55
tasks/setup.yml Normal file
View File

@ -0,0 +1,55 @@
---
- name: Register working directory
set_fact:
__droneci_autoscaler_workdir: "{{ droneci_autoscaler_service_directory }}_{{ inst.name }}"
- name: Register SSH key
set_fact:
__droneci_autoscaler_sshkey: "{{ inst.ssh_key | default(droneci_autoscaler_sshkey) | default(False) }}"
- block:
- name: Ensure service directory exists
file:
path: "{{ __droneci_autoscaler_workdir }}"
state: directory
mode: 0755
- name: Deploy compose file to '{{ __droneci_autoscaler_workdir }}'
template:
src: "services/droneci_autoscaler_compose.yml.j2"
dest: "{{ __droneci_autoscaler_workdir }}/docker-compose.yml"
owner: root
group: root
mode: 0640
validate: "docker-compose -f %s config -q"
- name: Write SSH private key
copy:
content: "{{ item }}"
dest: "{{ __droneci_autoscaler_workdir }}/ssh_key"
mode: 0600
loop: "{{ inst.ssh_key | default(droneci_autoscaler_sshkey) }}"
when: __droneci_autoscaler_sshkey
no_log: True
- name: Generate SSH key pair if missing
openssh_keypair:
path: "{{ __droneci_autoscaler_workdir }}/ssh_key"
type: ed25519
force: False
state: present
- name: Write userdata
template:
src: services/userdata.yml.j2
dest: "{{ __droneci_autoscaler_workdir }}/userdata.yml"
- name: Ensure scaler is up and running
docker_compose:
project_src: "{{ __droneci_autoscaler_workdir }}"
pull: yes
remove_orphans: yes
stopped: "{{ inst.service_stopped | default(droneci_autoscaler_service_stopped) }}"
state: present
become: True
become_user: root

View File

@ -0,0 +1,89 @@
#jinja2:lstrip_blocks: True
{{ ansible_managed | comment }}
version: "2.4"
services:
droneci_autoscaler_{{ inst.name }}:
container_name: {{ droneci_autoscaler_container_name }}
image: {{ droneci_autoscaler_image }}
restart: {{ droneci_autoscaler_restart_policy }}
volumes:
- "{{ __droneci_autoscaler_workdir }}/userdata.yml:/etc/scaler/userdata.yml"
- "{{ __droneci_autoscaler_workdir }}/ssh_key:/root/.ssh/id_rsa:ro"
{% for volume in droneci_autoscaler_volumes %}
- "{{ volume.name }}:{{ volume.dest }}"
{% endfor %}
{% if droneci_autoscaler_networks_applied | default([]) %}
networks:
{% for network in droneci_autoscaler_networks_applied %}
- {{ network }}
{% endfor %}
{% endif %}
environment:
- DRONE_INTERVAL={{ inst.interval | default(droneci_autoscaler_interval) }}
{% if (inst.slack_webhook | default(droneci_autoscaler_slack_webhook)) is defined %}
- DRONE_SLACK_WEBHOOK={{ inst.slack_webhook | default(droneci_autoscaler_slack_webhook) }}
- DRONE_SLACK_CREATE={{ (inst.slack_create | default(droneci_autoscaler_slack_create)) | bool | lower }}
- DRONE_SLACK_DESTROY={{ (inst.slack_destroy | default(droneci_autoscaler_slack_destroy)) | bool | lower }}
- DRONE_SLACK_ERROR={{ (inst.slack_error | default(droneci_autoscaler_slack_error)) | bool | lower }}
{% endif %}
- DRONE_LOGS_COLOR={{ (inst.logs_color | default(droneci_autoscaler_logs_color)) | bool | lower }}
- DRONE_LOGS_PRETTY={{ (inst.logs_pretty | default(droneci_autoscaler_logs_pretty)) | bool | lower }}
- DRONE_LOGS_DEBUG={{ (inst.logs_debug | default(droneci_autoscaler_logs_debug)) | bool | lower }}
- DRONE_POOL_MIN={{ inst.pool_min | default(droneci_autoscaler_pool_min) }}
- DRONE_POOL_MAX={{ inst.pool_max | default(droneci_autoscaler_pool_max) }}
- DRONE_POOL_MIN_AGE={{ inst.pool_ttl | default(droneci_autoscaler_pool_ttl) }}
- DRONE_SERVER_HOST={{ droneci_autoscaler_server_host }}
- DRONE_SERVER_PROTO={{ droneci_autoscaler_server_proto }}
- DRONE_SERVER_TOKEN={{ droneci_autoscaler_server_token }}
- DRONE_AGENT_TOKEN={{ inst.agent_token | default(droneci_autoscaler_agent_token) }}
- DRONE_AGENT_IMAGE={{ inst.agent_image | default(droneci_autoscaler_agent_image) }}
- DRONE_AGENT_CONCURRENCY={{ inst.agent_concurrency | default(droneci_autoscaler_agent_concurrency) }}
- DRONE_AGENT_OS={{ inst.agent_os | default(droneci_autoscaler_agent_os) }}
- DRONE_AGENT_ARCH={{ inst.agent_architecture | default(droneci_autoscaler_agent_architecture) }}
{% if inst.agent_volumes | default(droneci_autoscaler_agent_volumes) | default(False) %}
- DRONE_AGENT_VOLUMES={{ inst.agent_volumes | default(droneci_autoscaler_agent_volumes) | join(",") }}
{% endif %}
{% if inst.runner_volumes | default(droneci_autoscaler_runner_volumes) | default(False) %}
- DRONE_RUNNER_VOLUMES={{ inst.runner_volumes | default(droneci_autoscaler_runner_volumes) | join(",") }}
{% endif %}
- DRONE_RUNNER_PRIVILEGED_IMAGES={{ inst.runner_privileged | default(droneci_autoscaler_runner_privileged) | join(",") }}
- DRONE_GC_ENABLED={{ (inst.gc_enabled | default(droneci_autoscaler_gc_enabled)) | bool | lower }}
- DRONE_GC_DEBUG=false
- DRONE_REAPER_ENABLED=true
- DRONE_REAPER_INTERVAL=30m
- DRONE_WATCHTOWER_ENABLED={{ (inst.watchtower_enabled | default(droneci_autoscaler_watchtower_enabled)) | bool | lower }}
{% if (inst.prometheus_token | default(droneci_autoscaler_prometheus_token)) is defined %}
- DRONE_PROMETHEUS_AUTH_TOKEN={{ inst.prometheus_token | default(droneci_autoscaler_prometheus_token) }}
{% endif %}
{% if droneci_autoscaler_db_type == "pgsql" %}
- DRONE_DATABASE_DRIVER=postgres
- DRONE_DATABASE_DATASOURCE=postgres://{{ droneci_autoscaler_db_user }}:{{ droneci_autoscaler_db_password }}@{{ droneci_autoscaler_db_server }}/{{ droneci_autoscaler_db_name }}?sslmode={{ droneci_autoscaler_db_ssl_mode }}
{% endif %}
{% for item in inst.provider_config %}
- {{ item.name | upper }}={{ item.value }}
{% endfor %}
{% if droneci_autoscaler_memory_limit is defined %}
mem_limit: {{ droneci_autoscaler_memory_limit }}
{% endif %}
{% if droneci_autoscaler_memory_reservation is defined %}
mem_reservation: {{ droneci_autoscaler_memory_reservation }}
{% endif %}
{% if droneci_autoscaler_networks | default([]) | length > 0 %}
{% if droneci_autoscaler_volumes | default([]) | rejectattr("bind") | list | length > 0 %}
volumes:
{% for volume in droneci_autoscaler_volumes | rejectattr("bind") %}
{{ volume.name }}:
{% endfor %}
{% endif %}
networks:
{% for network in droneci_autoscaler_networks %}
{{ network.name }}:
{% if network.external | default(False) | bool %}
external: true
{% else %}
driver: {{ network.backend | default("bridge") }}
{% endif %}
{% endfor %}
{% endif %}

View File

@ -0,0 +1,61 @@
#jinja2: lstrip_blocks: True
#cloud-config
apt_reboot_if_required: false
package_update: true
package_upgrade: {{ droneci_autoscaler_agent_package_upgrade | bool | lower }}
{% if inst.agent_architecture | default(droneci_autoscaler_agent_architecture) == "arm" %}
bootcmd:
- [ dpkg, --add-architecture, armhf ]
{% endif %}
apt:
sources:
docker.list:
source: deb [arch={% if inst.agent_architecture | default(droneci_autoscaler_agent_architecture) == "arm" %}armhf{% elif inst.agent_architecture | default(droneci_autoscaler_agent_architecture) == "arm64" %}arm64{% else %}amd64{% endif %}] https://download.docker.com/linux/ubuntu $RELEASE stable
keyid: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88
packages:
- bridge-utils
- 'docker-ce{{ ':armhf' if inst.agent_architecture | default(droneci_autoscaler_agent_architecture) == "arm" else '' }}'
write_files:
- path: /etc/systemd/system/docker.service.d/override.conf
content: |
[Service]
ExecStart=
ExecStart={% if inst.agent_architecture | default(droneci_autoscaler_agent_architecture) == "arm" %}/usr/bin/setarch linux32 -B {% endif %}/usr/bin/dockerd
- path: /etc/systemd/system/containerd.service.d/override.conf
content: |
[Service]
ExecStart=
ExecStart={% if inst.agent_architecture | default(droneci_autoscaler_agent_architecture) == "arm" %}/usr/bin/setarch linux32 -B {% endif %}/usr/bin/containerd
- path: /etc/default/docker
content: |
DOCKER_OPTS=""
- path: /etc/docker/daemon.json
content: |
{
"hosts": ["0.0.0.0:2376", "unix:///var/run/docker.sock"],
"tls": true,
"tlsverify": true,
"tlscacert": "/etc/docker/ca.pem",
"tlscert": "/etc/docker/server-cert.pem",
"tlskey": "/etc/docker/server-key.pem"
}
- path: /etc/docker/ca.pem
encoding: b64
content: {% raw %}{{ .CACert | base64 }}{% endraw %}
- path: /etc/docker/server-cert.pem
encoding: b64
content: {% raw %}{{ .TLSCert | base64 }}{% endraw %}
- path: /etc/docker/server-key.pem
encoding: b64
content: {% raw %}{{ .TLSKey | base64 }}{% endraw %}