Skip to content

Commit

Permalink
update severely outdated package versions (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggilmore committed May 8, 2021
1 parent bef5279 commit 7f55c1e
Show file tree
Hide file tree
Showing 15 changed files with 620 additions and 876 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ yarn-error.log
.history

.envrc
.local-deploy-sourcegraph

Pulumi.dev.yaml
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12.16.1
14.16.1
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.local-deploy-sourcegraph/
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
yarn 1.22.4
kubectl 1.17.3
fd 7.4.0
pulumi 1.14.0
pulumi 3.2.1
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"editor.formatOnSave": true
}
"editor.formatOnSave": true,
}
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
# deploy-k8s-helper
# deploy-k8s-helper

A small helper program to aid in creating a test cluster for https://github.com/sourcegraph/deploy-sourcegraph.
A small helper program to aid in creating a test cluster for https://github.com/sourcegraph/deploy-sourcegraph.

## Prerequisites
## Prerequisites

- [Pulumi](https://pulumi.io/quickstart/install.html)
- Run `pulumi login` after installation
- Run `pulumi login` after installation
- [Yarn](https://yarnpkg.com/en/)
- GCP access to the ["Sourcegraph Auxiliary" (sourcegraph-server) GCP project](https://console.cloud.google.com/kubernetes/list?project=sourcegraph-server)
- Run `gcloud auth application-default login` to fetch the necessary credentials for Pulumi to use
- Run `gcloud auth application-default login` to fetch the necessary credentials for Pulumi to use
- https://github.com/sourcegraph/deploy-sourcegraph checked out on your local machine
- deploy-k8s-helper reads the contents of that directory. Make sure your that your checkout is up-to-date!
- deploy-k8s-helper reads the contents of that directory. Make sure your that your checkout is up-to-date!

### Configuration

See [config.ts](config.ts) for more information, but you **must** set the following configuration values via `pulumi config set <NAME> <VALUE>`

- `gcloudEmail` - The email that you use to sign in to our GCP project.
- example: geoffrey@sourcegraph.com
- `gcloudEmail` - The email that you use to sign in to our GCP project.
- example: geoffrey@sourcegraph.com
- `deploySourcegraphRoot` - The path to the root of your https://github.com/sourcegraph/deploy-sourcegraph checkout.
- example: /Users/ggilmore/dev/go/src/github.com/sourcegraph/deploy-sourcegraph
- example: /Users/ggilmore/dev/go/src/github.com/sourcegraph/deploy-sourcegraph

## Usage
## Usage

Run `yarn` so that you install all the necessary dependencies.
Run `yarn` so that you install all the necessary dependencies.

- `yarn up`: creates a new GKE cluster and fetches the necessary credentials
- `yarn destroy`: deletes a GKE cluster that was previously created with `yarn up`
Expand Down Expand Up @@ -57,7 +57,7 @@ Solution: Pick another zone to use from https://cloud.google.com/compute/docs/re

### (ingress-nginx) Cannot read property 'status' of undefined

This happens if you're trying to deploy a pre-`3.x` release of https://github.com/sourcegraph/deploy-sourcegraph/ (which didn't have `nginx-ingress`).
This happens if you're trying to deploy a pre-`3.x` release of https://github.com/sourcegraph/deploy-sourcegraph/ (which didn't have `nginx-ingress`).

Example:

Expand Down
1 change: 0 additions & 1 deletion cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const cluster = new gcp.container.Cluster(name, {
project: gcloudConfig.project,

initialNodeCount: clusterConfig.nodeCount,
removeDefaultNodePool: true,

nodeConfig: {
diskType: 'pd-ssd',
Expand Down
8 changes: 5 additions & 3 deletions config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ export const clusterConfig = {
* The number of nodes to create in this cluster.
* Defaults to 4.
*/
nodeCount: config.getNumber('nodeCount') || 4,
nodeCount: config.getNumber('nodeCount') || 3,

/**
* The name of a Google Compute Engine machine type.
* Defaults to n1-standard-8.
*/
machineType: config.get('machineType') || 'n1-standard-8',
machineType: config.get('machineType') || 'n1-standard-16',
}

export const gcloudConfig = {
Expand All @@ -47,4 +47,6 @@ export const gcloudConfig = {
* The path to the root of your sourcegraph/deploy-sourcegraph checkout.
* Example: /Users/ggilmore/dev/go/src/github.com/sourcegraph/deploy-sourcegraph
*/
export const deploySourcegraphRoot = config.require('deploySourcegraphRoot')
export const deploySourcegraphLocalRoot = config.get('deploySourcegraphLocalRoot')

export const deploySourcegraphRef = config.get('deploySourcegraphRef') || 'master'
120 changes: 66 additions & 54 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,83 @@ import * as path from 'path'

import * as k8s from '@pulumi/kubernetes'

import { k8sProvider } from './cluster'
import { deploySourcegraphRoot, gcloudConfig } from './config'
import { deploySourcegraphLocalRoot, gcloudConfig, deploySourcegraphRef } from './config'
import { cloneLocalDSCheckout } from './util'
import * as cluster from './cluster'

const clusterAdmin = new k8s.rbac.v1.ClusterRoleBinding(
'cluster-admin-role-binding',
{
metadata: { name: `${os.userInfo().username}-cluster-admin-role-binding` },
const k8sProvider = cluster.k8sProvider

roleRef: {
apiGroup: 'rbac.authorization.k8s.io',
kind: 'ClusterRole',
name: 'cluster-admin',
},
export = async () => {
const clusterAdmin = new k8s.rbac.v1.ClusterRoleBinding(
'cluster-admin-role-binding',
{
metadata: { name: `${os.userInfo().username}-cluster-admin-role-binding` },

subjects: [
{
roleRef: {
apiGroup: 'rbac.authorization.k8s.io',
kind: 'User',
name: gcloudConfig.username,
kind: 'ClusterRole',
name: 'cluster-admin',
},
],
},
{ provider: k8sProvider }
)

const storageClass = new k8s.storage.v1.StorageClass(
'sourcegraph-storage-class',
{
metadata: {
name: 'sourcegraph',
subjects: [
{
apiGroup: 'rbac.authorization.k8s.io',
kind: 'User',
name: gcloudConfig.username,
},
],
},
{ provider: k8sProvider }
)

const storageClass = new k8s.storage.v1.StorageClass(
'sourcegraph-storage-class',
{
metadata: {
name: 'sourcegraph',

labels: {
deploy: 'sourcegraph',
labels: {
deploy: 'sourcegraph',
},
},
},
provisioner: 'kubernetes.io/gce-pd',
provisioner: 'kubernetes.io/gce-pd',

parameters: {
type: 'pd-ssd',
parameters: {
type: 'pd-ssd',
},
},
},
{ provider: k8sProvider }
)
{ provider: k8sProvider }
)

const baseDeployment = new k8s.yaml.ConfigGroup(
'base',
{
files: `${path.posix.join(deploySourcegraphRoot, 'base')}/**/*.yaml`,
},
{
providers: { kubernetes: k8sProvider },
dependsOn: [clusterAdmin, storageClass],
}
)
const deploySourcegraphRoot = deploySourcegraphLocalRoot
? deploySourcegraphLocalRoot
: await cloneLocalDSCheckout(deploySourcegraphRef)

const ingressNginx = new k8s.yaml.ConfigGroup(
'ingress-nginx',
{
files: `${path.posix.join(deploySourcegraphRoot, 'configure', 'ingress-nginx')}/**/*.yaml`,
},
{ providers: { kubernetes: k8sProvider }, dependsOn: clusterAdmin }
)
const baseDeployment = new k8s.yaml.ConfigGroup(
'base',
{
files: `${path.posix.join(deploySourcegraphRoot, 'base')}/**/*.yaml`,
},
{
providers: { kubernetes: k8sProvider },
dependsOn: [clusterAdmin, storageClass],
}
)

export const ingressIPs = ingressNginx
.getResource('v1/Service', 'ingress-nginx', 'ingress-nginx')
.apply(svc => svc.status.apply(status => status.loadBalancer.ingress.map(i => i.ip)))
const ingressNginx = new k8s.yaml.ConfigGroup(
'ingress-nginx',
{
files: `${path.posix.join(deploySourcegraphRoot, 'configure', 'ingress-nginx')}/**/*.yaml`,
},
{ providers: { kubernetes: k8sProvider }, dependsOn: clusterAdmin }
)

export * from './cluster'
const ingressIPs = ingressNginx
.getResource('v1/Service', 'ingress-nginx', 'ingress-nginx')
.apply(svc => svc.status.apply(status => status.loadBalancer.ingress.map(i => i.ip)))

return {
ingressIPs,
...cluster,
}
}
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@
},
"devDependencies": {
"@sourcegraph/prettierrc": "3.0.3",
"@types/fs-extra": "^9.0.11",
"@types/node": "latest",
"opn-cli": "4.1.0",
"prettier": "2.0.4",
"tslint": "5.20.1",
"tslint-config-prettier": "1.18.0"
},
"dependencies": {
"@pulumi/gcp": "2.12.0",
"@pulumi/kubernetes": "1.6.0",
"@pulumi/pulumi": "1.14.0"
"@pulumi/gcp": "5.2.0",
"@pulumi/kubernetes": "3.1.1",
"@pulumi/pulumi": "3.2.1",
"fs-extra": "^10.0.0",
"simple-git": "^2.38.0"
}
}
2 changes: 1 addition & 1 deletion prettier.config.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require("@sourcegraph/prettierrc");
module.exports = require('@sourcegraph/prettierrc')
35 changes: 15 additions & 20 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
{
"compilerOptions": {
"outDir": "bin",
"target": "es6",
"lib": [
"es6"
],
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"experimentalDecorators": true,
"pretty": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"forceConsistentCasingInFileNames": true,
"strictNullChecks": true
},
"files": [
"index.ts"
]
"compilerOptions": {
"outDir": "bin",
"target": "es2016",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"experimentalDecorators": true,
"pretty": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"forceConsistentCasingInFileNames": true,
"strictNullChecks": true,
},
"files": ["index.ts", "config.ts", "cluster.ts"],
}
15 changes: 6 additions & 9 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"defaultSeverity": "error",
"extends": [
"tslint:recommended",
"tslint-config-prettier"
],
"jsRules": {},
"rules": {},
"rulesDirectory": []
}
"defaultSeverity": "error",
"extends": ["tslint:recommended", "tslint-config-prettier"],
"jsRules": {},
"rules": {},
"rulesDirectory": []
}
38 changes: 38 additions & 0 deletions util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import * as path from 'path'
import * as fs from 'fs-extra'

import simpleGit, { SimpleGit } from 'simple-git'

const localCheckoutDir = path.posix.join(__dirname, '.local-deploy-sourcegraph')

export interface PrepareOptions {
skipCleanup?: boolean
}

export async function cloneLocalDSCheckout(ref: string, options?: PrepareOptions): Promise<string> {
const opts: PrepareOptions = {
skipCleanup: false,
...options,
}

if (!opts.skipCleanup) {
await fs.remove(localCheckoutDir)
}
await fs.mkdirp(localCheckoutDir)

const git: SimpleGit = simpleGit({
baseDir: localCheckoutDir,
})

const cloneURL = 'https://github.com/sourcegraph/deploy-sourcegraph.git'

await git
.init()
.addRemote('upstream', cloneURL)
.fetch('upstream', ref, {
'--depth': '1',
})
.checkout('FETCH_HEAD')

return localCheckoutDir
}
Loading

0 comments on commit 7f55c1e

Please sign in to comment.