-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 57046f7
Showing
10 changed files
with
227 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<!-- @format --> | ||
|
||
<p><img src="https://code.benco.io/icon-collection/logos/ansible.svg" alt="ansible logo" title="ansible" align="left" height="60" /></p> | ||
|
||
# Ansible Role 🔗 Base-Service | ||
|
||
Configure and operate a base service: running anything from cypto blockchain clients to the vast list of cloud-native services | ||
|
||
## Requirements | ||
|
||
[Docker SDK](https://docker-py.readthedocs.io/en/stable/) for Python (for Python 2.6 support, use the deprecated `docker-py` library instead) or installation of the `docker` engine. | ||
|
||
## Role Variables | ||
|
||
| var | description | default | | ||
| :-------------: | :--------------------------------------------------------: | :--------------: | | ||
| _setupMode_ | infrastructure provisioning setup mode | `container` | | ||
| _name_ | name of service to deploy | `required` | | ||
| _image_ | service container image to deploy | `required` | | ||
| _config_ | configuration files associated with the service to mount | `{}` | | ||
| _configEnv_ | environment variables to set within the service runtime | `{}` | | ||
| _ports_ | listening port information for a service | `{}` | | ||
| _hostDataDir_ | host directory to store node runtime/operational data | `/var/tmp` | | ||
| _dataDir_ | container directory to store node runtime/operational data | `/tmp` | | ||
| _workDir_ | operational directory to store runtime artifacts | `/var/tmp` | | ||
| _restartPolicy_ | container restart policy | `unless-stopped` | | ||
| _cpus_ | available CPU resources each deployed component can use | `1.0` | | ||
| _memory_ | available memory resources each deployed component can use | `4g` | | ||
| _uninstall_ | whether to remove installed components and artifacts | `false` | | ||
|
||
## Dependencies | ||
|
||
``` | ||
collections: | ||
- name: community.docker | ||
``` | ||
|
||
## Example Playbook | ||
|
||
``` | ||
- hosts: servers | ||
roles: | ||
``` | ||
|
||
- Launch a container that sleeps for infinity: | ||
|
||
``` | ||
- role: o1labs.cloud.base-service | ||
vars: | ||
name: sleepy-service | ||
image: busybox:latest | ||
command: ["sleep", "infinity"] | ||
``` | ||
|
||
## License | ||
|
||
MIT | ||
|
||
## Author Information | ||
|
||
This Ansible role was created in 2023 by O1.IO. | ||
|
||
🏆 **always happy to help & donations are always welcome** 💸 | ||
|
||
- **ETH (Ethereum):** 0x652eD9d222eeA1Ad843efec01E60C29bF2CF6E4c | ||
|
||
- **BTC (Bitcoin):** 3E8gMxwEnfAAWbvjoPVqSz6DvPfwQ1q8Jn | ||
|
||
- **ATOM (Cosmos):** cosmos19vmcf5t68w6ug45mrwjyauh4ey99u9htrgqv09 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
setup_mode: container | ||
name: default-example | ||
image: busbox:latest | ||
command: "" | ||
ports: | ||
example-port1: | ||
ingressPort: 80 | ||
servicePort: 2411 | ||
example-port2: | ||
ingressPort: 443 | ||
servicePort: 2412 | ||
|
||
config: | ||
example-config1: | ||
destinationPath: /config/example-1.yaml | ||
data: | | ||
a: 1 | ||
b: 2 | ||
c: | ||
d: 3 | ||
example-config2: | ||
destintionPath: /config/example-2.toml | ||
data: | | ||
[a] | ||
b=1 | ||
[c] | ||
d=2 | ||
configEnv: {} | ||
|
||
resources: | ||
cpuLimit: 1 | ||
memRequest: 1Gi | ||
memLimit: 1Gi | ||
|
||
restart_policy: unless-stopped | ||
uninstall: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
- name: Uninstall service container | ||
community.docker.docker_container: | ||
name: "{{ name }}" | ||
state: absent | ||
purge_networks: yes | ||
listen: Container uninstall | ||
|
||
- name: Remove generated service config files | ||
become: true | ||
ansible.builtin.file: | ||
path: "{{ workDir }}/{{ item.destinationPath | basename }}" | ||
state: absent | ||
with_dict: "{{ config }}" | ||
listen: Container uninstall | ||
|
||
- name: Remove service data directory | ||
become: true | ||
ansible.builtin.file: | ||
path: "{{ hostDataDir }}" | ||
state: absent | ||
listen: Container uninstall |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# @format | ||
--- | ||
galaxy_info: | ||
author: O1 Labs | ||
role_name: base-service | ||
description: Ansible role for running any software process/service | ||
company: "O1.IO" | ||
license: MIT | ||
min_ansible_version: 2.5 | ||
platforms: | ||
- name: Debian | ||
versions: | ||
- jessie | ||
- stretch | ||
- name: Ubuntu | ||
versions: | ||
- xenial | ||
- bionic | ||
- cosmic | ||
galaxy_tags: | ||
- cloud | ||
- base | ||
- service | ||
- template |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
- name: Ensure existence of host data dir | ||
become: true | ||
file: | ||
path: "{{ hostDataDir }}" | ||
state: directory | ||
owner: "{{ ansible_user }}" | ||
group: "{{ ansible_user }}" | ||
mode: 0777 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
- name: Uninstall provisioned container components | ||
when: uninstall|bool == true | ||
block: | ||
- name: Broadcast uninstall signal | ||
command: /bin/true | ||
notify: Container uninstall | ||
always: | ||
- name: End play following uninstallation | ||
meta: end_play | ||
|
||
- name: Ensure existence of operations/work dir | ||
become: true | ||
file: | ||
path: "{{ workDir }}" | ||
state: directory | ||
mode: 0777 | ||
|
||
- name: Generate local rendering of service config files | ||
copy: | ||
content: "{{ item.value.data }}" | ||
dest: "{{ item.value.destinationPath }}" | ||
with_dict: "{{ config }}" | ||
|
||
- set_fact: | ||
volumeList: |- | ||
[ | ||
{% for conf in config %} | ||
"{{ workDir }}/{{ conf[destinationPath] | basename}}:{{ conf[destinationPath] }}", | ||
{% endfor %} | ||
] | ||
portList: |- | ||
[ | ||
{% for port in ports %} | ||
"{{ port[ingressPort] }}:{{ port[servicePort] }}", | ||
{% endfor %} | ||
] | ||
- name: Start service container | ||
community.docker.docker_container: | ||
name: "{{ name }}" | ||
image: "{{ image }}" | ||
command: "{{ command }}" | ||
env: "{{ configEnv }}" | ||
published_ports: "{{ portList }}" | ||
volumes: "{{ volumeList }}" | ||
cpus: "{{ resources.cpuLimit }}" | ||
memory: "{{ resources.memLimit }}" | ||
restart_policy: "{{ restartPolicy }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
- name: Manage storage/data setup | ||
include_tasks: "common/storage-setup.yml" | ||
|
||
- name: Setup service infrastructure topology | ||
include_tasks: "{{ setupMode }}/setup.yml" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
localhost | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# @format | ||
--- | ||
- hosts: localhost | ||
remote_user: root | ||
roles: | ||
- base-service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
# vars file for base-service |