forked from Reuf12/apm-pipeline-library
-
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.
action: create serverless cluster (#2365)
Co-authored-by: Jan Calanog <jan.calanog@elastic.co>
- Loading branch information
Showing
3 changed files
with
190 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,49 @@ | ||
## About | ||
|
||
GitHub Action to run the oblt-cli wrapper to create a Serverless cluster | ||
|
||
* [Usage](#usage) | ||
* [Configuration](#configuration) | ||
* [Customizing](#customizing) | ||
* [inputs](#inputs) | ||
|
||
## Usage | ||
|
||
### Configuration | ||
|
||
Given the CI GitHub action: | ||
|
||
```yaml | ||
--- | ||
name: Create serverless cluster using the oblt-cli | ||
on: | ||
issues: | ||
types: [opened] | ||
jobs: | ||
create-serverless: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: elastic/apm-pipeline-library/.github/actions/oblt-cli-create-serverless@current | ||
with: | ||
target: 'staging' | ||
cluster-name-prefix: 'foo' | ||
token: ${{ secrets.PAT_TOKEN }} | ||
``` | ||
## Customizing | ||
### inputs | ||
Following inputs can be used as `step.with` keys | ||
|
||
| Name | Type | Default | Description | | ||
|-----------------------------|---------|-----------------------------|------------------------------------| | ||
| `target` | String | `qa` | The target environment where to deploy the serverless cluster. | | ||
| `project-type` | String | `observability` | The project type. | | ||
| `cluster-name-prefix` | String | Optional | Prefix to be prepended to the randomised cluster name | | ||
| `cluster-name-suffix` | String | Optional | Suffix to be appended to the randomised cluster name | | ||
| `dry-run` | Boolean | `false` | Whether to dry-run the oblt-cli. | | ||
| `slackChannel` | String | `#observablt-bots` | The slack channel to be configured in the oblt-cli. | | ||
| `token` | String | Mandatory | The GitHub token with permissions fetch releases. | | ||
| `username` | String | `apmmachine` | Username to show in the deployments with oblt-cli, format: [a-z0-9]. | | ||
| `gitops` | Boolean | `false` | Whether to provide the GitOps metadata to the oblt-cli. | |
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,107 @@ | ||
name: 'Oblt-cli create serverless' | ||
description: 'Run the oblt-cli wrapper to create a serverless cluster.' | ||
inputs: | ||
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 | ||
target: | ||
description: 'The target environment where to deploy the serverless cluster. Default: `qa`' | ||
default: "qa" | ||
required: false | ||
project-type: | ||
description: 'The project type. Default: `observability`' | ||
default: "observability" | ||
required: false | ||
token: | ||
description: 'The GitHub access token.' | ||
required: true | ||
slackChannel: | ||
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: 'apmmachine' | ||
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 | ||
runs: | ||
using: "composite" | ||
steps: | ||
|
||
- name: Configure oblt-cli flags | ||
run: | | ||
{ | ||
[ -n '${{ inputs.cluster-name-prefix }}' ] \ | ||
&& echo -n '--cluster-name-prefix=${{ inputs.cluster-name-prefix }} ' | ||
[ -n '${{ inputs.cluster-name-suffix }}' ] \ | ||
&& echo -n '--cluster-name-suffix=${{ inputs.cluster-name-suffix }} ' | ||
[ '${{ inputs.dry-run }}' == 'true' ] \ | ||
&& echo -n '--dry-run ' | ||
} > .flags | ||
echo "COMMAND=$(cat .flags)" >> $GITHUB_ENV | ||
rm .flags | ||
shell: bash | ||
|
||
- name: Configure oblt-cli flags for gitops - issues | ||
if: ${{ !github.event.issue.pull_request && contains(inputs.gitops, 'true') }} | ||
run: | | ||
{ | ||
echo -n '{' | ||
echo -n '"GitOps":"true",' | ||
echo -n '"GitHubRepository":"${{ github.repository }}"' | ||
[ -n '${{ github.event.issue.number }}' ] && echo -n ',"GitHubIssue":"${{ github.event.issue.number }}"' | ||
echo -n '}' | ||
} > .gitops | ||
echo "GITOPS=$(cat .gitops)" >> $GITHUB_ENV | ||
rm .gitops | ||
shell: bash | ||
|
||
- name: Configure oblt-cli flags for gitops - pull-request | ||
if: github.event.issue.pull_request && contains(inputs.gitops, 'true') | ||
run: | | ||
{ | ||
echo -n '{' | ||
echo -n '"GitOps":"true",' | ||
echo -n '"GitHubRepository":"${{ github.repository }}",' | ||
echo -n '"GitHubCommit":"${{ github.event.comment.id }}",' | ||
echo -n '"GitHubPullRequest":"${{ github.event.issue.number }}"' | ||
echo -n '}' | ||
} > .gitops | ||
echo "GITOPS=$(cat .gitops)" >> $GITHUB_ENV | ||
rm .gitops | ||
shell: bash | ||
|
||
- name: Configure oblt-cli serverless parameters | ||
run: | | ||
{ | ||
echo -n '{' | ||
echo -n '"Target":"${{ inputs.target }}",' | ||
echo -n '"ProjectType":"${{ inputs.project-type }}"' | ||
echo -n '}' | ||
} > .serverless | ||
echo "SERVERLESS=$(cat .serverless)" >> $GITHUB_ENV | ||
rm .serverless | ||
shell: bash | ||
|
||
- name: Configure oblt-cli merge parameters | ||
run: | | ||
PARAMETERS=$(echo '${{ env.SERVERLESS }} ${{ env.GITOPS }}' | jq -c -s add) | ||
echo "PARAMETERS=${PARAMETERS}" >> $GITHUB_ENV | ||
shell: bash | ||
|
||
- uses: elastic/apm-pipeline-library/.github/actions/oblt-cli@current | ||
with: | ||
command: cluster create custom --template serverless ${{ env.COMMAND }} --parameters='${{ env.PARAMETERS }}' | ||
slackChannel: ${{ inputs.slackChannel }} | ||
token: ${{ inputs.token }} | ||
username: ${{ inputs.username }} |
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,34 @@ | ||
--- | ||
name: test-oblt-cli-create-serverless | ||
|
||
on: | ||
workflow_dispatch: ~ | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- '.github/actions/oblt-cli-create-serverless/**' | ||
|
||
jobs: | ||
|
||
run-oblt-cli-create-serverless: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Setup Git | ||
uses: elastic/apm-pipeline-library/.github/actions/setup-git@main | ||
|
||
- uses: elastic/apm-pipeline-library/.github/actions/github-token@main | ||
with: | ||
url: ${{ secrets.VAULT_ADDR }} | ||
roleId: ${{ secrets.VAULT_ROLE_ID }} | ||
secretId: ${{ secrets.VAULT_SECRET_ID }} | ||
|
||
- uses: ./.github/actions/oblt-cli-create-serverless | ||
with: | ||
token: ${{ env.GITHUB_TOKEN }} | ||
target: 'qa' | ||
cluster-name-prefix: 'testgithubaction' | ||
gitops: true | ||
dry-run: true |