Update/marketplace info (#1983)

* ensure arch is calways present in config

* add eos version to params when fetching marketplace info

* fix build script

* choose arch based on make goals

* conditionally send different arch param to registry

* better type for qp

Co-authored-by: Matt Hill <matthewonthemoon@gmail.com>
Co-authored-by: Aiden McClelland <me@drbonez.dev>
This commit is contained in:
Lucy C
2022-11-28 13:40:05 -07:00
committed by Aiden McClelland
parent 82fc945d73
commit 3372cdc0df
14 changed files with 68 additions and 50 deletions

View File

@@ -1,4 +1,6 @@
ARCH = $(shell uname -m) RASPI_TARGETS := embassyos-raspi.img embassyos-raspi.tar.gz gzip lite-upgrade.img
ARCH := $(shell if echo $(RASPI_TARGETS) | grep -qw "$(MAKECMDGOALS)"; then echo aarch64; else uname -m; fi)
OS_ARCH := $(shell if echo $(RASPI_TARGETS) | grep -qw "$(MAKECMDGOALS)"; then echo raspberrypi; else uname -m; fi)
ENVIRONMENT_FILE = $(shell ./check-environment.sh) ENVIRONMENT_FILE = $(shell ./check-environment.sh)
GIT_HASH_FILE = $(shell ./check-git-hash.sh) GIT_HASH_FILE = $(shell ./check-git-hash.sh)
VERSION_FILE = $(shell ./check-version.sh) VERSION_FILE = $(shell ./check-version.sh)
@@ -145,6 +147,9 @@ frontend/dist/install-wizard: $(FRONTEND_INSTALL_WIZARD_SRC) $(FRONTEND_SHARED_S
frontend/config.json: $(GIT_HASH_FILE) frontend/config-sample.json frontend/config.json: $(GIT_HASH_FILE) frontend/config-sample.json
jq '.useMocks = false' frontend/config-sample.json > frontend/config.json jq '.useMocks = false' frontend/config-sample.json > frontend/config.json
jq '.packageArch = "$(ARCH)"' frontend/config.json > frontend/config.json.tmp
jq '.osArch = "$(OS_ARCH)"' frontend/config.json.tmp > frontend/config.json
rm frontend/config.json.tmp
npm --prefix frontend run-script build-config npm --prefix frontend run-script build-config
frontend/patchdb-ui-seed.json: frontend/package.json frontend/patchdb-ui-seed.json: frontend/package.json

View File

@@ -1,6 +1,7 @@
{ {
"useMocks": true, "useMocks": true,
"targetArch": "aarch64", "packageArch": "aarch64",
"osArch": "rasberrypi",
"ui": { "ui": {
"api": { "api": {
"url": "rpc", "url": "rpc",

View File

@@ -1,5 +1,6 @@
export type WorkspaceConfig = { export type WorkspaceConfig = {
targetArch: 'aarch64' | 'x86_64' packageArch: 'aarch64' | 'x86_64'
osArch: 'aarch64' | 'x86_64' | 'raspberrypi'
gitHash: string gitHash: string
useMocks: boolean useMocks: boolean
// each key corresponds to a project and values adjust settings for that project, eg: ui, install-wizard, setup-wizard, diagnostic-ui // each key corresponds to a project and values adjust settings for that project, eg: ui, install-wizard, setup-wizard, diagnostic-ui

View File

@@ -3,8 +3,6 @@ import { LoadingController, ModalController } from '@ionic/angular'
import { ApiService } from '../../services/api/embassy-api.service' import { ApiService } from '../../services/api/embassy-api.service'
import { ErrorToastService } from '@start9labs/shared' import { ErrorToastService } from '@start9labs/shared'
import { EOSService } from 'src/app/services/eos.service' import { EOSService } from 'src/app/services/eos.service'
import { PatchDB } from 'patch-db-client'
import { DataModel } from 'src/app/services/patch-db/data-model'
@Component({ @Component({
selector: 'os-update', selector: 'os-update',
@@ -21,7 +19,6 @@ export class OSUpdatePage {
private readonly errToast: ErrorToastService, private readonly errToast: ErrorToastService,
private readonly embassyApi: ApiService, private readonly embassyApi: ApiService,
private readonly eosService: EOSService, private readonly eosService: EOSService,
private readonly patch: PatchDB<DataModel>,
) {} ) {}
ngOnInit() { ngOnInit() {

View File

@@ -308,11 +308,11 @@ export class ServerShowPage {
await loader.present() await loader.present()
try { try {
const updateAvailable = await this.eosService.getEOS() await this.eosService.loadEos()
await loader.dismiss() await loader.dismiss()
if (updateAvailable) { if (this.eosService.updateAvailable$.value) {
this.updateEos() this.updateEos()
} else { } else {
this.presentAlertLatest() this.presentAlertLatest()

View File

@@ -19,7 +19,7 @@ export module Mock {
'update-progress': null, 'update-progress': null,
updated: true, updated: true,
} }
export const MarketplaceEos: RR.GetMarketplaceEOSRes = { export const MarketplaceEos: RR.GetMarketplaceEosRes = {
version: '0.3.3', version: '0.3.3',
headline: 'Our biggest release ever.', headline: 'Our biggest release ever.',
'release-notes': { 'release-notes': {

View File

@@ -244,14 +244,15 @@ export module RR {
// marketplace // marketplace
export type GetMarketplaceInfoReq = { 'server-id': string } export type EnvInfo = {
export type GetMarketplaceInfoRes = StoreInfo
export type GetMarketplaceEOSReq = {
'server-id': string 'server-id': string
'eos-version': string 'eos-version': string
} }
export type GetMarketplaceEOSRes = MarketplaceEOS export type GetMarketplaceInfoReq = EnvInfo
export type GetMarketplaceInfoRes = StoreInfo
export type GetMarketplaceEosReq = EnvInfo
export type GetMarketplaceEosRes = MarketplaceEOS
export type GetMarketplacePackagesReq = { export type GetMarketplacePackagesReq = {
ids?: { id: string; version: string }[] ids?: { id: string; version: string }[]

View File

@@ -101,13 +101,12 @@ export abstract class ApiService {
abstract marketplaceProxy<T>( abstract marketplaceProxy<T>(
path: string, path: string,
params: {}, params: Record<string, unknown>,
url: string, url: string,
arch?: string,
): Promise<T> ): Promise<T>
abstract getEos( abstract getEos(): Promise<RR.GetMarketplaceEosRes>
params: RR.GetMarketplaceEOSReq,
): Promise<RR.GetMarketplaceEOSRes>
// password // password
// abstract updatePassword (params: RR.UpdatePasswordReq): Promise<RR.UpdatePasswordRes> // abstract updatePassword (params: RR.UpdatePasswordReq): Promise<RR.UpdatePasswordRes>

View File

@@ -19,6 +19,7 @@ import { AuthService } from '../auth.service'
import { DOCUMENT } from '@angular/common' import { DOCUMENT } from '@angular/common'
import { DataModel } from '../patch-db/data-model' import { DataModel } from '../patch-db/data-model'
import { PatchDB, pathFromArray, Update } from 'patch-db-client' import { PatchDB, pathFromArray, Update } from 'patch-db-client'
import { getServerInfo } from 'src/app/util/get-server-info'
@Injectable() @Injectable()
export class LiveApiService extends ApiService { export class LiveApiService extends ApiService {
@@ -177,8 +178,14 @@ export class LiveApiService extends ApiService {
// marketplace URLs // marketplace URLs
async marketplaceProxy<T>(path: string, qp: {}, baseUrl: string): Promise<T> { async marketplaceProxy<T>(
Object.assign(qp, { arch: this.config.targetArch }) path: string,
qp: Record<string, string>,
baseUrl: string,
arch: string = this.config.packageArch,
): Promise<T> {
// Object.assign(qp, { arch })
qp['arch'] = arch
const fullUrl = `${baseUrl}${path}?${new URLSearchParams(qp).toString()}` const fullUrl = `${baseUrl}${path}?${new URLSearchParams(qp).toString()}`
return this.rpcRequest({ return this.rpcRequest({
method: 'marketplace.get', method: 'marketplace.get',
@@ -186,13 +193,18 @@ export class LiveApiService extends ApiService {
}) })
} }
async getEos( async getEos(): Promise<RR.GetMarketplaceEosRes> {
params: RR.GetMarketplaceEOSReq, const { id, version } = await getServerInfo(this.patch)
): Promise<RR.GetMarketplaceEOSRes> { const qp: RR.GetMarketplaceEosReq = {
'server-id': id,
'eos-version': version,
}
return this.marketplaceProxy( return this.marketplaceProxy(
'/eos/v0/latest', '/eos/v0/latest',
params, qp,
this.config.marketplace.start9, this.config.marketplace.start9,
this.config.osArch,
) )
} }

View File

@@ -294,7 +294,12 @@ export class MockApiService extends ApiService {
// marketplace URLs // marketplace URLs
async marketplaceProxy(path: string, params: {}, url: string): Promise<any> { async marketplaceProxy(
path: string,
params: Record<string, string>,
url: string,
arch = '',
): Promise<any> {
await pauseFor(2000) await pauseFor(2000)
if (path === '/package/v0/info') { if (path === '/package/v0/info') {
@@ -320,9 +325,7 @@ export class MockApiService extends ApiService {
} }
} }
async getEos( async getEos(): Promise<RR.GetMarketplaceEosRes> {
params: RR.GetMarketplaceEOSReq,
): Promise<RR.GetMarketplaceEOSRes> {
await pauseFor(2000) await pauseFor(2000)
return Mock.MarketplaceEos return Mock.MarketplaceEos
} }

View File

@@ -9,7 +9,8 @@ import {
} from 'src/app/services/patch-db/data-model' } from 'src/app/services/patch-db/data-model'
const { const {
targetArch, packageArch,
osArch,
gitHash, gitHash,
useMocks, useMocks,
ui: { api, marketplace, mocks }, ui: { api, marketplace, mocks },
@@ -25,7 +26,8 @@ export class ConfigService {
version = require('../../../../../package.json').version as string version = require('../../../../../package.json').version as string
useMocks = useMocks useMocks = useMocks
mocks = mocks mocks = mocks
targetArch = targetArch packageArch = packageArch
osArch = osArch
gitHash = gitHash gitHash = gitHash
api = api api = api
marketplace = marketplace marketplace = marketplace

View File

@@ -2,7 +2,6 @@ import { Injectable } from '@angular/core'
import { Emver } from '@start9labs/shared' import { Emver } from '@start9labs/shared'
import { BehaviorSubject, combineLatest } from 'rxjs' import { BehaviorSubject, combineLatest } from 'rxjs'
import { distinctUntilChanged, map } from 'rxjs/operators' import { distinctUntilChanged, map } from 'rxjs/operators'
import { MarketplaceEOS } from 'src/app/services/api/api.types' import { MarketplaceEOS } from 'src/app/services/api/api.types'
import { ApiService } from 'src/app/services/api/embassy-api.service' import { ApiService } from 'src/app/services/api/embassy-api.service'
import { PatchDB } from 'patch-db-client' import { PatchDB } from 'patch-db-client'
@@ -52,14 +51,10 @@ export class EOSService {
private readonly patch: PatchDB<DataModel>, private readonly patch: PatchDB<DataModel>,
) {} ) {}
async getEOS(): Promise<boolean> { async loadEos(): Promise<void> {
const { id, version } = await getServerInfo(this.patch) const { version } = await getServerInfo(this.patch)
this.eos = await this.api.getEos({ this.eos = await this.api.getEos()
'server-id': id,
'eos-version': version,
})
const updateAvailable = this.emver.compare(this.eos.version, version) === 1 const updateAvailable = this.emver.compare(this.eos.version, version) === 1
this.updateAvailable$.next(updateAvailable) this.updateAvailable$.next(updateAvailable)
return updateAvailable
} }
} }

View File

@@ -169,16 +169,18 @@ export class MarketplaceService implements AbstractMarketplaceService {
} }
fetchInfo$(url: string): Observable<StoreInfo> { fetchInfo$(url: string): Observable<StoreInfo> {
return this.patch return this.patch.watch$('server-info').pipe(
.watch$('server-info', 'id') switchMap(serverInfo => {
.pipe( const qp: RR.GetMarketplaceInfoReq = {
switchMap(id => 'server-id': serverInfo.id,
this.api.marketplaceProxy<RR.GetMarketplaceInfoRes>( 'eos-version': serverInfo.version,
}
return this.api.marketplaceProxy<RR.GetMarketplaceInfoRes>(
'/package/v0/info', '/package/v0/info',
{ 'server-d': id }, qp,
url, url,
), )
), }),
) )
} }

View File

@@ -44,7 +44,7 @@ export class PatchDataService extends Observable<DataModel> {
} }
private checkForUpdates(): void { private checkForUpdates(): void {
this.eosService.getEOS() this.eosService.loadEos()
this.marketplaceService.getMarketplace$().pipe(take(1)).subscribe() this.marketplaceService.getMarketplace$().pipe(take(1)).subscribe()
} }