Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Cloudsmith auth #710

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions lib/schemas/src/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { z } from 'zod'

import { CircleCISchema } from './plugins/circleci'
import { CloudsmithSchema } from './plugins/cloudsmith'
import { DopplerSchema } from './plugins/doppler'
import { RootSchema } from './plugins/dotcom-tool-kit'
import { HerokuSchema } from './plugins/heroku'
Expand Down Expand Up @@ -28,6 +29,7 @@ export const legacyPluginOptions: Record<string, string> = {
export const PluginSchemas = {
'app root': RootSchema,
'@dotcom-tool-kit/circleci': CircleCISchema,
'@dotcom-tool-kit/cloudsmith': CloudsmithSchema,
'@dotcom-tool-kit/doppler': DopplerSchema,
'@dotcom-tool-kit/heroku': HerokuSchema,
'@dotcom-tool-kit/lint-staged-npm': LintStagedNpmSchema,
Expand Down
10 changes: 10 additions & 0 deletions lib/schemas/src/plugins/cloudsmith.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { z } from 'zod'

export const CloudsmithSchema = z.object({
serviceAccount: z
.string()
.optional()
.describe(
'the Cloudsmith service account. this will probably be your team name followed by the permissions access, e.g., cp-reliability-read-write.'
)
})
1 change: 1 addition & 0 deletions orb/src/@orb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ display:
orbs:
node: circleci/[email protected]
change-api: financial-times/[email protected]
cloudsmith-oidc: ft-circleci-orbs/[email protected]
aws-cli: circleci/[email protected]
serverless-framework: circleci/[email protected]
17 changes: 17 additions & 0 deletions orb/src/jobs/deploy-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,30 @@ parameters:
The system-code of the system being changed. Defaults to the repository
name.
type: string
cloudsmith-org:
default: 'financial-times'
type: string
cloudsmith-service-account:
default: ''
type: string

executor: << parameters.executor >>

environment:
CLOUDSMITH_ORGANISATION: << parameters.cloudsmith-org >>
CLOUDSMITH_SERVICE_ACCOUNT: << parameters.cloudsmith-service-account >>

steps:
- attach-workspace
- setup_remote_docker:
docker_layer_caching: true
- when:
condition:
and:
- << parameters.cloudsmith-org >>
- << parameters.cloudsmith-service-account >>
steps:
- cloudsmith-oidc/authenticate_with_oidc
- when:
condition:
and:
Expand Down
17 changes: 17 additions & 0 deletions orb/src/jobs/deploy-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,30 @@ parameters:
system-code:
default: ''
type: string
cloudsmith-org:
default: 'financial-times'
type: string
cloudsmith-service-account:
default: ''
type: string

executor: << parameters.executor >>

environment:
CLOUDSMITH_ORGANISATION: << parameters.cloudsmith-org >>
CLOUDSMITH_SERVICE_ACCOUNT: << parameters.cloudsmith-service-account >>

steps:
- attach-workspace
- setup_remote_docker:
docker_layer_caching: true
- when:
condition:
and:
- << parameters.cloudsmith-org >>
- << parameters.cloudsmith-service-account >>
steps:
- cloudsmith-oidc/authenticate_with_oidc
- when:
condition:
and:
Expand Down
17 changes: 17 additions & 0 deletions orb/src/jobs/deploy-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,30 @@ parameters:
executor:
default: default
type: executor
cloudsmith-org:
default: 'financial-times'
type: string
cloudsmith-service-account:
default: ''
type: string

executor: << parameters.executor >>

environment:
CLOUDSMITH_ORGANISATION: << parameters.cloudsmith-org >>
CLOUDSMITH_SERVICE_ACCOUNT: << parameters.cloudsmith-service-account >>

steps:
- attach-workspace
- setup_remote_docker:
docker_layer_caching: true
- when:
condition:
and:
- << parameters.cloudsmith-org >>
- << parameters.cloudsmith-service-account >>
steps:
- cloudsmith-oidc/authenticate_with_oidc
- run:
name: Deploy to staging
command: npx dotcom-tool-kit deploy:staging
Expand Down
21 changes: 17 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions plugins/cloudsmith/.toolkitrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: 2

plugins:
- '@dotcom-tool-kit/circleci-deploy'

options:
hooks:
- CircleCi:
workflows:
- name: 'tool-kit'
jobs:
- name: 'deploy-review'
custom:
cloudsmith-org: financial-times
!toolkit/if-defined '@dotcom-tool-kit/cloudsmith.serviceAccount':
cloudsmith-service-account: !toolkit/option '@dotcom-tool-kit/cloudsmith.serviceAccount'
- name: 'deploy-staging'
custom:
cloudsmith-org: financial-times
!toolkit/if-defined '@dotcom-tool-kit/cloudsmith.serviceAccount':
cloudsmith-service-account: !toolkit/option '@dotcom-tool-kit/cloudsmith.serviceAccount'
- name: 'deploy-production'
custom:
cloudsmith-org: financial-times
!toolkit/if-defined '@dotcom-tool-kit/cloudsmith.serviceAccount':
cloudsmith-service-account: !toolkit/option '@dotcom-tool-kit/cloudsmith.serviceAccount'
- name: 'nightly'
jobs:
- name: 'deploy-review'
custom:
cloudsmith-org: financial-times
!toolkit/if-defined '@dotcom-tool-kit/cloudsmith.serviceAccount':
cloudsmith-service-account: !toolkit/option '@dotcom-tool-kit/cloudsmith.serviceAccount'
31 changes: 31 additions & 0 deletions plugins/cloudsmith/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "@dotcom-tool-kit/cloudsmith",
"version": "0.1.0",
"description": "",
"main": "lib",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "FT.com Platforms Team <[email protected]>",
"license": "ISC",
"repository": {
"type": "git",
"url": "https://github.com/financial-times/dotcom-tool-kit.git",
"directory": "plugins/cloudsmith"
},
"bugs": "https://github.com/financial-times/dotcom-tool-kit/issues",
"homepage": "https://github.com/financial-times/dotcom-tool-kit/tree/main/plugins/cloudsmith",
"files": [
"/lib",
".toolkitrc.yml"
],
"engines": {
"node": "18.x || 20.x",
"npm": "7.x || 8.x || 9.x || 10.x"
},
"peerDependencies": {
"dotcom-tool-kit": "4.x"
}
}

28 changes: 28 additions & 0 deletions plugins/cloudsmith/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# @dotcom-tool-kit/cloudsmith

## Installation & Usage

With Tool Kit [already set up](https://github.com/financial-times/dotcom-tool-kit#installing-and-using-tool-kit), install this plugin as a dev dependency:

```sh
npm install --save-dev @dotcom-tool-kit/cloudsmith
```

And add it to your repo's `.toolkitrc.yml`:

```yml
plugins:
- '@dotcom-tool-kit/cloudsmith'
```

<!-- begin autogenerated docs -->
## Plugin-wide options

### `@dotcom-tool-kit/cloudsmith`

| Property | Description | Type |
| :--------------- | :---------------------------------------------------------------------------------------------------------------------------------------- | :------- |
| `serviceAccount` | the Cloudsmith service account. this will probably be your team name followed by the permissions access, e.g., cp-reliability-read-write. | `string` |

_All properties are optional._
<!-- end autogenerated docs -->
29 changes: 27 additions & 2 deletions scripts/create-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ pkg.author = 'FT.com Platforms Team <[email protected]>'
pkg.files = ['/lib', '.toolkitrc.yml']
pkg.engines = {
node: '18.x || 20.x',
npm: '7.x || 8.x || 9.x'
npm: '7.x || 8.x || 9.x || 10.x'
}
pkg.peerDependencies = {
'dotcom-tool-kit': '3.x'
'dotcom-tool-kit': '4.x'
}

fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2))
Expand All @@ -64,6 +64,31 @@ fs.writeFileSync('tsconfig.json', JSON.stringify(tsconfig, null, 2))
console.log('📄 adding empty toolkit config')
fs.writeFileSync('.toolkitrc.yml', 'version: 2\n')

console.log('📖 adding simple README')
fs.writeFileSync(
'readme.md',
`#dotcom-tool-kit/${name}

## Installation & Usage

With Tool Kit [already set up](https://github.com/financial-times/dotcom-tool-kit#installing-and-using-tool-kit), install this plugin as a dev dependency:

\`\`\`sh
npm install --save-dev @dotcom-tool-kit/${name}
\`\`\`

And add it to your repo's \`.toolkitrc.yml\`:

\`\`\`yml
plugins:
- '@dotcom-tool-kit/${name}'
\`\`\`

<!-- begin autogenerated docs -->
<!-- end autogenerated docs -->
`
)

console.log('🔗 adding reference to root tsconfig')
const rootTsconfig = JSON.parse(fs.readFileSync('../../tsconfig.json'))
rootTsconfig.references.push({ path: directory })
Expand Down
Loading