Compare commits

...

No commits in common. "main" and "docs" have entirely different histories.
main ... docs

26 changed files with 1034 additions and 1155 deletions

View File

@ -1,159 +0,0 @@
local PipelineLinting = {
kind: 'pipeline',
name: 'linting',
platform: {
os: 'linux',
arch: 'amd64',
},
steps: [
{
name: 'ansible-later',
image: 'thegeeklab/ansible-later',
commands: [
'ansible-later',
],
},
{
name: 'python-format',
image: 'python:3.11',
environment: {
PY_COLORS: 1,
},
commands: [
'pip install -qq yapf',
'[ -z "$(find . -type f -name *.py)" ] || (yapf -rd ./)',
],
},
{
name: 'python-flake8',
image: 'python:3.11',
environment: {
PY_COLORS: 1,
},
commands: [
'pip install -qq flake8',
'flake8',
],
},
],
trigger: {
ref: ['refs/heads/main', '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: 'thegeeklab/molecule:4',
environment: {
HCLOUD_TOKEN: { from_secret: 'hcloud_token' },
},
commands: [
'molecule test -s ' + scenario,
],
},
],
depends_on: [
'linting',
],
trigger: {
ref: ['refs/heads/main', 'refs/tags/**'],
},
};
local PipelineDocumentation = {
kind: 'pipeline',
name: 'documentation',
platform: {
os: 'linux',
arch: 'amd64',
},
steps: [
{
name: 'generate',
image: 'thegeeklab/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/main'],
},
},
],
trigger: {
ref: ['refs/heads/main', '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: 'thegeeklab/drone-matrix',
settings: {
homeserver: { from_secret: 'matrix_homeserver' },
roomid: { from_secret: 'matrix_roomid' },
template: 'Status: **{{ .Build.Status }}**<br/> Build: [{{ .Repo.Owner }}/{{ .Repo.Name }}]({{ .Build.Link }}){{ if .Build.Branch }} ({{ .Build.Branch }}){{ end }} by {{ .Commit.Author }}<br/> Message: {{ .Commit.Message.Title }}',
username: { from_secret: 'matrix_username' },
password: { from_secret: 'matrix_password' },
},
},
],
depends_on: [
'documentation',
],
trigger: {
status: ['success', 'failure'],
ref: ['refs/heads/main', 'refs/tags/**'],
},
};
[
PipelineLinting,
PipelineDeployment(scenario='centos7'),
PipelineDocumentation,
PipelineNotification,
]

View File

@ -1,152 +0,0 @@
---
kind: pipeline
name: linting
platform:
os: linux
arch: amd64
steps:
- name: ansible-later
image: thegeeklab/ansible-later
commands:
- ansible-later
- name: python-format
image: python:3.11
commands:
- pip install -qq yapf
- "[ -z \"$(find . -type f -name *.py)\" ] || (yapf -rd ./)"
environment:
PY_COLORS: 1
- name: python-flake8
image: python:3.11
commands:
- pip install -qq flake8
- flake8
environment:
PY_COLORS: 1
trigger:
ref:
- refs/heads/main
- refs/tags/**
- refs/pull/**
---
kind: pipeline
name: testing-centos7
platform:
os: linux
arch: amd64
concurrency:
limit: 1
workspace:
base: /drone/src
path: ${DRONE_REPO_NAME}
steps:
- name: ansible-molecule
image: thegeeklab/molecule:4
commands:
- molecule test -s centos7
environment:
HCLOUD_TOKEN:
from_secret: hcloud_token
trigger:
ref:
- refs/heads/main
- refs/tags/**
depends_on:
- linting
---
kind: pipeline
name: documentation
platform:
os: linux
arch: amd64
steps:
- name: generate
image: thegeeklab/ansible-doctor
environment:
ANSIBLE_DOCTOR_EXCLUDE_FILES: molecule/
ANSIBLE_DOCTOR_FORCE_OVERWRITE: true
ANSIBLE_DOCTOR_LOG_LEVEL: INFO
ANSIBLE_DOCTOR_OUTPUT_DIR: _docs/
ANSIBLE_DOCTOR_ROLE_NAME: ${DRONE_REPO_NAME#*.}
ANSIBLE_DOCTOR_TEMPLATE: hugo-book
- name: publish
image: plugins/gh-pages
settings:
netrc_machine: gitea.rknet.org
pages_directory: _docs/
password:
from_secret: gitea_token
remote_url: https://gitea.rknet.org/ansible/${DRONE_REPO_NAME}
target_branch: docs
username:
from_secret: gitea_username
when:
ref:
- refs/heads/main
trigger:
ref:
- refs/heads/main
- refs/tags/**
- refs/pull/**
depends_on:
- testing-centos7
---
kind: pipeline
name: notification
platform:
os: linux
arch: amd64
clone:
disable: true
steps:
- name: matrix
image: thegeeklab/drone-matrix
settings:
homeserver:
from_secret: matrix_homeserver
password:
from_secret: matrix_password
roomid:
from_secret: matrix_roomid
template: "Status: **{{ .Build.Status }}**<br/> Build: [{{ .Repo.Owner }}/{{ .Repo.Name }}]({{ .Build.Link }}){{ if .Build.Branch }} ({{ .Build.Branch }}){{ end }} by {{ .Commit.Author }}<br/> Message: {{ .Commit.Message.Title }}"
username:
from_secret: matrix_username
trigger:
ref:
- refs/heads/main
- refs/tags/**
status:
- success
- failure
depends_on:
- documentation
---
kind: signature
hmac: a356b609c0fd7dfe9de4d45d218e6690933d418d384972c38aa11a25e75bba1f
...

13
.gitignore vendored
View File

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

View File

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

View File

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

21
LICENSE
View File

@ -1,21 +0,0 @@
MIT License
Copyright (c) 2022 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.

View File

@ -1,12 +0,0 @@
# 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.

522
_docs/index.md Normal file
View File

@ -0,0 +1,522 @@
---
title: droneci_autoscaler
type: docs
---
[![Source Code](https://img.shields.io/badge/gitea-source%20code-blue?logo=gitea&amp;logoColor=white)](https://gitea.rknet.org/ansible/xoxys.droneci_autoscaler)
[![Build Status](https://img.shields.io/drone/build/ansible/xoxys.droneci_autoscaler?logo=drone&amp;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)](https://gitea.rknet.org/ansible/xoxys.droneci_autoscaler/src/branch/main/LICENSE)
Setup [Drone CI autoscaler](https://autoscale.drone.io/).
<!--more-->
- [Requirements](#requirements)
- [Default Variables](#default-variables)
- [droneci_autoscaler_agent_architecture](#droneci_autoscaler_agent_architecture)
- [droneci_autoscaler_agent_concurrency](#droneci_autoscaler_agent_concurrency)
- [droneci_autoscaler_agent_distro](#droneci_autoscaler_agent_distro)
- [droneci_autoscaler_agent_dns](#droneci_autoscaler_agent_dns)
- [droneci_autoscaler_agent_image](#droneci_autoscaler_agent_image)
- [droneci_autoscaler_agent_os](#droneci_autoscaler_agent_os)
- [droneci_autoscaler_agent_package_upgrade](#droneci_autoscaler_agent_package_upgrade)
- [droneci_autoscaler_agent_packages](#droneci_autoscaler_agent_packages)
- [droneci_autoscaler_agent_runcmd](#droneci_autoscaler_agent_runcmd)
- [droneci_autoscaler_agent_token](#droneci_autoscaler_agent_token)
- [droneci_autoscaler_agent_version](#droneci_autoscaler_agent_version)
- [droneci_autoscaler_agent_volumes](#droneci_autoscaler_agent_volumes)
- [droneci_autoscaler_db_type](#droneci_autoscaler_db_type)
- [droneci_autoscaler_docker_auth_config](#droneci_autoscaler_docker_auth_config)
- [droneci_autoscaler_exposed_ports](#droneci_autoscaler_exposed_ports)
- [droneci_autoscaler_gc_enabled](#droneci_autoscaler_gc_enabled)
- [droneci_autoscaler_image](#droneci_autoscaler_image)
- [droneci_autoscaler_instances](#droneci_autoscaler_instances)
- [droneci_autoscaler_interval](#droneci_autoscaler_interval)
- [droneci_autoscaler_logs_color](#droneci_autoscaler_logs_color)
- [droneci_autoscaler_logs_debug](#droneci_autoscaler_logs_debug)
- [droneci_autoscaler_logs_pretty](#droneci_autoscaler_logs_pretty)
- [droneci_autoscaler_memory_limit](#droneci_autoscaler_memory_limit)
- [droneci_autoscaler_memory_reservation](#droneci_autoscaler_memory_reservation)
- [droneci_autoscaler_networks](#droneci_autoscaler_networks)
- [droneci_autoscaler_networks_applied](#droneci_autoscaler_networks_applied)
- [droneci_autoscaler_pool_max](#droneci_autoscaler_pool_max)
- [droneci_autoscaler_pool_min](#droneci_autoscaler_pool_min)
- [droneci_autoscaler_pool_ttl](#droneci_autoscaler_pool_ttl)
- [droneci_autoscaler_restart_policy](#droneci_autoscaler_restart_policy)
- [droneci_autoscaler_runner_env_file](#droneci_autoscaler_runner_env_file)
- [droneci_autoscaler_runner_privileged](#droneci_autoscaler_runner_privileged)
- [droneci_autoscaler_runner_volumes](#droneci_autoscaler_runner_volumes)
- [droneci_autoscaler_server_host](#droneci_autoscaler_server_host)
- [droneci_autoscaler_server_proto](#droneci_autoscaler_server_proto)
- [droneci_autoscaler_server_token](#droneci_autoscaler_server_token)
- [droneci_autoscaler_service_directory](#droneci_autoscaler_service_directory)
- [droneci_autoscaler_service_stopped](#droneci_autoscaler_service_stopped)
- [droneci_autoscaler_sshkey](#droneci_autoscaler_sshkey)
- [droneci_autoscaler_version](#droneci_autoscaler_version)
- [droneci_autoscaler_volumes](#droneci_autoscaler_volumes)
- [droneci_autoscaler_watchtower_enabled](#droneci_autoscaler_watchtower_enabled)
- [Dependencies](#dependencies)
---
## Requirements
- Minimum Ansible version: `2.1`
## Default Variables
### droneci_autoscaler_agent_architecture
#### Default value
```YAML
droneci_autoscaler_agent_architecture: amd64
```
### droneci_autoscaler_agent_concurrency
#### Default value
```YAML
droneci_autoscaler_agent_concurrency: 2
```
### droneci_autoscaler_agent_distro
#### Default value
```YAML
droneci_autoscaler_agent_distro: ubuntu
```
### droneci_autoscaler_agent_dns
#### Default value
```YAML
droneci_autoscaler_agent_dns: []
```
### droneci_autoscaler_agent_image
#### Default value
```YAML
droneci_autoscaler_agent_image: drone/drone-runner-docker:{{ droneci_autoscaler_agent_version
}}
```
### droneci_autoscaler_agent_os
#### Default value
```YAML
droneci_autoscaler_agent_os: linux
```
### droneci_autoscaler_agent_package_upgrade
#### Default value
```YAML
droneci_autoscaler_agent_package_upgrade: false
```
### droneci_autoscaler_agent_packages
Install extra required packages during agents bootstrapping.
#### Default value
```YAML
droneci_autoscaler_agent_packages: []
```
### droneci_autoscaler_agent_runcmd
#### Default value
```YAML
droneci_autoscaler_agent_runcmd: []
```
### droneci_autoscaler_agent_token
#### Default value
```YAML
droneci_autoscaler_agent_token: myveryownsecret
```
### droneci_autoscaler_agent_version
#### Default value
```YAML
droneci_autoscaler_agent_version: latest
```
### droneci_autoscaler_agent_volumes
#### Default value
```YAML
droneci_autoscaler_agent_volumes: []
```
### droneci_autoscaler_db_type
Database type to use (default sqlite). All other DB variable will ony be used
it DB type is **not** sqlite.
#### Default value
```YAML
droneci_autoscaler_db_type: sqlite
```
### droneci_autoscaler_docker_auth_config
Docker registries auth config file (config.json).
#### Default value
```YAML
droneci_autoscaler_docker_auth_config: |
{
"auths": {
"https://index.docker.io/v1/": {
"auth": "abc...xy="
}
}
}
```
### droneci_autoscaler_exposed_ports
#### Default value
```YAML
droneci_autoscaler_exposed_ports: []
```
#### Example usage
```YAML
droneci_autoscaler_exposed_ports:
- "8080:8080"
```
### droneci_autoscaler_gc_enabled
#### Default value
```YAML
droneci_autoscaler_gc_enabled: false
```
### droneci_autoscaler_image
#### Default value
```YAML
droneci_autoscaler_image: drone/autoscaler:{{ droneci_autoscaler_version }}
```
### droneci_autoscaler_instances
#### Default value
```YAML
droneci_autoscaler_instances: []
```
#### Example usage
```YAML
droneci_autoscaler_instances:
- name: scaler_amd64
pool_max: 50
pool_ttl: 120m
agent_concurrency: 15
agent_architecture: amd64
sshkey: "dummy"
api_host: "drone-amd64.example.com"
docker_auth_config: |
{
"auths": {
"https://index.docker.io/v1/": {
"auth": "abc...xy="
}
}
}
exposed_ports:
- "8080:8080"
provider_config:
- name: DRONE_HETZNERCLOUD_DATACENTER
value: fsn1-dc14
- 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
```
### droneci_autoscaler_interval
#### Default value
```YAML
droneci_autoscaler_interval: 1m
```
### droneci_autoscaler_logs_color
#### Default value
```YAML
droneci_autoscaler_logs_color: false
```
### droneci_autoscaler_logs_debug
#### Default value
```YAML
droneci_autoscaler_logs_debug: false
```
### droneci_autoscaler_logs_pretty
#### Default value
```YAML
droneci_autoscaler_logs_pretty: true
```
### droneci_autoscaler_memory_limit
#### Default value
```YAML
droneci_autoscaler_memory_limit: _unset_
```
#### Example usage
```YAML
droneci_autoscaler_memory_limit: 512m
```
### droneci_autoscaler_memory_reservation
#### Default value
```YAML
droneci_autoscaler_memory_reservation: _unset_
```
#### Example usage
```YAML
droneci_autoscaler_memory_reservation: 256m
```
### droneci_autoscaler_networks
#### Default value
```YAML
droneci_autoscaler_networks:
- name: droneci_default
external: true
```
#### Example usage
```YAML
droneci_autoscaler_networks:
- name: default
# optional network driver, defaults to 'bride'
driver: host
```
### droneci_autoscaler_networks_applied
#### Default value
```YAML
droneci_autoscaler_networks_applied:
- droneci_default
```
### droneci_autoscaler_pool_max
#### Default value
```YAML
droneci_autoscaler_pool_max: 1
```
### droneci_autoscaler_pool_min
#### Default value
```YAML
droneci_autoscaler_pool_min: 0
```
### droneci_autoscaler_pool_ttl
#### Default value
```YAML
droneci_autoscaler_pool_ttl: 50m
```
### droneci_autoscaler_restart_policy
#### Default value
```YAML
droneci_autoscaler_restart_policy: always
```
### droneci_autoscaler_runner_env_file
The file needs to be mounted to the runner **and** agent.
#### Default value
```YAML
droneci_autoscaler_runner_env_file: _unset_
```
#### Example usage
```YAML
droneci_autoscaler_runner_env_file: /etc/drone.conf
```
### droneci_autoscaler_runner_privileged
#### Default value
```YAML
droneci_autoscaler_runner_privileged: []
```
### droneci_autoscaler_runner_volumes
#### Default value
```YAML
droneci_autoscaler_runner_volumes: []
```
### droneci_autoscaler_server_host
#### Default value
```YAML
droneci_autoscaler_server_host: droneci
```
### droneci_autoscaler_server_proto
#### Default value
```YAML
droneci_autoscaler_server_proto: http
```
### droneci_autoscaler_server_token
#### Default value
```YAML
droneci_autoscaler_server_token: myveryownsecret
```
### droneci_autoscaler_service_directory
#### Default value
```YAML
droneci_autoscaler_service_directory: /var/lib/docker/services/droneci_autoscaler
```
### droneci_autoscaler_service_stopped
#### Default value
```YAML
droneci_autoscaler_service_stopped: false
```
### droneci_autoscaler_sshkey
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.
#### Default value
```YAML
droneci_autoscaler_sshkey: _unset_
```
### droneci_autoscaler_version
#### Default value
```YAML
droneci_autoscaler_version: latest
```
### droneci_autoscaler_volumes
Define required docker volumes. If you don't use sqlite you could remove the default volume.
#### Default value
```YAML
droneci_autoscaler_volumes:
- name: data
dest: /var/lib/drone_autoscaler
bind: false
```
#### Example usage
```YAML
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
```
### droneci_autoscaler_watchtower_enabled
#### Default value
```YAML
droneci_autoscaler_watchtower_enabled: false
```
## Dependencies
None.

View File

@ -1,157 +0,0 @@
---
droneci_autoscaler_version: latest
droneci_autoscaler_image: "drone/autoscaler:{{ droneci_autoscaler_version }}"
droneci_autoscaler_service_directory: /var/lib/docker/services/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_version: latest
droneci_autoscaler_agent_image: "drone/drone-runner-docker:{{ droneci_autoscaler_agent_version }}"
droneci_autoscaler_agent_concurrency: 2
droneci_autoscaler_agent_os: linux
droneci_autoscaler_agent_architecture: amd64
droneci_autoscaler_agent_distro: ubuntu
droneci_autoscaler_agent_volumes: []
droneci_autoscaler_agent_package_upgrade: False
droneci_autoscaler_agent_dns: []
droneci_autoscaler_agent_runcmd: []
# @var droneci_autoscaler_agent_packages:description: >
# Install extra required packages during agents bootstrapping.
# @end
droneci_autoscaler_agent_packages: []
# @var droneci_autoscaler_docker_auth_config:description: Docker registries auth config file (config.json).
# @var droneci_autoscaler_docker_auth_config: >
# droneci_autoscaler_docker_auth_config: |
# {
# "auths": {
# "https://index.docker.io/v1/": {
# "auth": "abc...xy="
# }
# }
# }
# @end
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"
# api_host: "drone-amd64.example.com"
# docker_auth_config: |
# {
# "auths": {
# "https://index.docker.io/v1/": {
# "auth": "abc...xy="
# }
# }
# }
# exposed_ports:
# - "8080:8080"
# provider_config:
# - name: DRONE_HETZNERCLOUD_DATACENTER
# value: fsn1-dc14
# - 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_runner_env_file:description: The file needs to be mounted to the runner **and** agent.
# @var droneci_autoscaler_runner_env_file: $ "_unset_"
# @var droneci_autoscaler_runner_env_file:example: $ "/etc/drone.conf"
# @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_exposed_ports: []
# @var droneci_autoscaler_exposed_ports:example: >
# droneci_autoscaler_exposed_ports:
# - "8080:8080"
# @end
droneci_autoscaler_networks_applied:
- droneci_default

View File

@ -1,11 +0,0 @@
---
- name: Restart scaler service
docker_compose:
project_src: "{{ __droneci_autoscaler_workdir }}"
pull: yes
remove_orphans: yes
stopped: "{{ inst.service_stopped | default(droneci_autoscaler_service_stopped) }}"
restarted: "{{ not (inst.service_stopped | default(droneci_autoscaler_service_stopped)) }}"
listen: __droneci_autoscaler_restart
become: True
become_user: root

512
index.md Normal file
View File

@ -0,0 +1,512 @@
---
title: droneci_autoscaler
type: docs
---
[![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)](https://gitea.rknet.org/ansible/xoxys.droneci_autoscaler/src/branch/main/LICENSE)
Setup [Drone CI autoscaler](https://autoscale.drone.io/).
<!--more-->
- [Default Variables](#default-variables)
- [droneci_autoscaler_agent_architecture](#droneci_autoscaler_agent_architecture)
- [droneci_autoscaler_agent_concurrency](#droneci_autoscaler_agent_concurrency)
- [droneci_autoscaler_agent_distro](#droneci_autoscaler_agent_distro)
- [droneci_autoscaler_agent_image](#droneci_autoscaler_agent_image)
- [droneci_autoscaler_agent_os](#droneci_autoscaler_agent_os)
- [droneci_autoscaler_agent_package_upgrade](#droneci_autoscaler_agent_package_upgrade)
- [droneci_autoscaler_agent_packages](#droneci_autoscaler_agent_packages)
- [droneci_autoscaler_agent_resolved_dns](#droneci_autoscaler_agent_resolved_dns)
- [droneci_autoscaler_agent_runcmd](#droneci_autoscaler_agent_runcmd)
- [droneci_autoscaler_agent_token](#droneci_autoscaler_agent_token)
- [droneci_autoscaler_agent_version](#droneci_autoscaler_agent_version)
- [droneci_autoscaler_agent_volumes](#droneci_autoscaler_agent_volumes)
- [droneci_autoscaler_db_type](#droneci_autoscaler_db_type)
- [droneci_autoscaler_docker_auth_config](#droneci_autoscaler_docker_auth_config)
- [droneci_autoscaler_exposed_ports](#droneci_autoscaler_exposed_ports)
- [droneci_autoscaler_gc_enabled](#droneci_autoscaler_gc_enabled)
- [droneci_autoscaler_image](#droneci_autoscaler_image)
- [droneci_autoscaler_instances](#droneci_autoscaler_instances)
- [droneci_autoscaler_interval](#droneci_autoscaler_interval)
- [droneci_autoscaler_logs_color](#droneci_autoscaler_logs_color)
- [droneci_autoscaler_logs_debug](#droneci_autoscaler_logs_debug)
- [droneci_autoscaler_logs_pretty](#droneci_autoscaler_logs_pretty)
- [droneci_autoscaler_memory_limit](#droneci_autoscaler_memory_limit)
- [droneci_autoscaler_memory_reservation](#droneci_autoscaler_memory_reservation)
- [droneci_autoscaler_networks](#droneci_autoscaler_networks)
- [droneci_autoscaler_networks_applied](#droneci_autoscaler_networks_applied)
- [droneci_autoscaler_pool_max](#droneci_autoscaler_pool_max)
- [droneci_autoscaler_pool_min](#droneci_autoscaler_pool_min)
- [droneci_autoscaler_pool_ttl](#droneci_autoscaler_pool_ttl)
- [droneci_autoscaler_restart_policy](#droneci_autoscaler_restart_policy)
- [droneci_autoscaler_runner_env_file](#droneci_autoscaler_runner_env_file)
- [droneci_autoscaler_runner_privileged](#droneci_autoscaler_runner_privileged)
- [droneci_autoscaler_runner_volumes](#droneci_autoscaler_runner_volumes)
- [droneci_autoscaler_server_host](#droneci_autoscaler_server_host)
- [droneci_autoscaler_server_proto](#droneci_autoscaler_server_proto)
- [droneci_autoscaler_server_token](#droneci_autoscaler_server_token)
- [droneci_autoscaler_service_directory](#droneci_autoscaler_service_directory)
- [droneci_autoscaler_service_stopped](#droneci_autoscaler_service_stopped)
- [droneci_autoscaler_sshkey](#droneci_autoscaler_sshkey)
- [droneci_autoscaler_version](#droneci_autoscaler_version)
- [droneci_autoscaler_volumes](#droneci_autoscaler_volumes)
- [droneci_autoscaler_watchtower_enabled](#droneci_autoscaler_watchtower_enabled)
- [Dependencies](#dependencies)
---
## Default Variables
### droneci_autoscaler_agent_architecture
#### Default value
```YAML
droneci_autoscaler_agent_architecture: amd64
```
### droneci_autoscaler_agent_concurrency
#### Default value
```YAML
droneci_autoscaler_agent_concurrency: 2
```
### droneci_autoscaler_agent_distro
#### Default value
```YAML
droneci_autoscaler_agent_distro: ubuntu
```
### droneci_autoscaler_agent_image
#### Default value
```YAML
droneci_autoscaler_agent_image: drone/drone-runner-docker:{{ droneci_autoscaler_agent_version
}}
```
### droneci_autoscaler_agent_os
#### Default value
```YAML
droneci_autoscaler_agent_os: linux
```
### droneci_autoscaler_agent_package_upgrade
#### Default value
```YAML
droneci_autoscaler_agent_package_upgrade: false
```
### droneci_autoscaler_agent_packages
Install extra required packages during agents bootstrapping.
#### Default value
```YAML
droneci_autoscaler_agent_packages: []
```
### droneci_autoscaler_agent_resolved_dns
#### Default value
```YAML
droneci_autoscaler_agent_resolved_dns: []
```
### droneci_autoscaler_agent_runcmd
#### Default value
```YAML
droneci_autoscaler_agent_runcmd: []
```
### droneci_autoscaler_agent_token
#### Default value
```YAML
droneci_autoscaler_agent_token: myveryownsecret
```
### droneci_autoscaler_agent_version
#### Default value
```YAML
droneci_autoscaler_agent_version: latest
```
### droneci_autoscaler_agent_volumes
#### Default value
```YAML
droneci_autoscaler_agent_volumes: []
```
### droneci_autoscaler_db_type
Database type to use (default sqlite). All other DB variable will ony be used it DB type is **not** sqlite.
#### Default value
```YAML
droneci_autoscaler_db_type: sqlite
```
### droneci_autoscaler_docker_auth_config
Docker registries auth config file (config.json).
#### Default value
```YAML
droneci_autoscaler_docker_auth_config: |
{
"auths": {
"https://index.docker.io/v1/": {
"auth": "abc...xy="
}
}
}
```
### droneci_autoscaler_exposed_ports
#### Default value
```YAML
droneci_autoscaler_exposed_ports: []
```
#### Example usage
```YAML
droneci_autoscaler_exposed_ports:
- "8080:8080"
```
### droneci_autoscaler_gc_enabled
#### Default value
```YAML
droneci_autoscaler_gc_enabled: false
```
### droneci_autoscaler_image
#### Default value
```YAML
droneci_autoscaler_image: drone/autoscaler:{{ droneci_autoscaler_version }}
```
### droneci_autoscaler_instances
#### Default value
```YAML
droneci_autoscaler_instances: []
```
#### Example usage
```YAML
droneci_autoscaler_instances:
- name: scaler_amd64
pool_max: 50
pool_ttl: 120m
agent_concurrency: 15
agent_architecture: amd64
sshkey: "dummy"
api_host: "drone-amd64.example.com"
docker_auth_config: |
{
"auths": {
"https://index.docker.io/v1/": {
"auth": "abc...xy="
}
}
}
exposed_ports:
- "8080:8080"
provider_config:
- name: DRONE_HETZNERCLOUD_DATACENTER
value: fsn1-dc14
- 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
```
### droneci_autoscaler_interval
#### Default value
```YAML
droneci_autoscaler_interval: 1m
```
### droneci_autoscaler_logs_color
#### Default value
```YAML
droneci_autoscaler_logs_color: false
```
### droneci_autoscaler_logs_debug
#### Default value
```YAML
droneci_autoscaler_logs_debug: false
```
### droneci_autoscaler_logs_pretty
#### Default value
```YAML
droneci_autoscaler_logs_pretty: true
```
### droneci_autoscaler_memory_limit
#### Default value
```YAML
droneci_autoscaler_memory_limit: _unset_
```
#### Example usage
```YAML
droneci_autoscaler_memory_limit: 512m
```
### droneci_autoscaler_memory_reservation
#### Default value
```YAML
droneci_autoscaler_memory_reservation: _unset_
```
#### Example usage
```YAML
droneci_autoscaler_memory_reservation: 256m
```
### droneci_autoscaler_networks
#### Default value
```YAML
droneci_autoscaler_networks:
- name: droneci_default
external: true
```
#### Example usage
```YAML
droneci_autoscaler_networks:
- name: default
# optional network driver, defaults to 'bride'
driver: host
```
### droneci_autoscaler_networks_applied
#### Default value
```YAML
droneci_autoscaler_networks_applied:
- droneci_default
```
### droneci_autoscaler_pool_max
#### Default value
```YAML
droneci_autoscaler_pool_max: 1
```
### droneci_autoscaler_pool_min
#### Default value
```YAML
droneci_autoscaler_pool_min: 0
```
### droneci_autoscaler_pool_ttl
#### Default value
```YAML
droneci_autoscaler_pool_ttl: 50m
```
### droneci_autoscaler_restart_policy
#### Default value
```YAML
droneci_autoscaler_restart_policy: always
```
### droneci_autoscaler_runner_env_file
The file needs to be mounted to the runner **and** agent.
#### Default value
```YAML
droneci_autoscaler_runner_env_file: _unset_
```
#### Example usage
```YAML
droneci_autoscaler_runner_env_file: /etc/drone.conf
```
### droneci_autoscaler_runner_privileged
#### Default value
```YAML
droneci_autoscaler_runner_privileged: []
```
### droneci_autoscaler_runner_volumes
#### Default value
```YAML
droneci_autoscaler_runner_volumes: []
```
### droneci_autoscaler_server_host
#### Default value
```YAML
droneci_autoscaler_server_host: droneci
```
### droneci_autoscaler_server_proto
#### Default value
```YAML
droneci_autoscaler_server_proto: http
```
### droneci_autoscaler_server_token
#### Default value
```YAML
droneci_autoscaler_server_token: myveryownsecret
```
### droneci_autoscaler_service_directory
#### Default value
```YAML
droneci_autoscaler_service_directory: /var/lib/docker/services/droneci_autoscaler
```
### droneci_autoscaler_service_stopped
#### Default value
```YAML
droneci_autoscaler_service_stopped: false
```
### droneci_autoscaler_sshkey
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.
#### Default value
```YAML
droneci_autoscaler_sshkey: _unset_
```
### droneci_autoscaler_version
#### Default value
```YAML
droneci_autoscaler_version: latest
```
### droneci_autoscaler_volumes
Define required docker volumes. If you don't use sqlite you could remove the default volume.
#### Default value
```YAML
droneci_autoscaler_volumes:
- name: data
dest: /var/lib/drone_autoscaler
bind: false
```
#### Example usage
```YAML
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
```
### droneci_autoscaler_watchtower_enabled
#### Default value
```YAML
droneci_autoscaler_watchtower_enabled: false
```
## Dependencies
None.

View File

@ -1,27 +0,0 @@
# Standards: 0.2
---
galaxy_info:
# @meta author:value: [Robert Kaussow](https://gitea.rknet.org/xoxys)
author: "Robert Kaussow <mail@thegeeklab.de>"
namespace: xoxys
role_name: droneci_autoscaler
# @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)](https://gitea.rknet.org/ansible/xoxys.droneci_autoscaler/src/branch/main/LICENSE)
#
# Setup [Drone CI autoscaler](https://autoscale.drone.io/).
# @end
description: Setup Drone CI autoscaler
license: MIT
min_ansible_version: 2.10
platforms:
- name: EL
versions:
- 7
galaxy_tags: []
dependencies: []
collections:
- xoxys.general
- community.general
- community.crypto

View File

@ -1,48 +0,0 @@
---
- 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_docker_auth_config: |
{
"auths": {
"https://index.docker.io/v1/": {
"auth": "abc...xy="
}
}
}
droneci_autoscaler_agent_volumes:
- "/root/.docker/config.json:/root/.docker/config.json"
droneci_autoscaler_agent_environ:
- "DRONE_DOCKER_CONFIG=/root/.docker/config.json"
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-dc14
- 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

@ -1,120 +0,0 @@
---
- name: Create
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ molecule_no_log }}"
vars:
ssh_port: 22
ssh_user: root
ssh_path: "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}/ssh_key"
tasks:
- name: Create SSH key
user:
name: "{{ lookup('env', 'USER') }}"
generate_ssh_key: true
ssh_key_file: "{{ ssh_path }}"
force: true
register: generated_ssh_key
- name: Register the SSH key name
set_fact:
ssh_key_name: "molecule-generated-{{ 12345 | random | to_uuid }}"
- name: Register SSH key for test instance(s)
hcloud_ssh_key:
name: "{{ ssh_key_name }}"
public_key: "{{ generated_ssh_key.ssh_public_key }}"
state: present
- name: Create molecule instance(s)
hcloud_server:
name: "{{ item.name }}"
server_type: "{{ item.server_type }}"
ssh_keys:
- "{{ ssh_key_name }}"
image: "{{ item.image }}"
location: "{{ item.location | default(omit) }}"
datacenter: "{{ item.datacenter | default(omit) }}"
user_data: "{{ item.user_data | default(omit) }}"
api_token: "{{ lookup('env', 'HCLOUD_TOKEN') }}"
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: hetzner_jobs
until: hetzner_jobs.finished
retries: 300
loop: "{{ server.results }}"
- name: Create volume(s)
hcloud_volume:
name: "{{ item.name }}"
server: "{{ item.name }}"
location: "{{ item.location | default(omit) }}"
size: "{{ item.volume_size | default(10) }}"
api_token: "{{ lookup('env', 'HCLOUD_TOKEN') }}"
state: "present"
loop: "{{ molecule_yml.platforms }}"
when: item.volume | default(False) | bool
register: volumes
async: 7200
poll: 0
- name: Wait for volume(s) creation to complete
async_status:
jid: "{{ item.ansible_job_id }}"
register: hetzner_volumes
until: hetzner_volumes.finished
retries: 300
when: volumes.changed
loop: "{{ volumes.results }}"
# Mandatory configuration for Molecule to function.
- name: Populate instance config dict
set_fact:
instance_conf_dict:
{
"instance": "{{ item.hcloud_server.name }}",
"ssh_key_name": "{{ ssh_key_name }}",
"address": "{{ item.hcloud_server.ipv4_address }}",
"user": "{{ ssh_user }}",
"port": "{{ ssh_port }}",
"identity_file": "{{ ssh_path }}",
"volume": "{{ item.item.item.volume | default(False) | bool }}",
}
loop: "{{ hetzner_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: |
# Molecule managed
{{ instance_conf | to_nice_yaml(indent=2) }}
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
loop: "{{ lookup('file', molecule_instance_config) | from_yaml }}"
- name: Wait for VM to settle down
pause:
seconds: 30

View File

@ -1,78 +0,0 @@
---
- name: Destroy
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ molecule_no_log }}"
tasks:
- name: Check existing instance config file
stat:
path: "{{ molecule_instance_config }}"
register: cfg
- name: Populate the instance config
set_fact:
instance_conf: "{{ (lookup('file', molecule_instance_config) | from_yaml) if cfg.stat.exists else [] }}"
- name: Destroy molecule instance(s)
hcloud_server:
name: "{{ item.instance }}"
api_token: "{{ lookup('env', 'HCLOUD_TOKEN') }}"
state: absent
register: server
loop: "{{ instance_conf }}"
async: 7200
poll: 0
- name: Wait for instance(s) deletion to complete
async_status:
jid: "{{ item.ansible_job_id }}"
register: hetzner_jobs
until: hetzner_jobs.finished
retries: 300
loop: "{{ server.results }}"
- pause:
seconds: 5
- name: Destroy volume(s)
hcloud_volume:
name: "{{ item.instance }}"
server: "{{ item.instance }}"
api_token: "{{ lookup('env', 'HCLOUD_TOKEN') }}"
state: "absent"
register: volumes
loop: "{{ instance_conf }}"
when: item.volume | default(False) | bool
async: 7200
poll: 0
- name: Wait for volume(s) deletion to complete
async_status:
jid: "{{ item.ansible_job_id }}"
register: hetzner_volumes
until: hetzner_volumes.finished
retries: 300
when: volumes.changed
loop: "{{ volumes.results }}"
- name: Remove registered SSH key
hcloud_ssh_key:
name: "{{ instance_conf[0].ssh_key_name }}"
state: absent
when: (instance_conf | default([])) | length > 0
# Mandatory configuration for Molecule to function.
- name: Populate instance config
set_fact:
instance_conf: {}
- name: Dump instance config
copy:
content: |
# Molecule managed
{{ instance_conf | to_nice_yaml(indent=2) }}
dest: "{{ molecule_instance_config }}"
when: server.changed | bool

View File

@ -1,24 +0,0 @@
---
dependency:
name: galaxy
options:
role-file: molecule/requirements.yml
requirements-file: molecule/requirements.yml
env:
ANSIBLE_GALAXY_DISPLAY_PROGRESS: "false"
driver:
name: delegated
platforms:
- name: centos7-droneci-autoscaler
image: centos-7
server_type: cx11
lint: |
/usr/local/bin/flake8
provisioner:
name: ansible
env:
ANSIBLE_FILTER_PLUGINS: ${ANSIBLE_FILTER_PLUGINS:-./plugins/filter}
ANSIBLE_LIBRARY: ${ANSIBLE_LIBRARY:-./library}
log: False
verifier:
name: testinfra

View File

@ -1,15 +0,0 @@
---
- name: Prepare
hosts: all
gather_facts: false
tasks:
- name: Bootstrap python for Ansible
raw: |
command -v python3 python || (
(test -e /usr/bin/dnf && sudo dnf install -y python3) ||
(test -e /usr/bin/apt && (apt -y update && apt install -y python-minimal)) ||
(test -e /usr/bin/yum && sudo yum -y -qq install python3) ||
echo "Warning: Python not boostrapped due to unknown platform."
)
become: true
changed_when: false

View File

@ -1,12 +0,0 @@
import os
import testinfra.utils.ansible_runner
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_scaler_amd64/docker-compose.yml')
assert f.exists

View File

@ -1 +0,0 @@
centos7

View File

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

View File

@ -1,11 +0,0 @@
---
collections:
- name: https://gitea.rknet.org/ansible/xoxys.general/releases/download/v2.1.1/xoxys-general-2.1.1.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: main

View File

@ -1,12 +0,0 @@
[flake8]
ignore = D100, 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*
[yapf]
based_on_style = google
column_limit = 99
dedent_closing_brackets = true
coalesce_brackets = true
split_before_logical_operator = true

View File

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

View File

@ -1,57 +0,0 @@
---
- 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.sshkey | default(droneci_autoscaler_sshkey)) | default('') }}"
- 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: "{{ __droneci_autoscaler_sshkey }}"
dest: "{{ __droneci_autoscaler_workdir }}/ssh_key"
mode: 0600
when: __droneci_autoscaler_sshkey | length > 0
no_log: True
- name: Generate SSH key pair
openssh_keypair:
path: "{{ __droneci_autoscaler_workdir }}/ssh_key"
type: ed25519
force: False
state: present
when: not __droneci_autoscaler_sshkey | length > 0
- name: Write userdata
template:
src: services/userdata.yml.j2
dest: "{{ __droneci_autoscaler_workdir }}/userdata.yml"
mode: 0640
notify: __droneci_autoscaler_restart
- 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

@ -1,105 +0,0 @@
#jinja2:lstrip_blocks: True
{{ ansible_managed | comment }}
version: "2.4"
services:
droneci_autoscaler_{{ inst.name }}:
container_name: {{ inst.name }}
image: {{ droneci_autoscaler_image }}
restart: {{ droneci_autoscaler_restart_policy }}
{% if inst.exposed_ports | default(droneci_autoscaler_exposed_ports) | length > 0 %}
ports:
{% for port in inst.exposed_ports | default(droneci_autoscaler_exposed_ports) %}
- {{ port | quote }}
{% endfor %}
{% endif %}
volumes:
- "{{ __droneci_autoscaler_workdir }}/userdata.yml:/etc/scaler/userdata.yml:Z"
- "{{ __droneci_autoscaler_workdir }}/ssh_key:/root/.ssh/id_rsa:ro,Z"
{% 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.agent_environ | default(droneci_autoscaler_agent_environ) | default(False) %}
- DRONE_AGENT_ENVIRON={{ inst.agent_environ | default(droneci_autoscaler_agent_environ) | join(",") }}
{% endif %}
{% if inst.api_host is defined %}
- DRONE_HTTP_HOST={{ inst.api_host }}
{% 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={{ inst.runner_privileged | default(droneci_autoscaler_runner_privileged) | join(",") }}
{% if inst.runner_env_file | default(droneci_autoscaler_runner_env_file) is defined %}
- DRONE_RUNNER_ENVFILE={{ inst.runner_env_file | default(droneci_autoscaler_runner_env_file) }}
{% endif %}
- 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 }}/{{ inst.db_name | default(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_volumes | default([]) | rejectattr("bind") | list | length > 0 %}
volumes:
{% for volume in droneci_autoscaler_volumes | rejectattr("bind") %}
{{ volume.name }}:
{% endfor %}
{% endif %}
{% if droneci_autoscaler_networks | default([]) | length > 0 %}
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

@ -1,91 +0,0 @@
#jinja2: lstrip_blocks: True
#cloud-config
package_update: true
package_upgrade: {{ droneci_autoscaler_agent_package_upgrade | bool | lower }}
package_reboot_if_required: false
{% 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/{{ inst.agent_distro | default(droneci_autoscaler_agent_distro) }} $RELEASE stable
keyid: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88
packages:
{% for package in inst.agent_packages | default(droneci_autoscaler_agent_packages) %}
- {{ package }}
{% endfor %}
- 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",
"dns": {{ droneci_autoscaler_agent_dns | to_json }}
}
{% if inst.docker_auth_config | default(droneci_autoscaler_docker_auth_config) is defined %}
- path: /root/.docker/config.json
content: |
{{ inst.docker_auth_config | default(droneci_autoscaler_docker_auth_config) | to_nice_json(indent=2) | indent(width=6) }}
{% endif %}
- path: /etc/drone.conf
content: |
{% if inst.docker_auth_config | default(droneci_autoscaler_docker_auth_config) is defined %}
PLUGIN_CONFIG={{ inst.docker_auth_config | default(droneci_autoscaler_docker_auth_config) | to_nice_json(indent=2) | regex_replace("\s+", " ") }}
{% endif %}
- 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 %}
{% if droneci_autoscaler_agent_dns | length > 0 %}
- path: /etc/systemd/resolved.conf
content: |
[Resolve]
DNS={{ droneci_autoscaler_agent_dns | join(" ") }}
{% endif %}
{% if droneci_autoscaler_agent_runcmd | length > 0 %}
runcmd:
{% for cmd in droneci_autoscaler_agent_runcmd %}
- {{ cmd }}
{% endfor %}
{% endif %}