Skip to content

Commit

Permalink
feat(snapshoty): run (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
v1v authored Jun 5, 2024
1 parent aabc304 commit cad2ab3
Show file tree
Hide file tree
Showing 9 changed files with 4,726 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ repos:
- id: check-yaml
- id: check-xml
- id: end-of-file-fixer
exclude: dist/index.js
- id: mixed-line-ending
- id: trailing-whitespace
exclude: dist/index.js
- repo: https://github.com/reakaleek/gh-action-readme
rev: v0.3.1
hooks:
Expand Down
1 change: 1 addition & 0 deletions snapshoty/run/.node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
40 changes: 40 additions & 0 deletions snapshoty/run/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# <!--name-->snapshoty/run<!--/name-->


<!--description-->
The best way to handle snapshot lifecycle.
<!--/description-->

## Inputs
<!--inputs-->
| Name | Description | Required | Default |
|----------------------|----------------------------------------------------|----------|---------|
| `config` | Path to configuration file | `true` | ` ` |
| `bucket-name` | Name of the bucket to use | `true` | ` ` |
| `gcs-client-email` | Google Cloud email of the service account | `true` | ` ` |
| `gcs-private-key` | Google Cloud private key of the service account | `true` | ` ` |
| `gcs-private-key-id` | Google Cloud private key id of the service account | `true` | ` ` |
| `gcs-project` | Google Cloud project id of the service account | `true` | ` ` |
<!--/inputs-->

In addition, you can pass env variables with the prefix `SNAPSHOTY_`, the prefix will be removed and the name
of the variable will be passed.

## Usage

<!--usage action="elastic/oblt-actions/snapshoty/run" version="env:VERSION"-->
```yaml
steps:
- uses: elastic/oblt-actions/snapshoty/run@v1
with:
config: snapshoty.yml
bucket-name: 'my-bucket'
gcs-client-email: '[email protected]'
gcs-private-ley: 'my-secret-key'
gcs-private-key-id: 'my-private-key'
gcs-project: 'my-gcs-project'
env:
SNAPSHOTY_DATE: "2023-09-20"
```
<!--/usage-->
24 changes: 24 additions & 0 deletions snapshoty/run/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: 'snapshoty/run'
description: 'The best way to handle snapshot lifecycle.'
inputs:
config:
description: 'Path to configuration file'
required: true
bucket-name:
description: 'Name of the bucket to use'
required: true
gcs-client-email:
description: 'Google Cloud email of the service account'
required: true
gcs-private-key:
description: 'Google Cloud private key of the service account'
required: true
gcs-private-key-id:
description: 'Google Cloud private key id of the service account'
required: true
gcs-project:
description: 'Google Cloud project id of the service account'
required: true
runs:
using: 'node20'
main: 'dist/index.js'
3 changes: 3 additions & 0 deletions snapshoty/run/dist/index.js

Large diffs are not rendered by default.

144 changes: 144 additions & 0 deletions snapshoty/run/dist/licenses.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
@actions/core
MIT
The MIT License (MIT)

Copyright 2019 GitHub

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@actions/exec
MIT
The MIT License (MIT)

Copyright 2019 GitHub

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@actions/http-client
MIT
Actions Http Client for Node.js

Copyright (c) GitHub, Inc.

All rights reserved.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


@actions/io
MIT
The MIT License (MIT)

Copyright 2019 GitHub

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@fastify/busboy
MIT
Copyright Brian White. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.

tunnel
MIT
The MIT License (MIT)

Copyright (c) 2012 Koichi Kobayashi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


undici
MIT
MIT License

Copyright (c) Matteo Collina and Undici contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


uuid
MIT
The MIT License (MIT)

Copyright (c) 2010-2020 Robert Kieffer and other contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
63 changes: 63 additions & 0 deletions snapshoty/run/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const core = require('@actions/core');
const exec = require('@actions/exec');
const os = require("os");

async function run() {
try {
const gcsClientEmail = core.getInput('gcs-client-email');
const gcsPrivateKey = core.getInput('gcs-private-key');
const gcsPrivateKeyId = core.getInput('gcs-private-key-id');
const gcsProject = core.getInput('gcs-project');
const bucketName = core.getInput('bucket-name');
const config = core.getInput('config');

const workDir = process.env.GITHUB_WORKSPACE;
const userInfo = os.userInfo();

const args = [
'run', '--rm',
'-v', `${workDir}:/app`,
'-u', `${userInfo.uid}:${userInfo.gid}`,
'-w', '/app',
'-e', `GCS_CLIENT_EMAIL=${gcsClientEmail}`,
'-e', `GCS_PRIVATE_KEY=${gcsPrivateKey}`,
'-e', `GCS_PRIVATE_KEY_ID=${gcsPrivateKeyId}`,
'-e', `GCS_PROJECT=${gcsProject}`
]

// GCS env vars are secrets
for (secret of [gcsClientEmail, gcsPrivateKey, gcsPrivateKeyId, gcsProject]) {
core.setSecret(secret);
}

// Forward env vars
Object.keys(process.env).forEach(function (key) {
if (key.startsWith("GITHUB_") || key.startsWith("RUNNER_")) {
let value = process.env[key];
args.push('-e', `${key}=${value}`);

if (key === 'GITHUB_TOKEN') {
core.setSecret(value);
}
}

// Special case so we can inject env variables
if (key.startsWith("SNAPSHOTY_")) {
let value = process.env[key];
let variable = key.replace("SNAPSHOTY_", "")
args.push('-e', `${variable}=${value}`);
}
});
args.push('docker.elastic.co/observability-ci/snapshoty:v1', 'snapshoty');
if (core.isDebug()) {
args.push('--debug');
}
args.push('--config', config, 'upload', '--bucket-name', bucketName);

return await exec.exec('docker', args);
} catch (error) {
core.setFailed(error.message);
}
}

run();
Loading

0 comments on commit cad2ab3

Please sign in to comment.