|
| 1 | +import { simpleInstallRequest } from 'helpers/simpleInstallRequest' |
| 2 | +import { initialState } from 'components/DbLabInstanceForm/reducer' |
| 3 | +import { DEBUG_API_SERVER } from 'components/DbLabInstanceForm/utils' |
| 4 | + |
| 5 | +const API_SERVER = process.env.REACT_APP_API_SERVER |
| 6 | + |
| 7 | +const formatExtraEnvs = (extraEnvs: { [key: string]: string }) => { |
| 8 | + return Object.entries(extraEnvs) |
| 9 | + .filter(([key, value]) => value) |
| 10 | + .map(([key, value]) => { |
| 11 | + if (key === 'GCP_SERVICE_ACCOUNT_CONTENTS') { |
| 12 | + return `${key}=${value.replace(/\n\s+/g, '')}` |
| 13 | + } |
| 14 | + return `${key}=${value}` |
| 15 | + }) |
| 16 | +} |
| 17 | + |
| 18 | +export const launchDeploy = async ({ |
| 19 | + state, |
| 20 | + userID, |
| 21 | + orgKey, |
| 22 | + extraEnvs, |
| 23 | + cloudImage, |
| 24 | +}: { |
| 25 | + state: typeof initialState |
| 26 | + orgKey: string |
| 27 | + userID?: number |
| 28 | + extraEnvs: { |
| 29 | + [key: string]: string |
| 30 | + } |
| 31 | + cloudImage: string |
| 32 | +}) => { |
| 33 | + const response = await simpleInstallRequest( |
| 34 | + '/launch', |
| 35 | + { |
| 36 | + method: 'POST', |
| 37 | + body: JSON.stringify({ |
| 38 | + playbook: 'deploy_dle.yml', |
| 39 | + provision: state.provider, |
| 40 | + server: { |
| 41 | + name: state.name, |
| 42 | + serverType: state.instanceType.native_name, |
| 43 | + image: cloudImage, |
| 44 | + location: state.location.native_code, |
| 45 | + }, |
| 46 | + image: 'postgresai/dle-se-ansible:v1.0-rc.8', |
| 47 | + extraVars: [ |
| 48 | + `provision=${state.provider}`, |
| 49 | + `server_name=${state.name}`, |
| 50 | + `dle_platform_project_name=${state.name}`, |
| 51 | + `server_type=${state.instanceType.native_name}`, |
| 52 | + `server_image=${cloudImage}`, |
| 53 | + `server_location=${state.location.native_code}`, |
| 54 | + `volume_size=${state.storage}`, |
| 55 | + `dle_version=${state.tag}`, |
| 56 | + `zpool_datasets_number=${state.snapshots}`, |
| 57 | + `dle_verification_token=${state.verificationToken}`, |
| 58 | + `dle_platform_org_key=${orgKey}`, |
| 59 | + ...(state.publicKeys |
| 60 | + ? // eslint-disable-next-line no-useless-escape |
| 61 | + [`ssh_public_keys=\"${state.publicKeys}\"`] |
| 62 | + : []), |
| 63 | + ...(API_SERVER === DEBUG_API_SERVER |
| 64 | + ? [`dle_platform_url=https://v2.postgres.ai/api/general`] |
| 65 | + : []), |
| 66 | + ], |
| 67 | + extraEnvs: formatExtraEnvs(extraEnvs), |
| 68 | + }), |
| 69 | + }, |
| 70 | + userID, |
| 71 | + ) |
| 72 | + |
| 73 | + return { |
| 74 | + response: response.ok ? await response.json() : null, |
| 75 | + error: response.ok ? null : await response.json(), |
| 76 | + } |
| 77 | +} |
0 commit comments