Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Fixed bugs in project auto-update. #7442

Merged
merged 1 commit into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ COPY packages/server-core/package.json ./packages/server-core/
COPY packages/taskserver/package.json ./packages/taskserver/
COPY packages/projects/package.json ./packages/projects/
COPY project-package-jsons ./
COPY patches/ ./patches/

#RUN npm ci --verbose # we should make lockfile or shrinkwrap then use npm ci for predicatble builds

Expand Down
35 changes: 7 additions & 28 deletions packages/server-core/src/projects/project/project-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ export const getCronJobBody = (project: ProjectInterface, image: string): object
}
}

export const createProjectUpdateJob = async (app: Application, projectName: string): Promise<void> => {
export const createOrUpdateProjectUpdateJob = async (app: Application, projectName: string): Promise<void> => {
const project = await app.service('project').Model.findOne({
where: {
name: projectName
Expand All @@ -845,31 +845,8 @@ export const createProjectUpdateJob = async (app: Application, projectName: stri

const image = apiPods.pods[0].containers.find((container) => container.name === 'xrengine')!.image

try {
if (app.k8BatchClient) await app.k8BatchClient.createNamespacedCronJob('default', getCronJobBody(project, image))
} catch (err) {
logger.error('Failed to create project update cronjob %o', err)
}
}

export const updateProjectUpdateJob = async (app: Application, projectName: string): Promise<void> => {
const project = await app.service('project').Model.findOne({
where: {
name: projectName
}
})

const apiPods = await getPodsData(
`app.kubernetes.io/instance=${config.server.releaseName},app.kubernetes.io/component=api`,
'api',
'Api',
app
)

const image = apiPods.pods[0].containers.find((container) => container.name === 'xrengine')!.image

try {
if (app.k8BatchClient)
if (app.k8BatchClient) {
try {
await app.k8BatchClient.patchNamespacedCronJob(
`${process.env.RELEASE_NAME}-${projectName}-auto-update`,
'default',
Expand All @@ -884,8 +861,10 @@ export const updateProjectUpdateJob = async (app: Application, projectName: stri
}
}
)
} catch (err) {
logger.error('Failed to patch project update cronjob %o', err)
} catch (err) {
logger.error('Could not find cronjob %o', err)
await app.k8BatchClient.createNamespacedCronJob('default', getCronJobBody(project, image))
}
}
}

Expand Down
8 changes: 3 additions & 5 deletions packages/server-core/src/projects/project/project.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ import {
getUserRepos
} from './github-helper'
import {
createProjectUpdateJob,
createOrUpdateProjectUpdateJob,
getEnginePackageJson,
getProjectConfig,
getProjectPackageJson,
onProjectEvent,
removeProjectUpdateJob,
updateProjectUpdateJob
removeProjectUpdateJob
} from './project-helper'

const templateFolderDirectory = path.join(appRootPath.path, `packages/projects/template-project/`)
Expand Down Expand Up @@ -490,8 +489,7 @@ export class Project extends Service {
}

if (this.app.k8BatchClient && (data.updateType === 'tag' || data.updateType === 'commit')) {
if (!existingProjectResult) await createProjectUpdateJob(this.app, projectName)
else await updateProjectUpdateJob(this.app, projectName)
await createOrUpdateProjectUpdateJob(this.app, projectName)
} else if (this.app.k8BatchClient && (data.updateType === 'none' || data.updateType == null))
await removeProjectUpdateJob(this.app, projectName)

Expand Down
30 changes: 22 additions & 8 deletions scripts/update-cronjob-image.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import appRootPath from 'app-root-path'
import cli from 'cli'
import dotenv from 'dotenv-flow'
import {createFeathersExpressApp} from "@xrengine/server-core/src/createApp";
import {ServerMode} from "@xrengine/server-core/declarations";
import {getCronJobBody} from "@xrengine/server-core/src/projects/project/project-helper";

import { ServerMode } from '@xrengine/server-core/declarations'
import { createFeathersExpressApp } from '@xrengine/server-core/src/createApp'
import { getCronJobBody } from '@xrengine/server-core/src/projects/project/project-helper'

dotenv.config({
path: appRootPath.path,
Expand Down Expand Up @@ -49,11 +50,24 @@ cli.main(async () => {
})
if (app.k8BatchClient)
for (const project of autoUpdateProjects.data) {
await app.k8BatchClient.patchNamespacedCronJob(`${process.env.RELEASE_NAME}-${project.name}-auto-update`, 'default', getCronJobBody(project, `${options.ecrUrl}/${options.repoName}-api:${options.tag}__${options.startTime}`), undefined, undefined, undefined, undefined, {
headers: {
'content-type': "application/merge-patch+json"
}
})
try {
await app.k8BatchClient.patchNamespacedCronJob(
`${process.env.RELEASE_NAME}-${project.name}-auto-update`,
'default',
getCronJobBody(project, `${options.ecrUrl}/${options.repoName}-api:${options.tag}__${options.startTime}`),
undefined,
undefined,
undefined,
undefined,
{
headers: {
'content-type': 'application/merge-patch+json'
}
}
)
} catch (err) {
console.log('Missing cronjob', `${process.env.RELEASE_NAME}-${project.name}-auto-update`)
}
}
cli.exit(0)
} catch (err) {
Expand Down