Skip to content

Commit

Permalink
Merge pull request #425 from RoadieHQ/SC-6776-add-aws-actions-package
Browse files Browse the repository at this point in the history
[SC-6776] add aws actions package
  • Loading branch information
kissmikijr authored Feb 28, 2022
2 parents 6f95e2a + 5313a95 commit 6086416
Show file tree
Hide file tree
Showing 13 changed files with 1,791 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/funny-geckos-live.md
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
1 change: 1 addition & 0 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@roadiehq/backstage-plugin-aws-auth": "^0.3.2",
"@roadiehq/scaffolder-backend-module-http-request": "^2.1.8",
"@roadiehq/scaffolder-backend-module-utils": "^0.1.2",
"@roadiehq/scaffolder-backend-module-aws": "^1.0.0",
"@vscode/sqlite3": "^5.0.7",
"app": "^0.0.8",
"dockerode": "^3.2.1",
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/plugins/scaffolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
} from '@backstage/plugin-scaffolder-backend';
import { createHttpBackstageAction } from '@roadiehq/scaffolder-backend-module-http-request';
import { createZipAction, createWriteFileAction, createSleepAction, createAppendFileAction } from '@roadiehq/scaffolder-backend-module-utils';
import { createAwsS3CpAction } from '@roadiehq/scaffolder-backend-module-aws';
import Docker from 'dockerode';
import { Router } from 'express';
import type { PluginEnvironment } from '../types';
Expand Down Expand Up @@ -54,6 +55,7 @@ export const createActions = (options: {
createSleepAction(),
createWriteFileAction(),
createAppendFileAction(),
createAwsS3CpAction(),
createHttpBackstageAction({ config }),
...defaultActions
];
Expand Down
41 changes: 41 additions & 0 deletions packages/entities/s3-upload-template.yaml
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

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 plugins/scaffolder-actions/scaffolder-backend-module-aws/README.md
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 }}
```
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"
]
}
Loading

0 comments on commit 6086416

Please sign in to comment.