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

feat: Initial Action #2

Merged
merged 65 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
83f3420
wip
jsirianni Jan 22, 2024
2364c0f
fix matrix
jsirianni Jan 22, 2024
5438ff1
install cli
jsirianni Jan 22, 2024
c438e12
pull image
jsirianni Jan 22, 2024
d6a80d3
run bindplane in background
jsirianni Jan 22, 2024
4d94905
arg syntax
jsirianni Jan 22, 2024
f3c5971
fix action name and uses field
jsirianni Jan 22, 2024
5263a6e
switch to docker
jsirianni Jan 22, 2024
5009f84
cURL
jsirianni Jan 22, 2024
a1b7617
put bindplane binary in path
jsirianni Jan 22, 2024
74bfe20
fix args and add shellcheck to ci
jsirianni Jan 22, 2024
79f74e1
remove missing function call
jsirianni Jan 22, 2024
bc582cd
Add debug resource get
jsirianni Jan 22, 2024
7ce99fd
fix paths
jsirianni Jan 22, 2024
5499a90
remove dir support
jsirianni Jan 22, 2024
baa2db7
fix resources for tests
jsirianni Jan 22, 2024
72071cc
wait for bindplane to become ready
jsirianni Jan 22, 2024
60f48ed
try setting bindplane host
jsirianni Jan 22, 2024
9135e20
detect runner ip
jsirianni Jan 22, 2024
e0db5ac
detect internal ip
jsirianni Jan 22, 2024
d9f9f81
debug
jsirianni Jan 22, 2024
9d59f6b
use first addr
jsirianni Jan 22, 2024
c3a45f3
exec into container
jsirianni Jan 22, 2024
34311b8
test additional version
jsirianni Jan 22, 2024
00e4c3f
try write back without commit
jsirianni Jan 22, 2024
8366507
test write back
jsirianni Jan 22, 2024
7bede5c
ci
jsirianni Jan 22, 2024
fbbcc9d
test write back
jsirianni Jan 22, 2024
497c7de
test write back
jsirianni Jan 22, 2024
6907d65
test write back
jsirianni Jan 22, 2024
4044089
try write back
jsirianni Jan 22, 2024
0e13d4b
add github auth
jsirianni Jan 22, 2024
de9b4a2
BindPlane OP Action: Update OTEL Configs
Jan 22, 2024
237fe44
clone repo
jsirianni Jan 22, 2024
d23dbd0
try again
jsirianni Jan 22, 2024
45a79d4
latest
jsirianni Jan 22, 2024
a470a35
BindPlane OP Action: Update OTEL Configs
Jan 22, 2024
3170b22
shellcheck
jsirianni Jan 22, 2024
51b1fce
prevent out of order commits
jsirianni Jan 22, 2024
0b30f5c
BindPlane OP Action: Update OTEL Configs
Jan 22, 2024
a6fb59a
shellcheck
jsirianni Jan 22, 2024
0c39ec2
return early if nothing to commit
jsirianni Jan 22, 2024
a62cc35
fix out path
jsirianni Jan 22, 2024
b2d7566
clone repo outside of orig context
jsirianni Jan 22, 2024
1faa264
BindPlane OP Action: Update OTEL Configs
Jan 22, 2024
f4b0905
BindPlane OP Action: Update OTEL Configs
Jan 22, 2024
3a1b309
comment
jsirianni Jan 22, 2024
05712c9
always run
jsirianni Jan 22, 2024
ff16905
fix workflow example
jsirianni Jan 22, 2024
0f84df2
fix rm
jsirianni Jan 22, 2024
7c53c33
skip apply if not on target branch
jsirianni Jan 22, 2024
3a8a47e
update org
jsirianni Jan 22, 2024
0be28d3
rename params
jsirianni Jan 23, 2024
88f9324
fix bad rename
jsirianni Jan 23, 2024
1c7ab46
enable bool for write back. Move branch check outside of write back b…
jsirianni Jan 23, 2024
82f2f2e
some cleanup
jsirianni Jan 23, 2024
ceb9597
readme
jsirianni Jan 23, 2024
a25a5eb
badge
jsirianni Jan 23, 2024
a2c93e8
readme job name
jsirianni Jan 23, 2024
5a051b9
grab pending version
jsirianni Jan 23, 2024
2c3e0c5
add logging useful for debugging running action
jsirianni Jan 24, 2024
b91574a
remove unused files
jsirianni Jan 24, 2024
c6e5515
use latest instead of pending
jsirianni Jan 26, 2024
beb2524
cleanup zip output
jsirianni Jan 26, 2024
39340e7
feat: Auto rollout (#4)
jsirianni Jan 29, 2024
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
116 changes: 116 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: CI
on:
pull_request:
push:
branches:
- main
- dev

permissions:
# Allow action to write raw configs back to the repository.
contents: write

# Run commits in order to prevent out of order write back commits.
concurrency:
group: ${{ github.head_ref || github.ref_name }}
cancel-in-progress: false

jobs:
shellcheck:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install ShellCheck
run: sudo apt-get install shellcheck

- name: Run ShellCheck
run: shellcheck -x -s bash entrypoint.sh

test:
runs-on: ubuntu-latest
strategy:
matrix:
# This matrix allows us to test multiple bindplane versions.
# When writing back to the repo, we write to directories based
# on the bindplane version.
bindplane_versions:
- 1.40.0
- 1.37.0
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Detect Runner IP
run: echo "MAIN_IP=$(ip addr show | grep 'inet ' | grep -v '127.0.0.1' | awk '{print $2}' | cut -f1 -d'/' | head -n 1)" >> $GITHUB_ENV

- name: Print Runner IP
run: echo $MAIN_IP

- name: Pull BindPlane
run: docker pull ghcr.io/observiq/bindplane-ee:${{ matrix.bindplane_versions }}

- name: Start BindPlane
run: |
docker run \
-d \
--name bindplane \
-e BINDPLANE_USERNAME=admin \
-e BINDPLANE_PASSWORD=admin \
-e BINDPLANE_REMOTE_URL=http://${MAIN_IP}:3001 \
-e BINDPLANE_SESSION_SECRET=2c23c9d3-850f-4062-a5c8-3f9b814ae144 \
-e BINDPLANE_SECRET_KEY=8a5353f7-bbf4-4eea-846d-a6d54296b781 \
-e BINDPLANE_LOG_OUTPUT=stdout \
-e BINDPLANE_ACCEPT_EULA=true \
-p 3001:3001 \
ghcr.io/observiq/bindplane-ee:${{ matrix.bindplane_versions }}

- name: Wait for BindPlane
uses: nick-fields/retry@v2
with:
timeout_minutes: 1
polling_interval_seconds: 5
max_attempts: 10
shell: bash
command: docker exec bindplane /bindplane get agent

- name: Run BindPlane Action
# This should be replaced with a release action.
# <organization>/<repository>@<tag>
uses: ./
with:
# These values are hardcode to match the test instance used by
# this workflow. The instance does not persist. Consumers of
# this action should always use secrets when passing in the remote
# url, bindplane_username, bindplane_password or api key.
#
# Remote url will never be localhost when running this action. The action
# executes in a container and localhost will always be the container's network
# and not the network of the bindplane instance, even if that instance
# is running within this runner.
bindplane_remote_url: http://${{ env.MAIN_IP }}:3001
bindplane_username: admin
bindplane_password: admin
destination_path: test/resources/destinations/resource.yaml
configuration_path: test/resources/configurations/resource.yaml
configuration_output_dir: test/otel/${{ matrix.bindplane_versions }}
target_branch: dev
# Token should have contents: write permissions
token: ${{ secrets.GITHUB_TOKEN }}
enable_otel_config_write_back: true
enable_auto_rollout: true

- name: Get Resources
if: always()
run: |
docker exec bindplane /bindplane get destinations
docker exec bindplane /bindplane get configurations

- name: Debug Container Logs
if: always()
run: docker logs bindplane
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Container image that runs your code
FROM alpine:3.10

RUN apk add --no-cache bash curl git jq

COPY --chmod=0755 entrypoint.sh /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
96 changes: 95 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,95 @@
# bindplane-op-action
[![CI](https://github.com/observIQ/bindplane-op-action/actions/workflows/ci.yml/badge.svg)](https://github.com/observIQ/bindplane-op-action/actions/workflows/ci.yml)

# bindplane-op-action

The BindPlane OP action can be used to deploy configurations to your BindPlane OP
server. It also supports exporting the OpenTelemetry configurations back to the repository.

## Configuration

| Parameter | Default | Description |
| :---------------------------- | :--------- | :------------------------------ |
| bindplane_remote_url | required | The endpoint that will be used to connect to BindPalne OP. |
| bindplane_api_key | | API key used to authenticate to BindPlane. Required when BindPlane multi account is enabled or when running on BindPlane Cloud |
| bindplane_username | | Username used to authenticate to BindPlane. Not required if API key is set. |
| bindplane_password | | Password used to authenticate to BindPlane.
| target_branch | required | The branch that the action will use when applying resources to bindplane or when writing otel configs back to the repo. |
| destination_path | | Path to the file which contains the BindPlane destination resources |
| configuration_path | | Path to the file which contains the BindPlane configuration resources |
| enable_otel_config_write_back | `false` | Whether or not the action should write the raw OpenTelemetry configurations back to the repository. |
| configuration_output_dir | | When write back is enabled, this is the path that will be written to. |
| token | | The Github token that will be used to write to the repo. Usually secrets.GITHUB_TOKEN is sufficient. Requires the `contents.write` permission. |
| enable_auto_rollout | `false` | When enabled, the action will trigger a rollout for any configuration that has been updated. |

## Usage

### Export Resources

To get started, you must handle exporting your existing resources to the repository. Use
the `bindplane get` commands with the `--export` flag.

```bash
bindplane get destination -o yaml --export > destination.yaml
bindplane get configuration -o yaml --export > configuration.yaml
Comment on lines +32 to +33
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the PR instructions it has plural of these file names destinations.yaml and configurations.yaml what do we want? It failed for me as I followed the PR instructions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you got it working. The path you export the initial resources too should match whatever you configure your action to point to, in your repo you have:

          destination_path: destination.yaml
          configuration_path: configuration.yaml

but you could have anything. My example repo has the following structure:

.
├── otel
│   ├── k8s-cluster.yaml
│   ├── k8s-gateway.yaml
│   └── k8s-node.yaml
├── README.md
└── resources
    ├── configurations
    │   └── resource.yaml
    └── destinations
        └── resource.yaml

Where resources/ is the top level directory for my destinations and configurations. The output dir is otel.

```

With the resources exported to the repository, you can move on to configuring the action
using a new workflow.

### Workflow

The following workflow can be used as an example. It uses the same file paths
created in the [Export Resources](#export-resources) section.

This example will write the raw OTEL configurations back to the repository at the
path `otel/`

```yaml
name: bindplane

on:
push:
branches:
- main

# Write back requires access to the repo
permissions:
contents: write

# Run commits in order to prevent out of order write back commits.
concurrency:
group: ${{ github.head_ref || github.ref_name }}
cancel-in-progress: false

jobs:
bindplane:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: observIQ/bindplane-op-action@main
with:
bindplane_remote_url: ${{ secrets.BINDPLANE_REMOTE_URL }}
bindplane_username: ${{ secrets.BINDPLANE_USERNAME }}
bindplane_password: ${{ secrets.BINDPLANE_PASSWORD }}
target_branch: main
destination_path: destination.yaml
configuration_path: configuration.yaml
enable_otel_config_write_back: true
configuration_output_dir: otel/
token: ${{ secrets.GITHUB_TOKEN }}
enable_auto_rollout: true
```

After the action is executed, you can expect to see OTEL configurations
in the `otel/` directory.

```
otel
├── k8s-cluster.yaml
├── k8s-gateway.yaml
└── k8s-node.yaml
```
48 changes: 48 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: 'BindPlane OP Action'
description: 'GitHub Action for BindPlane OP.'
author: 'observIQ'

inputs:
bindplane_remote_url:
description: 'The URL that will be used to connect to BindPlane OP'
required: true
bindplane_api_key:
description: 'The BindPlane OP API key that will be used to authenticate to BindPlane OP'
bindplane_username:
description: 'The BindPlane OP bindplane_username that will be used to authenticate to BindPlane OP'
bindplane_password:
description: 'The BindPlane OP bindplane_password that will be used to authenticate to BindPlane OP'
target_branch:
description: 'Resource apply and OTEL config write back will only happen when this branch is the current branch of the action'
destination_path:
description: 'Path to the file which contains the BindPlane destination resources'
configuration_path:
description: 'Path to the file which contains the BindPlane configuration resources'
enable_otel_config_write_back:
description: 'Enable OTEL raw config write back'
default: false
configuration_output_dir:
description: 'Path to the directory which will contain the rendered OTEL format of the configuration resources'
token:
description: 'The GitHub token used to authenticate to GitHub when writing OTEL configs back to the repo'
enable_auto_rollout:
description: 'When enabled, the action will trigger a rollout for all configurations that have been updated'
default: false

runs:
using: 'docker'
image: 'Dockerfile'
# Arg order must match the order of the arg parsing
# in entrypoint.sh.
args:
- ${{ inputs.bindplane_remote_url }}
- ${{ inputs.bindplane_api_key }}
- ${{ inputs.bindplane_username }}
- ${{ inputs.bindplane_password }}
- ${{ inputs.target_branch }}
- ${{ inputs.destination_path }}
- ${{ inputs.configuration_path }}
- ${{ inputs.enable_otel_config_write_back }}
- ${{ inputs.configuration_output_dir }}
- ${{ inputs.token }}
- ${{ inputs.enable_auto_rollout }}
Loading
Loading