Skip to content

Commit dd7f6f9

Browse files
authored
All in one dogfood deploy script (#2300)
* all in one dogfood deploy script * do it in parallel. yeehaw
1 parent 8febc79 commit dd7f6f9

File tree

3 files changed

+83
-23
lines changed

3 files changed

+83
-23
lines changed

.eslintrc.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ module.exports = {
9292
'react/react-in-jsx-scope': 'off',
9393
'react/prop-types': 'off',
9494
},
95-
ignorePatterns: ['dist/', 'node_modules/'],
95+
ignorePatterns: ['dist/', 'node_modules/', 'tools/deno/'],
9696
overrides: [
9797
{
9898
// default export is needed in config files

tools/deno/deploy-dogfood.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#! /usr/bin/env -S deno run --allow-run --allow-net --allow-read --allow-write --allow-env
2+
3+
/*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
7+
*
8+
* Copyright Oxide Computer Company
9+
*/
10+
import $ from 'jsr:@david/dax@0.41.0'
11+
import { parseArgs } from 'jsr:@std/cli@0.224.7'
12+
13+
// This script will not work unless you have the following helpful bits in your SSH config:
14+
//
15+
// Host gc*
16+
// StrictHostKeyChecking no
17+
// UserKnownHostsFile /dev/null
18+
// User root
19+
// ProxyCommand ssh jeeves.eng.oxide.computer pilot tp nc any $(echo "%h" | sed s/gc//) %p
20+
// ServerAliveInterval 15
21+
// ForwardAgent yes
22+
//
23+
// host jeeves
24+
// hostname %h.eng.oxide.computer
25+
// user <your actual username>
26+
// ForwardAgent yes
27+
28+
const USAGE = `
29+
Usage:
30+
31+
tools/deno/dogfood-deploy.ts <console commit hash>
32+
`.trim()
33+
34+
const args = parseArgs(Deno.args)
35+
const consoleCommit = args._[0]
36+
37+
if (!consoleCommit) {
38+
console.error('Error: Console commit hash is required\n')
39+
console.log(USAGE)
40+
Deno.exit(1)
41+
}
42+
43+
console.log('Finding nexus zones...')
44+
const zones: string = await $`./tools/dogfood/find-zone.sh nexus`.text()
45+
const gimletNums = zones
46+
.split('\n')
47+
.filter((line) => line.includes('nexus'))
48+
.map((line) => line.trim().split(' ')[0])
49+
50+
console.log(`Found: ${JSON.stringify(gimletNums)}\n`)
51+
52+
const TARBALL_URL = `https://dl.oxide.computer/releases/console/${consoleCommit}.tar.gz`
53+
const TARBALL_FILE = '/tmp/console.tar.gz'
54+
55+
console.log(`Downloading tarball to ${TARBALL_FILE}`)
56+
await $`curl --show-error --fail --location --output ${TARBALL_FILE} ${TARBALL_URL}`
57+
console.log(`Done downloading.\n`)
58+
59+
const go = await $.confirm(`Deploy console to gimlets ${JSON.stringify(gimletNums)}?`)
60+
if (!go) {
61+
console.log('Deploy aborted')
62+
Deno.exit()
63+
}
64+
65+
async function deploy(num: string) {
66+
console.log(`Deploying to gimlet ${num}...`)
67+
await $`./tools/dogfood/scp-assets.sh gc${num} ${TARBALL_FILE}`
68+
console.log(`Done with gimlet ${num}...`)
69+
}
70+
71+
await Promise.all(gimletNums.map(deploy))

tools/dogfood/scp-assets.sh

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,30 @@ set -o pipefail
1111

1212
# What this does:
1313
#
14-
# 1. Download console tarball (restricts this to use on commits pushed to console main)
15-
# 2. SCP tarball to gimlet
16-
# 3. Over SSH:
14+
# 1. SCP tarball to gimlet
15+
# 2. Over SSH:
1716
# a. Extract tarball to tmp dir next to static dir
1817
# b. Delete tarball
1918
# c. Rename tmp dir to static dir
2019
#
2120
# Usage:
2221
#
23-
# First use `find-zone.sh nexus` to find the gimlets running nexus, then run this
24-
#
25-
# ./scp-assets.sh gc21 1234567890abcdef1234567890abcdef12345678
26-
#
27-
# If you want to do more than one, use a loop
28-
#
29-
# for gimlet in gc8 gc12 gc21; do
30-
# .scp-assets.sh $gimlet 99173b920969e95d9d025d0038b8ffdb4c46c0ec
31-
# done
22+
# The primary intended usage is to use tools/deno/deploy-dogfood.ts, which first
23+
# uses find-zone.sh to find the nexus gimlets and then downloads the tarball
24+
# and calls this script on each one. To use this script directly, do what that
25+
# script does.
26+
27+
28+
STATIC_DIR="static"
29+
TMP_DIR="static-tmp"
3230

3331
GIMLET="$1"
34-
COMMIT="$2"
32+
TARBALL_FILE="$2"
3533

3634
# kinda silly but we have to find the zone name, then we use the log file name to infer the nexus dir
3735
LOG_FILE=$(ssh $GIMLET 'NEXUS_ZONE=$(pfexec svcs -H -o ZONE -Z nexus); LOG_FILE=$(pfexec svcs -z $NEXUS_ZONE -L svc:/oxide/nexus:default); echo $LOG_FILE')
3836
NEXUS_DIR="$(echo $LOG_FILE | sed 's/\/svc\/log.*//')/nexus"
3937

40-
STATIC_DIR="static"
41-
TMP_DIR="static-tmp"
42-
TARBALL_URL="https://dl.oxide.computer/releases/console/$COMMIT.tar.gz"
43-
TARBALL_FILE="/tmp/console.tar.gz"
44-
45-
echo 'downloading console tarball...'
46-
curl --silent --show-error --fail --location --output $TARBALL_FILE $TARBALL_URL
47-
echo 'done. now scping it to the gimlet...'
48-
4938
scp -r $TARBALL_FILE "$GIMLET:$NEXUS_DIR/"
5039

5140
ssh $GIMLET <<SSH_EOF

0 commit comments

Comments
 (0)