-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #425 from RoadieHQ/SC-6776-add-aws-actions-package
[SC-6776] add aws actions package
- Loading branch information
Showing
13 changed files
with
1,791 additions
and
17 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,5 @@ | ||
--- | ||
'@roadiehq/scaffolder-backend-module-aws': minor | ||
--- | ||
|
||
Publish first version of the action |
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
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
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,41 @@ | ||
# Notice the v1beta3 version | ||
apiVersion: scaffolder.backstage.io/v1beta3 | ||
kind: Template | ||
metadata: | ||
name: s3-upload | ||
title: scaffolder-backend-module-aws s3 upload template | ||
description: An example template to test most of the scaffolder-backend-module-utils actions | ||
spec: | ||
owner: roadie | ||
type: service | ||
|
||
parameters: | ||
- title: Create File | ||
properties: | ||
createPath: | ||
title: Path | ||
type: string | ||
description: workspace path to zip | ||
createContent: | ||
title: File Content | ||
type: string | ||
description: content of the file | ||
ui:widget: textarea | ||
ui:options: | ||
rows: 5 | ||
|
||
steps: | ||
- id: createFile | ||
name: Create File | ||
action: roadiehq:utils:fs:write | ||
input: | ||
path: ${{ parameters.createPath }} | ||
content: ${{ parameters.createContent }} | ||
|
||
- id: s3Upload | ||
name: Upload to S3 | ||
action: roadiehq:aws:s3:cp | ||
input: | ||
bucket: scaffolder-actions-upload-test | ||
region: eu-west-1 | ||
|
41 changes: 41 additions & 0 deletions
41
plugins/scaffolder-actions/scaffolder-backend-module-aws/.eslintrc.js
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,41 @@ | ||
const parent = require('@backstage/cli/config/eslint.backend'); | ||
|
||
module.exports = { | ||
extends: [require.resolve('@backstage/cli/config/eslint.backend')], | ||
ignorePatterns: ['sample-templates/'], | ||
rules: { | ||
'no-console': 0, // Permitted in console programs | ||
'new-cap': ['error', { capIsNew: false }], // Because Express constructs things e.g. like 'const r = express.Router()' | ||
// Usage of path.resolve is extra sensitive in the scaffolder, so forbid it in non-test code | ||
'no-restricted-imports': [ | ||
'error', | ||
{ | ||
...parent.rules['no-restricted-imports'][1], | ||
paths: [ | ||
{ | ||
name: 'path', | ||
importNames: ['resolve'], | ||
message: | ||
'Do not use path.resolve, use `resolveSafeChildPath` from `@backstage/backend-common` instead as it prevents security issues', | ||
}, | ||
], | ||
}, | ||
], | ||
'no-restricted-syntax': parent.rules['no-restricted-syntax'].concat([ | ||
{ | ||
message: | ||
'Do not use path.resolve, use `resolveSafeChildPath` from `@backstage/backend-common` instead as it prevents security issues', | ||
selector: | ||
'MemberExpression[object.name="path"][property.name="resolve"]', | ||
}, | ||
]), | ||
}, | ||
overrides: [ | ||
{ | ||
files: ['*.test.*', 'src/setupTests.*', 'dev/**'], | ||
rules: { | ||
'no-restricted-imports': parent.rules['no-restricted-imports'], | ||
}, | ||
}, | ||
], | ||
}; |
Empty file.
123 changes: 123 additions & 0 deletions
123
plugins/scaffolder-actions/scaffolder-backend-module-aws/README.md
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,123 @@ | ||
# scaffolder-backend-module-utils actions package | ||
|
||
Welcome to the roadie `aws` actions for the `scaffolder-backend`. | ||
|
||
This contains a collection of actions: | ||
|
||
- `roadiehq:aws:s3:cp` | ||
|
||
## Getting started | ||
|
||
Create your Backstage application using the Backstage CLI as described here: | ||
https://backstage.io/docs/getting-started/create-an-app | ||
|
||
> Note: If you are using this plugin in a Backstage monorepo that contains the code for `@backstage/plugin-scaffolder-backend`, you need to modify your internal build processes to transpile files from the `node_modules` folder as well. | ||
You need to configure the action in your backend: | ||
|
||
## From your Backstage root directory | ||
|
||
``` | ||
cd packages/backend | ||
yarn add @roadiehq/scaffolder-backend-module-aws | ||
``` | ||
|
||
Configure the action: | ||
(you can check the [docs](https://backstage.io/docs/features/software-templates/writing-custom-actions#registering-custom-actions) to see all options): | ||
|
||
Import the action that you'd like to register to your backstage instance. | ||
|
||
```typescript | ||
// packages/backend/src/plugins/scaffolder.ts | ||
import { createAwsS3CpAction } from '@roadiehq/scaffolder-backend-module-aws'; | ||
... | ||
|
||
const actions = [ | ||
createAwsS3CpAction(), | ||
...createBuiltinActions({ | ||
containerRunner, | ||
integrations, | ||
config, | ||
catalogClient, | ||
reader, | ||
}), | ||
]; | ||
|
||
return await createRouter({ | ||
containerRunner, | ||
logger, | ||
config, | ||
database, | ||
catalogClient, | ||
reader, | ||
actions, | ||
}); | ||
``` | ||
|
||
# Authentication | ||
|
||
This action accepts an optional `credentials` parameter. Which should be a `CredentialProvider` interface from the [@aws-sdk/credential-provider](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_credential_providers.html) If you want to override the `@aws-sdk/client-s3` module's default authentication, provide a valid credential to the action. | ||
|
||
Example: | ||
|
||
```typescript | ||
// packages/backend/src/plugins/scaffolder.ts | ||
import { createAwsS3CpAction } from '@roadiehq/scaffolder-backend-module-aws'; | ||
import { fromIni } from "@aws-sdk/credential-provider"; | ||
... | ||
|
||
const actions = [ | ||
createAwsS3CpAction({credentials: fromIni({profile: "dev" })}), | ||
...createBuiltinActions({ | ||
containerRunner, | ||
integrations, | ||
config, | ||
catalogClient, | ||
reader, | ||
}), | ||
]; | ||
|
||
return await createRouter({ | ||
containerRunner, | ||
logger, | ||
config, | ||
database, | ||
catalogClient, | ||
reader, | ||
actions, | ||
}); | ||
``` | ||
|
||
# Template | ||
|
||
This is a minimum template to use this action. It accepts one required parameter `bucket`. And will upload the whole workspace context to this bucket. | ||
|
||
```yaml | ||
--- | ||
apiVersion: scaffolder.backstage.io/v1beta3 | ||
kind: Template | ||
metadata: | ||
name: upload-to-s3 | ||
title: Upload | ||
description: Uploads the workspace context to the given S3 bucket | ||
spec: | ||
owner: roadie | ||
type: service | ||
|
||
parameters: | ||
- title: Upload to S3 | ||
properties: | ||
required: ['bucket'] | ||
bucket: | ||
title: Bucket | ||
type: string | ||
description: The context will be uploaded into this bucket | ||
|
||
steps: | ||
- id: uploadToS3 | ||
name: Upload to S3 | ||
action: roadiehq:aws:s3:cp | ||
input: | ||
region: eu-west-1 | ||
bucket: ${{ parameters.bucket }} | ||
``` |
56 changes: 56 additions & 0 deletions
56
plugins/scaffolder-actions/scaffolder-backend-module-aws/package.json
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,56 @@ | ||
{ | ||
"name": "@roadiehq/scaffolder-backend-module-aws", | ||
"version": "1.0.0", | ||
"main": "src/index.ts", | ||
"types": "src/index.ts", | ||
"license": "Apache-2.0", | ||
"publishConfig": { | ||
"access": "public", | ||
"main": "dist/index.cjs.js", | ||
"types": "dist/index.d.ts" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "github:RoadieHQ/roadie-backstage-plugins", | ||
"directory": "plugins/scaffolder-actions/scaffolder-backend-module-aws" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/RoadieHQ/roadie-backstage-plugins/issues", | ||
"email": "[email protected]" | ||
}, | ||
"scripts": { | ||
"start": "backstage-cli backend:dev", | ||
"build": "backstage-cli backend:build", | ||
"lint": "backstage-cli lint", | ||
"test": "backstage-cli test", | ||
"prepack": "backstage-cli prepack", | ||
"postpack": "backstage-cli postpack", | ||
"clean": "backstage-cli clean" | ||
}, | ||
"dependencies": { | ||
"@aws-sdk/client-s3": "^3.53.0", | ||
"@aws-sdk/types": "^3.53.0", | ||
"@backstage/backend-common": "^0.10.1", | ||
"@backstage/config": "^0.1.8", | ||
"@backstage/errors": "^0.2.0", | ||
"@backstage/plugin-scaffolder-backend": "^0.15.2", | ||
"cross-fetch": "^3.1.4", | ||
"fs-extra": "^10.0.0", | ||
"glob": "^7.2.0", | ||
"winston": "^3.2.1" | ||
}, | ||
"devDependencies": { | ||
"@aws-sdk/types": "^3.53.0", | ||
"@backstage/cli": "^0.13.0", | ||
"@types/adm-zip": "^0.4.34", | ||
"@types/fs-extra": "^9.0.13", | ||
"@types/glob": "^7.2.0", | ||
"@types/jest": "^26.0.7", | ||
"@types/mock-fs": "^4.13.1", | ||
"aws-sdk-client-mock": "^0.6.0", | ||
"mock-fs": "^5.1.2" | ||
}, | ||
"files": [ | ||
"dist" | ||
] | ||
} |
Oops, something went wrong.