Skip to content

Commit

Permalink
feat: add Cloudsmith auth
Browse files Browse the repository at this point in the history
This adds in the orb to authenticate with Cloudsmith via OIDC. Our
Cloudsmith orb requires two environment variables to work:

  * CLOUDSMITH_ORGANISATION
  * CLOUDSMITH_SERVICE_ACCOUNT

To allow us to specify these in Tool Kit config instead (which is a lot
cleaner, the config lives in the code etc) we need to define a schema
for a nonexistent `cloudsmith` plugin and then pass params through into
the CircleCI config.

Co-Authored-By: Alex Muller <[email protected]>
Co-Authored-By: Ivo Murrell <[email protected]>
  • Loading branch information
3 people committed Dec 3, 2024
1 parent c84315e commit 3eaa79a
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 0 deletions.
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
6 changes: 6 additions & 0 deletions lib/schemas/src/plugins/cloudsmith.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { z } from 'zod'

export const CloudsmithSchema = z.object({
organisation: z.string().optional(),
serviceAccount: z.string().optional()
})
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
16 changes: 16 additions & 0 deletions plugins/circleci-deploy/.toolkitrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ options:
!toolkit/if-defined '@dotcom-tool-kit/serverless.awsAccountId':
aws-account-id: !toolkit/option '@dotcom-tool-kit/serverless.awsAccountId'
system-code: !toolkit/option '@dotcom-tool-kit/serverless.systemCode'
!toolkit/if-defined '@dotcom-tool-kit/cloudsmith.organisation':
cloudsmith-org: !toolkit/option '@dotcom-tool-kit/cloudsmith.organisation'
!toolkit/if-defined '@dotcom-tool-kit/cloudsmith.serviceAccount':
cloudsmith-service-account: !toolkit/option '@dotcom-tool-kit/cloudsmith.serviceAccount'
- name: 'deploy-staging'
requires:
- 'setup'
Expand All @@ -39,6 +43,10 @@ options:
filters:
branches:
only: main
!toolkit/if-defined '@dotcom-tool-kit/cloudsmith.organisation':
cloudsmith-org: !toolkit/option '@dotcom-tool-kit/cloudsmith.organisation'
!toolkit/if-defined '@dotcom-tool-kit/cloudsmith.serviceAccount':
cloudsmith-service-account: !toolkit/option '@dotcom-tool-kit/cloudsmith.serviceAccount'
- name: 'e2e-test-review'
requires:
- 'deploy-review'
Expand Down Expand Up @@ -71,6 +79,10 @@ options:
!toolkit/if-defined '@dotcom-tool-kit/serverless.awsAccountId':
aws-account-id: !toolkit/option '@dotcom-tool-kit/serverless.awsAccountId'
system-code: !toolkit/option '@dotcom-tool-kit/serverless.systemCode'
!toolkit/if-defined '@dotcom-tool-kit/cloudsmith.organisation':
cloudsmith-org: !toolkit/option '@dotcom-tool-kit/cloudsmith.organisation'
!toolkit/if-defined '@dotcom-tool-kit/cloudsmith.serviceAccount':
cloudsmith-service-account: !toolkit/option '@dotcom-tool-kit/cloudsmith.serviceAccount'
- name: 'nightly'
jobs:
- name: 'deploy-review'
Expand All @@ -85,6 +97,10 @@ options:
!toolkit/if-defined '@dotcom-tool-kit/serverless.awsAccountId':
aws-account-id: !toolkit/option '@dotcom-tool-kit/serverless.awsAccountId'
system-code: !toolkit/option '@dotcom-tool-kit/serverless.systemCode'
!toolkit/if-defined '@dotcom-tool-kit/cloudsmith.organisation':
cloudsmith-org: !toolkit/option '@dotcom-tool-kit/cloudsmith.organisation'
!toolkit/if-defined '@dotcom-tool-kit/cloudsmith.serviceAccount':
cloudsmith-service-account: !toolkit/option '@dotcom-tool-kit/cloudsmith.serviceAccount'
!toolkit/if-defined '@dotcom-tool-kit/circleci.cypressImage':
executors:
- name: cypress
Expand Down

0 comments on commit 3eaa79a

Please sign in to comment.