Skip to content

Commit

Permalink
Add oblt-cli/cluster-create-custom action (#14)
Browse files Browse the repository at this point in the history
* Add oblt-cli/cluster-create-custom action

* fix

* Convert to outputs

* Add gitops: true test

* fix names

* convert to matrix

* test

* revert matrix

* Remove comment

* Simplify README.md

* test

* Revert "test"

This reverts commit fc1a349.

* Use existing image

* test

* Revert "test"

This reverts commit 851de53.

* Use obltmachine instead of apmmachine

Co-authored-by: Victor Martinez <[email protected]>

* Fix heading

* test

* fix

* fix

* fix

* cleanup

* cleanup

* fix dry-run

* Fix dry-run input

---------

Co-authored-by: Victor Martinez <[email protected]>
  • Loading branch information
reakaleek and v1v authored Jun 3, 2024
1 parent 789ffb1 commit 5ea2f71
Show file tree
Hide file tree
Showing 4 changed files with 230 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/test-oblt-cli-cluster-create-custom-gitops.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: test-oblt-cli-cluster-create-custom-gitops

on:
workflow_dispatch:
inputs:
dry-run:
description: 'Dry run'
required: true
default: false
type: boolean
push:
paths:
- '.github/workflows/test-oblt-cli-cluster-create-custom-gitops.yml'
- 'oblt-cli/cluster-create-custom/**'

permissions:
contents: read
id-token: write

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- if: github.event_name == 'workflow_dispatch' && github.event.inputs.dry-run == 'true'
uses: elastic/oblt-actions/google/auth@v1
- uses: elastic/oblt-actions/git/setup@v1
- uses: ./oblt-cli/cluster-create-custom
with:
github-token: ${{ secrets.OBLT_CLI_GITHUB_TOKEN }}
template: 'deploy-kibana'
cluster-name-prefix: 'testgithubaction'
gitops: true
dry-run: ${{ github.event.inputs.dry-run != '' && github.event.inputs.dry-run || true }}
parameters: '{"RemoteClusterName":"release-oblt","StackVersion":"8.7.0","KibanaDockerImage":"docker.elastic.co/observability-ci/kibana-cloud:8.7.0-SNAPSHOT"}'
35 changes: 35 additions & 0 deletions .github/workflows/test-oblt-cli-cluster-create-custom.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: test-oblt-cli-cluster-create-custom

on:
workflow_dispatch:
inputs:
dry-run:
description: 'Dry run'
required: true
default: false
type: boolean
push:
paths:
- '.github/workflows/test-oblt-cli-cluster-create-custom.yml'
- 'oblt-cli/cluster-create-custom/**'

permissions:
contents: read
id-token: write

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- if: github.event_name == 'workflow_dispatch' && github.event.inputs.dry-run == 'true'
uses: elastic/oblt-actions/google/auth@v1
- uses: elastic/oblt-actions/git/setup@v1
- uses: ./oblt-cli/cluster-create-custom
with:
github-token: ${{ secrets.OBLT_CLI_GITHUB_TOKEN }}
template: 'deploy-kibana'
cluster-name-prefix: 'testgithubaction'
gitops: false
dry-run: ${{ github.event.inputs.dry-run != '' && github.event.inputs.dry-run || true }}
parameters: '{"RemoteClusterName":"release-oblt","StackVersion":"8.7.0","KibanaDockerImage":"docker.elastic.co/observability-ci/kibana-cloud:8.7.0-SNAPSHOT"}'
43 changes: 43 additions & 0 deletions oblt-cli/cluster-create-custom/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# oblt-cli/cluster-create-custom

GitHub Action to run the oblt-cli wrapper to create a custom cluster

## Inputs

Following inputs can be used as `step.with` keys

| Name | Description | Required | Default |
|-----------------------|----------------------------------------------------------------------|----------|--------------------|
| `template` | The Oblt cluster to use. | `true` | - |
| `parameters` | Parameters values defined in JSON | `true` | - |
| `github-token` | The GitHub token with permissions fetch releases. | `true` | - |
| `cluster-name-prefix` | Prefix to be prepended to the randomised cluster name | `false` | - |
| `cluster-name-suffix` | Suffix to be appended to the randomised cluster name | `false` | - |
| `skip-random-name` | Whether to skip the randomised cluster name | `false` | `false` |
| `dry-run` | Whether to dry-run the oblt-cli. | `false` | `false` |
| `slack-channel` | The slack channel to be configured in the oblt-cli. | `false` | `#observablt-bots` |
| `username` | Username to show in the deployments with oblt-cli, format: [a-z0-9]. | `false` | `obltmachine` |
| `gitops` | Whether to provide the GitOps metadata to the oblt-cli. | `false` | `false` |

## Usage

```yaml
---
name: Create custom cluster using the oblt-cli
on:
issues:
types: [opened]
jobs:
run-oblt-cli:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: elastic/oblt-actions/google/auth@v1
- uses: elastic/oblt-actions/git/setup@v1
- uses: elastic/oblt-actions/oblt-cli/cluster-create-custom@v1
with:
template: 'deploy-kibana'
cluster-name-prefix: 'foo'
parameters: '{"RemoteClusterName":"release-oblt","StackVersion":"8.7.0","ElasticsearchDockerImage":"docker.elastic.co/observability-ci/elasticsearch-cloud-ess:8.7.0-046d305b","KibanaDockerImage":"docker.elastic.co/observability-ci/kibana-cloud:8.7.0-SNAPSHOT-87"}'
token: ${{ secrets.PAT_TOKEN }}
```
117 changes: 117 additions & 0 deletions oblt-cli/cluster-create-custom/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: 'Oblt-cli create custom'
description: 'Run the oblt-cli wrapper to create a custom cluster.'
inputs:
template:
description: 'The Oblt cluster template to use'
required: true
parameters:
description: 'The Oblt cluster parameters to use in JSON format.'
required: true
default: '{}'
github-token:
description: 'The GitHub access token.'
required: true
cluster-name-prefix:
description: 'Prefix to be prepended to the randomised cluster name'
required: false
cluster-name-suffix:
description: 'Suffix to be appended to the randomised cluster name'
required: false
slack-channel:
description: 'The slack channel to notify the status.'
default: '#observablt-bots'
required: false
username:
description: 'Username to show in the deployments with oblt-cli, format: [a-z0-9]'
default: 'obltmachine'
required: false
gitops:
description: 'Whether to provide the GitOps metadata to the oblt-cli'
default: false
required: false
dry-run:
description: 'Whether to dryRun'
default: false
required: false
skip-random-name:
description: 'Whether to deploy a cluster with a random name'
default: false
required: false
runs:
using: "composite"
steps:
- name: Configure oblt-cli flags
id: flags
uses: actions/github-script@v7
env:
template: ${{ inputs.template }}
cluster_name_prefix: ${{ inputs.cluster-name-prefix }}
cluster_name_suffix: ${{ inputs.cluster-name-suffix }}
dry_run: ${{ inputs.dry-run }}
gitops: ${{ inputs.gitops }}
input_parameters: ${{ inputs.parameters }}
skip_random_name: ${{ inputs.skip-random-name }}
with:
script: |
const {
template,
cluster_name_prefix,
cluster_name_suffix,
dry_run,
gitops,
input_parameters,
skip_random_name,
} = process.env
let parameters = {}
if (gitops === 'true') {
parameters.GitOps = 'true'
parameters.GitHubRepository = `${context.repo.owner}/${context.repo.repo}`
if (context.eventName === 'issues' && context.issue.number) {
parameters.GitHubIssue = context.issue.number
} else {
parameters.GitHubPullRequest = context.issue.number
}
}
parameters.EphemeralCluster = 'true'
parameters = { ...parameters, ...JSON.parse(input_parameters) }
core.setOutput('PARAMETERS', `--parameters='${JSON.stringify(parameters)}'`)
if (template) {
core.setOutput('TEMPLATE', `--template=${template}`)
}
if (cluster_name_prefix) {
core.setOutput('CLUSTER_NAME_PREFIX', `--cluster-name-prefix=${cluster_name_prefix}`)
}
if (cluster_name_suffix) {
core.setOutput('CLUSTER_NAME_SUFFIX', `--cluster-name-suffix=${cluster_name_suffix}`)
}
if (dry_run !== 'false') {
core.setOutput('DRY_RUN', '--dry-run')
}
if (skip_random_name === 'true') {
core.setOutput('SKIP_RANDOM_NAME', '--skip-random-name')
}
- uses: elastic/oblt-actions/oblt-cli/[email protected]
with:
github-token: ${{ inputs.github-token }}
slack-channel: ${{ inputs.slack-channel }}
username: ${{ inputs.username }}

- run: |
oblt-cli cluster create custom \
${{ steps.flags.outputs.TEMPLATE }} \
${{ steps.flags.outputs.DRY_RUN }} \
${{ steps.flags.outputs.CLUSTER_NAME_PREFIX }} \
${{ steps.flags.outputs.CLUSTER_NAME_SUFFIX }} \
${{ steps.flags.outputs.PARAMETERS }} \
${{ steps.flags.outputs.SKIP_RANDOM_NAME }}
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.github-token }}

0 comments on commit 5ea2f71

Please sign in to comment.