Skip to content

Commit 4278ce5

Browse files
committed
add all resources route, update docs, add cron for creating elements inventory
1 parent 44994d3 commit 4278ce5

15 files changed

Lines changed: 471 additions & 19 deletions

File tree

.github/workflows/inventory.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Build elements inventory
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: '5 * * * 0'
7+
push:
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
Build:
14+
runs-on: self-hosted
15+
strategy:
16+
fail-fast: true
17+
steps:
18+
- uses: actions/checkout@v6
19+
with:
20+
fetch-depth: 30
21+
- name: Build elements inventory
22+
run: python3 genesis_core/cmd/elements_inventory.py

Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
SHELL := bash
2+
REPOSITORY := https://repository.genesis-core.tech
3+
ifeq ($(SSH_KEY),)
4+
SSH_KEY = ~/.ssh/id_rsa.pub
5+
endif
6+
7+
all: help
8+
9+
help:
10+
@echo "build_core - build genesis core"
11+
@echo "bootstrap - bootstrap genesis core"
12+
13+
build_core:
14+
genesis build -i $(SSH_KEY) -f . --inventory --manifest-var repository=https://repository.genesis-core.tech
15+
16+
bootstrap:
17+
genesis bootstrap -i output/inventory.json -f -m core --admin-password admin --cidr 10.20.0.0/22

docs/em/cli.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Examples
2+
3+
## Build element from repository
4+
5+
Build a Genesis element. The command build all images, manifests and other artifacts required for the element. The manifest in the project may be a raw YAML file or a template using Jinja2 templates. For Jinja2 templates, the following variables are
6+
available by default:
7+
8+
- {{ version }}: version of the element
9+
- {{ name }}: name of the element
10+
- {{ images }}: list of images
11+
- {{ manifests }}: list of manifests
12+
13+
Go to project directory and run the following command:
14+
15+
```bash
16+
genesis build <element_name>
17+
```
18+
19+
## Install element from repository
20+
21+
```bash
22+
genesis e install <element_name>
23+
```
File renamed without changes.
File renamed without changes.

docs/index.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ Welcome to Genesis Core!
66

77
The Genesis Core is an open source software that offers a one turnkey solution to deal with infrastructure at all levels - from bare metal and virtual machines to applications and services.
88

9-
Refer to the [wiki](https://github.com/infraguys/genesis_core/wiki) for more detailed information.
10-
119
## 📦 Installation
1210

1311
There are several ways to install Genesis Core and depend on your purpose you can choose one of them.
@@ -19,7 +17,7 @@ This stand may be used for development purposes as well if you are focusing on a
1917

2018
## Basic usage
2119

22-
In a case you would like to run Genesis Core on your own infrastructure, you can use the [basic guide](https://github.com/infraguys/genesis_core/wiki/BasicUsage) for more details.
20+
In a case you would like to run Genesis Core on your own infrastructure, you can use the [basic guide](./usage/basic_usage.md) for more details.
2321

2422
## 🚀 Development
2523

docs/secret/certificates.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Certificates
2+
3+
Certificates are a part for the Secret Manager service. The service allows to issue and manage certificates, store them in specified storage and use them for different purposes.
4+
5+
The current implementation only support `dns_core` method (provider) to issue and manage certificates. This method supposed DNS challenges via Core DNS that is
6+
available from the internet.
7+
8+
Examples:
9+
10+
```bash
11+
curl --location 'http://10.20.0.2:11010/v1/secret/certificates/' \
12+
--header 'Content-Type: application/json' \
13+
--header 'Authorization: Bearer MY_TOKEN' \
14+
--data-raw '{
15+
"name": "my-cert",
16+
"project_id": "00000000-0000-0000-0000-000000000000",
17+
"method": {
18+
"kind": "dns_core"
19+
},
20+
"constructor": {
21+
"kind": "plain"
22+
},
23+
"email": "user@genesis-core.tech",
24+
"domains": ["test0.cdns.genesis-core.tech"]
25+
}'
26+
```
27+
28+
The main fields are:
29+
30+
- **name** - name of the certificate.
31+
- **project_id** - it's a project the certificate belongs.
32+
- **method** - the method (provider) to issue and manage the certificate.
33+
- **constructor** - In the context of the certificates, the constructor object creates and stores the certificate. The `plain` means create and store in the plain format.
34+
- **email** - the email address to use for the certificate.
35+
- **domains** - the list of domains to use for the certificate.
36+
37+
Also it's possible to specify domains with wildcards.
38+
39+
```bash
40+
curl --location 'http://10.20.0.2:11010/v1/secret/certificates/' \
41+
--header 'Content-Type: application/json' \
42+
--header 'Authorization: Bearer MY_TOKEN' \
43+
--data-raw '{
44+
"name": "my-cert",
45+
"project_id": "00000000-0000-0000-0000-000000000000",
46+
"method": {
47+
"kind": "dns_core"
48+
},
49+
"constructor": {
50+
"kind": "plain"
51+
},
52+
"email": "user@genesis-core.tech",
53+
"domains": ["*.test1.cdns.genesis-core.tech", "test1.cdns.genesis-core.tech"]
54+
}'
55+
```
56+
57+
## Methods / Providers
58+
59+
The Genesis Core supports the following methods / providers to issue and manage certificates:
60+
61+
### dns_core
62+
63+
The `dns_core` provider allows to issue and manage certificates via Core DNS. It means Core DNS service should be available from the internet to accept ACME challenges. The main logic to communicate with Let's Encrypt is implemented in the [GCL CertBot plugin](https://github.com/infraguys/gcl_certbot_plugin) look at it for more information but the main steps are:
64+
65+
- Create or get private client key.
66+
- Initiate a client with the key.
67+
- Request a certificate for domains.
68+
- Pass the DNS challenge.
69+
- Some final preparation.

docs/usage/basic_usage.md

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
# Basic usage
2+
3+
This guide describes how to install and use Genesis Core on existing infrastructure. The existing infrastructure can be a local machine or several servers.
4+
It's assumed Linux(Ubuntu) is used as the OS on your machines.
5+
6+
## Requirements
7+
8+
Before you install and use genesis core you need to install several requirements:
9+
10+
### Packages
11+
12+
Install necessary packages:
13+
14+
#### Ubuntu
15+
16+
Install packages
17+
18+
```bash
19+
sudo apt update
20+
sudo apt install qemu-kvm qemu-utils libvirt-daemon-system libvirt-dev mkisofs -y
21+
```
22+
23+
Add user to group
24+
25+
```bash
26+
sudo adduser $USER libvirt
27+
sudo adduser $USER kvm
28+
```
29+
30+
### Libvirt
31+
32+
Create a libvirt storage pool or use `default` if it already exists.
33+
34+
Check pools:
35+
36+
```bash
37+
sudo virsh pool-list --all
38+
```
39+
40+
Create a new pool if no one exists or you would like to use another one.
41+
42+
```bash
43+
sudo virsh pool-define-as default dir --target "/var/lib/libvirt/images/"
44+
sudo virsh pool-build default
45+
sudo virsh pool-start default
46+
sudo virsh pool-autostart default
47+
```
48+
49+
Check the status with virsh-info:
50+
51+
```bash
52+
sudo virsh pool-info default
53+
```
54+
55+
## Installation
56+
57+
The simplest way to install Genesis Core is to get a prebuilt virtual machine image with all necessary dependencies. Take the the [latest image here](http://repository.genesis-core.tech:8081/genesis-core/latest/genesis-core.qcow2).
58+
59+
### Local machine / Development
60+
61+
Install Genesis DevTools first. For more information about it, see [Genesis DevTools](https://github.com/infraguys/genesis_devtools). The devtools allows to build and run the genesis core locally. Since we already downloaded the latest image, we don't need to build it from scratch but if you need to build an image from source look at the [instructions here](https://github.com/infraguys/genesis_devtools?tab=readme-ov-file#build).
62+
63+
The devtools has `bootstrap` command that will start the Genesis Core locally.
64+
65+
```bash
66+
genesis bootstrap -i genesis-core.raw -m core
67+
```
68+
69+
For more information about the `bootstrap` command, see [instructions here](https://github.com/infraguys/genesis_devtools?tab=readme-ov-file#bootstrap).
70+
71+
The installation is ready at address `10.20.0.2` but at this time it's not very useful since it cannot run any workload. Let's add a local machine as a hypervisor to solve this problem.
72+
73+
#### Get admin token
74+
75+
Before we can add a hypervisor, we need to get an admin token. The command to get the token is:
76+
77+
```bash
78+
curl --location 'http://10.20.0.2:11010/v1/iam/clients/00000000-0000-0000-0000-000000000000/actions/get_token/invoke' \
79+
--header 'Content-Type: application/x-www-form-urlencoded' \
80+
--data-urlencode 'grant_type=password' \
81+
--data-urlencode 'username=<YOUR_ADMIN_USERNAME>' \
82+
--data-urlencode 'password=<YOUR_ADMIN_PASSWORD>' \
83+
--data-urlencode 'client_id=GenesisCoreClientId' \
84+
--data-urlencode 'client_secret=GenesisCoreClientSecret' \
85+
--data-urlencode 'scope=' \
86+
--data-urlencode 'ttl=86400'
87+
```
88+
89+
The return value is `json` object with the `access_token` field. Copy the token and use it in the next steps.
90+
91+
#### Add hypervisor
92+
93+
##### Libvirt via SSH (preffered)
94+
95+
Create key in genesis core's VM for root user:
96+
97+
```console
98+
# ssh-keygen
99+
```
100+
101+
Copy public key to hypervisor (recommended user is `ubuntu`)
102+
103+
##### Libvirt via TCP connect
104+
105+
We need to get access to libvirt via a tcp connection. By default the tcp connection is closed, so we need to enable it.
106+
107+
**NOTE:** For development purposes we can use raw tcp connection. Don't use it in production.
108+
109+
Edit libvirt configuration file `/etc/libvirt/libvirtd.conf`, add these lines;
110+
111+
```bash
112+
listen_tcp = 1
113+
listen_addr = "0.0.0.0"
114+
auth_tcp = "none"
115+
```
116+
117+
Run commands to enable libvirt tcp connection:
118+
119+
```bash
120+
sudo systemctl stop libvirtd
121+
sudo systemctl enable --now libvirtd-tcp.socket
122+
sudo systemctl start libvirtd
123+
```
124+
125+
Check the libvirt is listening the tcp socket:
126+
127+
```bash
128+
sudo systemctl status libvirtd.service
129+
sudo systemctl status libvirtd.service | grep "libvirtd-tcp.socket"
130+
```
131+
132+
##### Configure ZFS for storage
133+
134+
It's recommended to create distinct dataset for zvols:
135+
136+
```bash
137+
zpool create rpool ... # create pool itself
138+
zfs create -o volmode=dev rpool/disks
139+
virsh pool-define-as --name rpool --source-name rpool/disks --type zfs
140+
virsh pool-start rpool
141+
virsh pool-autostart rpool
142+
```
143+
144+
##### Config hypervisor in core
145+
146+
Add the machine as a hypervisor, replace `XXXX` with the token from the previous step.:
147+
148+
```bash
149+
curl --location --globoff 'http://10.20.0.2:11010/v1/hypervisors/' \
150+
--header 'Content-Type: application/json' \
151+
--header 'Authorization: Bearer XXXX' \
152+
--data '{
153+
"driver_spec": {
154+
"driver": "libvirt",
155+
"iface_mtu": 1500,
156+
"network_type": "network",
157+
"network": "genesis-core-net",
158+
"storage_pool": "default", // for qcow
159+
"storage_pool": "rpool", // for ZFS
160+
"connection_uri": "qemu+tcp://10.20.0.1/system", // for TCP connect
161+
"connection_uri": "qemu+ssh://ubuntu@10.20.0.1:22/system?no_verify=1", // for SSH connect
162+
"machine_prefix": "dev-"
163+
},
164+
"avail_cores": 4,
165+
"avail_ram": 4096,
166+
"all_cores": 4,
167+
"all_ram": 4096,
168+
"status": "ACTIVE"
169+
}'
170+
```
171+
172+
- storage_pool - name of the libvirt storage pool to use.
173+
- connection_uri - libvirt connection uri. If you need to add another machine use different ip address.
174+
- all_cores - total number of cores you would like to allocate to the hypervisor.
175+
- all_ram - total amount of ram you would like to allocate to the hypervisor.
176+
- avail_cores - use the same value as `all_cores`.
177+
- avail_ram - use the same value as `all_ram`.
178+
179+
### Production
180+
181+
The production installation guide will be added soon.
182+
183+
## Usage
184+
185+
Follow the [usage guide](https://github.com/infraguys/genesis_core/wiki/Usage) for more information.

genesis_core/cmd/bootstrap.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import ipaddress
2020
import logging
2121
import os
22+
import pwd
23+
import grp
2224
import sys
2325
import time
2426
import typing as tp
@@ -45,7 +47,8 @@
4547

4648
LOG = logging.getLogger(__name__)
4749
LOG.setLevel(logging.INFO)
48-
GCTL_CFG_DIR = "/home/ubuntu/.genesis"
50+
USER = "ubuntu"
51+
GCTL_CFG_DIR = f"/home/{USER}/.genesis"
4952
SPEC_PATH = "/mnt/cdrom/spec.json"
5053
MANIFEST_PATH = "/mnt/cdrom/core.yaml"
5154
MAIN_SUBNET_UUID = sys_uuid.UUID("c910a7e1-61ae-4d56-bdd6-a59faa3cbda3")
@@ -242,7 +245,13 @@ def _install_core_manifest(spec: dict[str, tp.Any], core_element_name: str = "co
242245

243246
# Create a configuration file for gctl
244247
os.makedirs(GCTL_CFG_DIR, exist_ok=True)
245-
with open(os.path.join(GCTL_CFG_DIR, "genesisctl.yaml"), "w") as f:
248+
# chown GCTL_CFG_DIR to ubuntu user
249+
uid = pwd.getpwnam(USER).pw_uid
250+
gid = grp.getgrnam(USER).gr_gid
251+
os.chown(GCTL_CFG_DIR, uid, gid)
252+
253+
config_path = os.path.join(GCTL_CFG_DIR, "genesisctl.yaml")
254+
with open(config_path, "w") as f:
246255
yaml.safe_dump(
247256
{
248257
"schema_version": 1,
@@ -263,8 +272,10 @@ def _install_core_manifest(spec: dict[str, tp.Any], core_element_name: str = "co
263272
},
264273
f,
265274
)
275+
os.chown(config_path, uid, gid)
266276

267-
os.system(f"genesis --config {GCTL_CFG_DIR}/genesisctl.yaml elements install {manifest_path}")
277+
os.system("genesis autocomplete")
278+
os.system(f"genesis --config {config_path} elements install {manifest_path}")
268279

269280

270281
def _init_secrets(spec: dict[str, tp.Any]):

0 commit comments

Comments
 (0)