Skip to content

Commit

Permalink
fix(worker): don't fail update if app is not correctly stopping
Browse files Browse the repository at this point in the history
  • Loading branch information
nicotsx committed Dec 10, 2023
1 parent e6aab9c commit 2b39f73
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
37 changes: 37 additions & 0 deletions packages/worker/src/services/app/__tests__/app.executors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,41 @@ describe('test: app executors', () => {
spy.mockRestore();
});
});

describe('test: updateApp()', () => {
it('should still update even if current compose file is broken', async () => {
// arrange
const spy = vi.spyOn(dockerHelpers, 'compose');
const config = createAppConfig();

spy.mockRejectedValueOnce(new Error('test'));
spy.mockResolvedValueOnce({ stdout: 'done', stderr: '' });

// act
const { message, success } = await appExecutors.updateApp(config.id, config);

// assert
expect(success).toBe(true);
expect(message).toBe(`App ${config.id} updated successfully`);
spy.mockRestore();
});

it('should replace app directory with new one', async () => {
// arrange
const config = createAppConfig();
const oldFolder = path.join(ROOT_FOLDER, 'apps', config.id);

await fs.promises.writeFile(path.join(oldFolder, 'docker-compose.yml'), 'test');

// act
await appExecutors.updateApp(config.id, config);

// assert
const exists = await pathExists(oldFolder);
const content = await fs.promises.readFile(path.join(oldFolder, 'docker-compose.yml'), 'utf-8');

expect(exists).toBe(true);
expect(content).not.toBe('test');
});
});
});
8 changes: 6 additions & 2 deletions packages/worker/src/services/app/app.executors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,12 @@ export class AppExecutors {
await this.ensureAppDir(appId);
await generateEnvFile(appId, config);

await compose(appId, 'up --detach --force-recreate --remove-orphans');
await compose(appId, 'down --rmi all --remove-orphans');
try {
await compose(appId, 'up --detach --force-recreate --remove-orphans');
await compose(appId, 'down --rmi all --remove-orphans');
} catch (err) {
logger.warn(`App ${appId} has likely a broken docker-compose.yml file. Continuing with update...`);
}

this.logger.info(`Deleting folder ${appDirPath}`);
await fs.promises.rm(appDirPath, { recursive: true, force: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ export const InstallForm: React.FC<IProps> = ({ formFields, info, onSubmit, init
defaultValue={false}
render={({ field: { onChange, value, ref, ...props } }) => (
<Switch
{...props}
className="mb-3"
disabled={info.force_expose}
ref={ref}
checked={value}
onCheckedChange={onChange}
{...props}
disabled={info.force_expose}
label={t('expose-app')}
/>
)}
Expand Down

0 comments on commit 2b39f73

Please sign in to comment.