Skip to content

Commit

Permalink
fix(app): Fix paths to BR premigration wheels on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mcous committed Aug 21, 2019
1 parent 3c0d2a9 commit 0ff8638
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 52 deletions.
7 changes: 0 additions & 7 deletions app-shell/electron-builder.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@
"build/br-premigration-wheels",
"!Makefile"
],
"extraResources": [
{
"from": "../api/dist",
"to": "./api/dist",
"filter": ["**/*"]
}
],
"artifactName": "${productName}-v${version}-${os}-${env.BUILD_ID}.${ext}",
"asar": true,
"mac": {
Expand Down
1 change: 0 additions & 1 deletion app-shell/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"form-data": "^2.5.0",
"fs-extra": "^6.0.1",
"get-stream": "^5.1.0",
"globby": "^10.0.1",
"merge-options": "^1.0.1",
"node-fetch": "^2.6.0",
"node-stream-zip": "^1.8.2",
Expand Down
16 changes: 5 additions & 11 deletions app-shell/src/buildroot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ import { getConfig } from '../config'
import { CURRENT_VERSION } from '../update'
import { downloadManifest, getReleaseSet } from './release-manifest'
import { getReleaseFiles, readUserFileInfo } from './release-files'
import {
getPremigrationWheels,
startPremigration,
uploadSystemFile,
} from './update'
import { startPremigration, uploadSystemFile } from './update'

import type { Action, Dispatch } from '../types'
import type { ReleaseSetUrls, ReleaseSetFilepaths } from './types'
Expand Down Expand Up @@ -44,11 +40,9 @@ export function registerBuildrootUpdate(dispatch: Dispatch) {
case 'buildroot:START_PREMIGRATION': {
const robot = action.payload

getPremigrationWheels()
.then(wheels => {
log.info('Starting robot premigration', { robot, wheels })
return startPremigration(robot, wheels.api, wheels.updateServer)
})
log.info('Starting robot premigration', { robot })

startPremigration(robot)
.then(
(): BuildrootAction => ({
type: 'buildroot:PREMIGRATION_DONE',
Expand All @@ -58,7 +52,7 @@ export function registerBuildrootUpdate(dispatch: Dispatch) {
.catch(
(error: Error): BuildrootAction => ({
type: 'buildroot:PREMIGRATION_ERROR',
payload: error.message,
payload: { message: error.message },
})
)
.then(dispatch)
Expand Down
43 changes: 11 additions & 32 deletions app-shell/src/buildroot/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
// start a buildroot migration by POSTing the necessary wheel files to a robot
// and restarting

import assert from 'assert'
import path from 'path'
import globby from 'globby'

import { fetch, postFile } from '../http'
import type { RobotHost } from '@opentrons/app/src/robot-api'
Expand All @@ -14,42 +12,23 @@ const PREMIGRATION_WHL_DIR = path.join(
'../../build/br-premigration-wheels'
)

const API_WHL_PATTERN = path.join(PREMIGRATION_WHL_DIR, 'opentrons-*.whl')
const SERVER_WHL_PATTERN = path.join(PREMIGRATION_WHL_DIR, 'otupdate-*.whl')
const PREMIGRATION_API_WHL = path.join(
PREMIGRATION_WHL_DIR,
'opentrons-3.10.3-py2.py3-none-any.whl'
)
const PREMIGRATION_SERVER_WHL = path.join(
PREMIGRATION_WHL_DIR,
'otupdate-3.10.3-py2.py3-none-any.whl'
)
const SYSTEM_FILENAME = 'ot2-system.zip'

const getWheel = (pattern: string): Promise<string> =>
globby(pattern).then(matches => {
assert(
matches.length === 1,
`Expected 1 file to match ${pattern}, found [${matches.join(', ')}]`
)
return matches[0]
})

export function getPremigrationWheels(): Promise<{
api: string,
updateServer: string,
}> {
const getApiWheel = getWheel(API_WHL_PATTERN)
const getServerWheel = getWheel(SERVER_WHL_PATTERN)

return Promise.all([getApiWheel, getServerWheel]).then(
([api, updateServer]) => ({ api, updateServer })
)
}

export function startPremigration(
robot: RobotHost,
apiWheelPath: string,
serverWheelPath: string
): Promise<mixed> {
export function startPremigration(robot: RobotHost): Promise<mixed> {
const apiUrl = `http://${robot.ip}:${robot.port}/server/update`
const serverUrl = `http://${robot.ip}:${robot.port}/server/update/bootstrap`
const restartUrl = `http://${robot.ip}:${robot.port}/server/restart`

return postFile(apiUrl, 'whl', apiWheelPath)
.then(() => postFile(serverUrl, 'whl', serverWheelPath))
return postFile(apiUrl, 'whl', PREMIGRATION_API_WHL)
.then(() => postFile(serverUrl, 'whl', PREMIGRATION_SERVER_WHL))
.then(() => fetch(restartUrl, { method: 'POST' }))
}

Expand Down
24 changes: 24 additions & 0 deletions app/src/shell/buildroot/__tests__/reducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,30 @@ describe('app/shell/buildroot reducer', () => {
initialState: { ...INITIAL_STATE, session: BASE_SESSION },
expected: { ...INITIAL_STATE, session: null },
},
{
name: 'handles buildroot:UNEXPECTED_ERROR',
action: {
type: 'buildroot:UNEXPECTED_ERROR',
payload: { message: 'AH!' },
},
initialState: { ...INITIAL_STATE, info: null },
expected: {
...INITIAL_STATE,
session: { ...INITIAL_STATE.session, error: 'AH!' },
},
},
{
name: 'handles buildroot:PREMIGRATION_ERROR',
action: {
type: 'buildroot:PREMIGRATION_ERROR',
payload: { message: 'AH!' },
},
initialState: { ...INITIAL_STATE, info: null },
expected: {
...INITIAL_STATE,
session: { ...INITIAL_STATE.session, error: 'AH!' },
},
},
]

SPECS.forEach(spec => {
Expand Down
1 change: 1 addition & 0 deletions app/src/shell/buildroot/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export function buildrootReducer(
case actions.BR_CLEAR_SESSION:
return { ...state, session: null }

case actions.BR_PREMIGRATION_ERROR:
case actions.BR_UNEXPECTED_ERROR:
return {
...state,
Expand Down
2 changes: 1 addition & 1 deletion app/src/shell/buildroot/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export type BuildrootAction =
meta: {| shell: true |},
|}
| {| type: 'buildroot:PREMIGRATION_DONE', payload: string |}
| {| type: 'buildroot:PREMIGRATION_ERROR', payload: string |}
| {| type: 'buildroot:PREMIGRATION_ERROR', payload: {| message: string |} |}
| {|
type: 'buildroot:READ_USER_FILE',
payload: {| systemFile: string |},
Expand Down

0 comments on commit 0ff8638

Please sign in to comment.