Skip to content

Commit 7f55c1e

Browse files
authored
update severely outdated package versions (#78)
1 parent bef5279 commit 7f55c1e

15 files changed

+620
-876
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ yarn-error.log
1111
.history
1212

1313
.envrc
14+
.local-deploy-sourcegraph
1415

1516
Pulumi.dev.yaml

Diff for: .nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
12.16.1
1+
14.16.1

Diff for: .prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.local-deploy-sourcegraph/

Diff for: .tool-versions

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
yarn 1.22.4
22
kubectl 1.17.3
33
fd 7.4.0
4-
pulumi 1.14.0
4+
pulumi 3.2.1

Diff for: .vscode/settings.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"editor.formatOnSave": true
3-
}
2+
"editor.formatOnSave": true,
3+
}

Diff for: README.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
# deploy-k8s-helper
1+
# deploy-k8s-helper
22

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

5-
## Prerequisites
5+
## Prerequisites
66

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

1515
### Configuration
1616

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

19-
- `gcloudEmail` - The email that you use to sign in to our GCP project.
20-
- example: [email protected]
19+
- `gcloudEmail` - The email that you use to sign in to our GCP project.
20+
- example: [email protected]
2121
- `deploySourcegraphRoot` - The path to the root of your https://github.com/sourcegraph/deploy-sourcegraph checkout.
22-
- example: /Users/ggilmore/dev/go/src/github.com/sourcegraph/deploy-sourcegraph
22+
- example: /Users/ggilmore/dev/go/src/github.com/sourcegraph/deploy-sourcegraph
2323

24-
## Usage
24+
## Usage
2525

26-
Run `yarn` so that you install all the necessary dependencies.
26+
Run `yarn` so that you install all the necessary dependencies.
2727

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

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

60-
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`).
60+
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`).
6161

6262
Example:
6363

Diff for: cluster.ts

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const cluster = new gcp.container.Cluster(name, {
1919
project: gcloudConfig.project,
2020

2121
initialNodeCount: clusterConfig.nodeCount,
22-
removeDefaultNodePool: true,
2322

2423
nodeConfig: {
2524
diskType: 'pd-ssd',

Diff for: config.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ export const clusterConfig = {
1414
* The number of nodes to create in this cluster.
1515
* Defaults to 4.
1616
*/
17-
nodeCount: config.getNumber('nodeCount') || 4,
17+
nodeCount: config.getNumber('nodeCount') || 3,
1818

1919
/**
2020
* The name of a Google Compute Engine machine type.
2121
* Defaults to n1-standard-8.
2222
*/
23-
machineType: config.get('machineType') || 'n1-standard-8',
23+
machineType: config.get('machineType') || 'n1-standard-16',
2424
}
2525

2626
export const gcloudConfig = {
@@ -47,4 +47,6 @@ export const gcloudConfig = {
4747
* The path to the root of your sourcegraph/deploy-sourcegraph checkout.
4848
* Example: /Users/ggilmore/dev/go/src/github.com/sourcegraph/deploy-sourcegraph
4949
*/
50-
export const deploySourcegraphRoot = config.require('deploySourcegraphRoot')
50+
export const deploySourcegraphLocalRoot = config.get('deploySourcegraphLocalRoot')
51+
52+
export const deploySourcegraphRef = config.get('deploySourcegraphRef') || 'master'

Diff for: index.ts

+66-54
Original file line numberDiff line numberDiff line change
@@ -3,71 +3,83 @@ import * as path from 'path'
33

44
import * as k8s from '@pulumi/kubernetes'
55

6-
import { k8sProvider } from './cluster'
7-
import { deploySourcegraphRoot, gcloudConfig } from './config'
6+
import { deploySourcegraphLocalRoot, gcloudConfig, deploySourcegraphRef } from './config'
7+
import { cloneLocalDSCheckout } from './util'
8+
import * as cluster from './cluster'
89

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

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

20-
subjects: [
21-
{
18+
roleRef: {
2219
apiGroup: 'rbac.authorization.k8s.io',
23-
kind: 'User',
24-
name: gcloudConfig.username,
20+
kind: 'ClusterRole',
21+
name: 'cluster-admin',
2522
},
26-
],
27-
},
28-
{ provider: k8sProvider }
29-
)
3023

31-
const storageClass = new k8s.storage.v1.StorageClass(
32-
'sourcegraph-storage-class',
33-
{
34-
metadata: {
35-
name: 'sourcegraph',
24+
subjects: [
25+
{
26+
apiGroup: 'rbac.authorization.k8s.io',
27+
kind: 'User',
28+
name: gcloudConfig.username,
29+
},
30+
],
31+
},
32+
{ provider: k8sProvider }
33+
)
34+
35+
const storageClass = new k8s.storage.v1.StorageClass(
36+
'sourcegraph-storage-class',
37+
{
38+
metadata: {
39+
name: 'sourcegraph',
3640

37-
labels: {
38-
deploy: 'sourcegraph',
41+
labels: {
42+
deploy: 'sourcegraph',
43+
},
3944
},
40-
},
41-
provisioner: 'kubernetes.io/gce-pd',
45+
provisioner: 'kubernetes.io/gce-pd',
4246

43-
parameters: {
44-
type: 'pd-ssd',
47+
parameters: {
48+
type: 'pd-ssd',
49+
},
4550
},
46-
},
47-
{ provider: k8sProvider }
48-
)
51+
{ provider: k8sProvider }
52+
)
4953

50-
const baseDeployment = new k8s.yaml.ConfigGroup(
51-
'base',
52-
{
53-
files: `${path.posix.join(deploySourcegraphRoot, 'base')}/**/*.yaml`,
54-
},
55-
{
56-
providers: { kubernetes: k8sProvider },
57-
dependsOn: [clusterAdmin, storageClass],
58-
}
59-
)
54+
const deploySourcegraphRoot = deploySourcegraphLocalRoot
55+
? deploySourcegraphLocalRoot
56+
: await cloneLocalDSCheckout(deploySourcegraphRef)
6057

61-
const ingressNginx = new k8s.yaml.ConfigGroup(
62-
'ingress-nginx',
63-
{
64-
files: `${path.posix.join(deploySourcegraphRoot, 'configure', 'ingress-nginx')}/**/*.yaml`,
65-
},
66-
{ providers: { kubernetes: k8sProvider }, dependsOn: clusterAdmin }
67-
)
58+
const baseDeployment = new k8s.yaml.ConfigGroup(
59+
'base',
60+
{
61+
files: `${path.posix.join(deploySourcegraphRoot, 'base')}/**/*.yaml`,
62+
},
63+
{
64+
providers: { kubernetes: k8sProvider },
65+
dependsOn: [clusterAdmin, storageClass],
66+
}
67+
)
6868

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

73-
export * from './cluster'
77+
const ingressIPs = ingressNginx
78+
.getResource('v1/Service', 'ingress-nginx', 'ingress-nginx')
79+
.apply(svc => svc.status.apply(status => status.loadBalancer.ingress.map(i => i.ip)))
80+
81+
return {
82+
ingressIPs,
83+
...cluster,
84+
}
85+
}

Diff for: package.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@
1313
},
1414
"devDependencies": {
1515
"@sourcegraph/prettierrc": "3.0.3",
16+
"@types/fs-extra": "^9.0.11",
1617
"@types/node": "latest",
1718
"opn-cli": "4.1.0",
1819
"prettier": "2.0.4",
1920
"tslint": "5.20.1",
2021
"tslint-config-prettier": "1.18.0"
2122
},
2223
"dependencies": {
23-
"@pulumi/gcp": "2.12.0",
24-
"@pulumi/kubernetes": "1.6.0",
25-
"@pulumi/pulumi": "1.14.0"
24+
"@pulumi/gcp": "5.2.0",
25+
"@pulumi/kubernetes": "3.1.1",
26+
"@pulumi/pulumi": "3.2.1",
27+
"fs-extra": "^10.0.0",
28+
"simple-git": "^2.38.0"
2629
}
2730
}

Diff for: prettier.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = require("@sourcegraph/prettierrc");
1+
module.exports = require('@sourcegraph/prettierrc')

Diff for: tsconfig.json

+15-20
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
{
2-
"compilerOptions": {
3-
"outDir": "bin",
4-
"target": "es6",
5-
"lib": [
6-
"es6"
7-
],
8-
"module": "commonjs",
9-
"moduleResolution": "node",
10-
"sourceMap": true,
11-
"experimentalDecorators": true,
12-
"pretty": true,
13-
"noFallthroughCasesInSwitch": true,
14-
"noImplicitAny": true,
15-
"noImplicitReturns": true,
16-
"forceConsistentCasingInFileNames": true,
17-
"strictNullChecks": true
18-
},
19-
"files": [
20-
"index.ts"
21-
]
2+
"compilerOptions": {
3+
"outDir": "bin",
4+
"target": "es2016",
5+
"module": "commonjs",
6+
"moduleResolution": "node",
7+
"sourceMap": true,
8+
"experimentalDecorators": true,
9+
"pretty": true,
10+
"noFallthroughCasesInSwitch": true,
11+
"noImplicitAny": true,
12+
"noImplicitReturns": true,
13+
"forceConsistentCasingInFileNames": true,
14+
"strictNullChecks": true,
15+
},
16+
"files": ["index.ts", "config.ts", "cluster.ts"],
2217
}

Diff for: tslint.json

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
{
2-
"defaultSeverity": "error",
3-
"extends": [
4-
"tslint:recommended",
5-
"tslint-config-prettier"
6-
],
7-
"jsRules": {},
8-
"rules": {},
9-
"rulesDirectory": []
10-
}
2+
"defaultSeverity": "error",
3+
"extends": ["tslint:recommended", "tslint-config-prettier"],
4+
"jsRules": {},
5+
"rules": {},
6+
"rulesDirectory": []
7+
}

Diff for: util.ts

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import * as path from 'path'
2+
import * as fs from 'fs-extra'
3+
4+
import simpleGit, { SimpleGit } from 'simple-git'
5+
6+
const localCheckoutDir = path.posix.join(__dirname, '.local-deploy-sourcegraph')
7+
8+
export interface PrepareOptions {
9+
skipCleanup?: boolean
10+
}
11+
12+
export async function cloneLocalDSCheckout(ref: string, options?: PrepareOptions): Promise<string> {
13+
const opts: PrepareOptions = {
14+
skipCleanup: false,
15+
...options,
16+
}
17+
18+
if (!opts.skipCleanup) {
19+
await fs.remove(localCheckoutDir)
20+
}
21+
await fs.mkdirp(localCheckoutDir)
22+
23+
const git: SimpleGit = simpleGit({
24+
baseDir: localCheckoutDir,
25+
})
26+
27+
const cloneURL = 'https://github.com/sourcegraph/deploy-sourcegraph.git'
28+
29+
await git
30+
.init()
31+
.addRemote('upstream', cloneURL)
32+
.fetch('upstream', ref, {
33+
'--depth': '1',
34+
})
35+
.checkout('FETCH_HEAD')
36+
37+
return localCheckoutDir
38+
}

0 commit comments

Comments
 (0)