Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to make the yaml-file more generic #63

Merged
merged 3 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ publish:

development:
@podman-compose -f development/podman-compose.yml down
podman-compose -f development/podman-compose.yml up
podman-compose -f development/podman-compose.yml up -d
62 changes: 40 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ managed by Red Hat Insights.
- [General workflow of the worker](#general-workflow-of-the-worker)
- [Getting started with local development](#getting-started-with-local-development)
- [Publish first message](#publish-first-message)
- [Bash script example](#bash-script-example)
- [Worker playbooks](#worker-playbooks)
- [Custom playbook](#custom-playbook)
- [Convert2RHEL Playbook](#convert2rhel-playbook)
- [FAQ](#faq)
- [Are there special environment variables used by `rhc-worker-bash`?](#are-there-special-environment-variables-used-by-rhc-worker-bash)
- [Can I change behavior of `rhc-worker-bash`?](#can-i-change-behavior-of-rhc-worker-bash)
Expand All @@ -23,10 +25,11 @@ managed by Red Hat Insights.
Everything starts when message is sent to rhcd. Worker then:

1. Picks up the message from rhcd
2. Downloads the bash script as temporary file (see [Bash script example](#bash-script-example))
3. Executes the script
4. Reads stdout of the script
5. Sends the stdout wrapped in JSON back to rhcd
2. Downloads the worker playbook as temporary file (see [Worker playbooks](#worker-playbooks))
3. Verify the integrity of the playbook with `insights-client`
4. Executes the script
5. Reads stdout of the script
6. Sends the stdout wrapped in JSON back to rhcd

Then rhcd sends the message to upload service (with data from worker) in order to show the results in Insights UI - our setup for local development simulates the upload with minio storage.

Expand All @@ -37,12 +40,18 @@ Almost everything that is needed for local development is placed in `development
Overview of what is needed:

- Script to be executed and data host serving our script
- Example is present inside the folder `development/nginx`
- **Set it up yourself** - see [Bash script example](#bash-script-example) below
- Example is present inside the folder `development/nginx/data`
- **Set it up yourself** - see [Worker playbooks](#worker-playbooks) below
- System connected via rhc with running rhcd == the system on which the script will be executed
- **Set it up yourself** - for vagrant box see commands below

```bash
# Get a new centos-7 box
vagrant init eurolinux-vagrant/centos-7

# Install insights-client and rhc
...

# Connect via rhc
vagrant ssh -- -t 'rhc connect --server=$(RHSM_SERVER_URL) --username=$(RHSM_USERNAME) --password=$(RHSM_PASSWORD)'
# Run rhcd
Expand Down Expand Up @@ -72,25 +81,34 @@ vagrant ssh -- -t 'rhcd --log-level trace \
4. You should see logs in rhcd and file with stdout of your script uploaded to the minio storage
- Go to <http://localhost:9990/login> and use credentials from `.env` file

### Bash script example
### Worker playbooks

There is an [example playbook](
https://github.com/oamg/rhc-worker-bash/blob/main/development/nginx/data/example.yaml)
available under `development/nginx/data`, with a minimal bash script to use
during the worker execution.

If there's a need to test any other playbook provided in this repository, one
must change what playbook will be used during the message consumption in the
[mqtt_publish.py](https://github.com/oamg/rhc-worker-bash/blob/main/development/python/mqtt_publish.py#L22)
file with the name that corresponds the ones present in `development/nginx/data`. Currently, the ones available are:

1. [example.yaml](https://github.com/oamg/rhc-worker-bash/blob/main/development/nginx/data/example.yaml)
2. [convert2rhel.yaml](https://github.com/oamg/rhc-worker-bash/blob/main/development/nginx/data/convert2rhel.yaml)
andywaltlova marked this conversation as resolved.
Show resolved Hide resolved

#### Custom playbook

Create or update a yaml file inside the folder `development/nginx/data/*`.
Correct structure with exampe bash script can be seen below:

```yml
vars:
_insights_signature: |
ascii_armored gpg signature
_insights_signature_exclude: "/vars/insights_signature,/vars/content_vars"
content: |
#!/bin/sh
/usr/bin/convert2rhel --help
content_vars:
# variables that will be handed to the script as environment vars
# will be prefixed with RHC_WORKER_*
FOO: bar
BAR: foo
```
#### Convert2RHEL Playbook

A specialized [Convert2RHEL](https://github.com/oamg/convert2rhel) playbook can be found under the `development/nginx/data` as well. The playbook will take of the following functions:

1. Setup Convert2RHEL (Download certificates, repositories and etc...)
2. Set a couple of environment variables for the Convert2RHEl execution (Based on the `content_vars` defined in the playbook)
3. Run convert2rhel with default commands
4. A function to run any post-execution commands needed by the conversion (Currently empty.)

## FAQ

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ vars:
_insights_signature_exclude: "/vars/insights_signature,/vars/content_vars"
content: |
#!/bin/sh
data='{"alert": false, "summary": "convert2rhel did not detect issues", "report": "", "report_json": {"foo": "bar"}}'
/usr/bin/convert2rhel --help
/usr/bin/convert2rhel --version
echo "BEGIN MARKER"
echo "$data"
echo "END MARKER"
echo "Hello, world!"
andywaltlova marked this conversation as resolved.
Show resolved Hide resolved
content_vars:
# variables that will be handed to the script as environment vars
# will be prefixed with RHC_WORKER_*
Expand Down
5 changes: 2 additions & 3 deletions development/python/mqtt_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@
import paho.mqtt.client as mqtt

def get_ip_address():
host_ip = ""
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
host_ip = s.getsockname()[0]
s.close()
return host_ip

# This is changed everytime you refresh the box and register the machine again.
CLIENT_ID = "973afbce-19b4-4862-9d7a-6e9d8c410674"
CLIENT_ID = "26468815-8407-4058-bcc8-6bcb4eae51c1"
BROKER = '127.0.0.1'
BROKER_PORT = 1883
TOPIC = f"yggdrasil/{CLIENT_ID}/data/in"

# NOTE: currently can be whatever you placed inside devleopment/nginx/data folder
SERVED_FILENAME = "yaml-file"
SERVED_FILENAME = "example.yml"

MESSAGE = {
"type": "data",
Expand Down
1 change: 0 additions & 1 deletion src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func main() {
}

log.Infoln("Listening to messages...", yggdDispatchSocketAddr)

// Register as a Worker service with gRPC and start accepting connections.
s := grpc.NewServer()
pb.RegisterWorkerServer(s, &jobServer{})
Expand Down
Loading