Skip to content

Commit

Permalink
feat: support new deployer args (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwwinter authored Jul 11, 2024
1 parent ba836f2 commit 7b00317
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pr-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
context: ./
file: ./build/Dockerfile
builder: ${{ steps.buildx.outputs.name }}
push: true
tags: aamdigital/deployer-ms:pr-${{ github.event.number }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
Expand Down
22 changes: 21 additions & 1 deletion integrations/elementor-plugin/form-actions/aam-deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function get_label() {
/**
* Run action.
*
* Submit the data to
* Submit the data to
*
* @since 1.0.0
* @access public
Expand Down Expand Up @@ -72,7 +72,9 @@ public function run( $record, $ajax_handler ) {
'username' => $fields['username'],
'email' => $fields['email'],
'monitor' => $settings['monitor'] ? True : False,
'sentry' => $settings['sentry'] ? True : False,
'backend' => $settings['backend'] ? True : False,
'queryBackend' => $settings['queryBackend'] ? True : False,
'client' => $settings['client'],
'clientKey' => $settings['client-key'],
'base' => $settings['base'],
Expand Down Expand Up @@ -177,6 +179,15 @@ public function register_settings_section( $widget ) {
]
);

$widget->add_control(
'queryBackend',
[
'label' => esc_html__( 'Add am-backend-services (query-backend)', 'elementor-forms-aam-deploy' ),
'type' => \Elementor\Controls_Manager::SWITCHER,
'description' => esc_html__( 'Deploys aam-backend-services (e.g. reports).', 'elementor-forms-aam-deploy' ),
]
);

$widget->add_control(
'monitor',
[
Expand All @@ -186,6 +197,15 @@ public function register_settings_section( $widget ) {
]
);

$widget->add_control(
'sentry',
[
'label' => esc_html__( 'Add sentry monitoring', 'elementor-forms-aam-deploy' ),
'type' => \Elementor\Controls_Manager::SWITCHER,
'description' => esc_html__( 'Adds sentry monitoring for the deployment.', 'elementor-forms-aam-deploy' ),
]
);

$widget->add_control(
'msg_name_exists',
[
Expand Down
12 changes: 7 additions & 5 deletions src/app.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ describe('AppController', () => {
clientKey: 'test-key',
base: 'test-base',
backend: true,
queryBackend: true,
monitor: false,
sentry: false,
};

beforeEach(async () => {
Expand Down Expand Up @@ -149,7 +151,7 @@ describe('AppController', () => {
await expect(testMail('[email protected]')).resolves.toBeTruthy();
});

it('should throw error if ERROR is written to log', async () => {
xit('should throw error if ERROR is written to log', async () => {
const res = firstValueFrom(controller.deployApp(deploymentData));
lines.next('some logs');
lines.next('ERROR my custom error');
Expand All @@ -167,14 +169,14 @@ describe('AppController', () => {
throw new Error('No error thrown');
});

it('should write arguments to file', () => {
xit('should write arguments to file', () => {
const res = firstValueFrom(controller.deployApp(deploymentData));

lines.next('DONE');

expect(res).resolves.toBeTruthy();
expect(mockWs.write).toHaveBeenCalledWith(
'test-name de [email protected] test-username test-base y n',
'test-name test-base de [email protected] test-username y y n n\n',
);
expect(mockWs.close).toHaveBeenCalled();
// Ensure tail is properly "unwatched"
Expand All @@ -185,7 +187,7 @@ describe('AppController', () => {
const emptyLocale = { ...deploymentData, locale: '' };
controller.deployApp(emptyLocale).subscribe(() => {
expect(mockWs.write).toHaveBeenCalledWith(
'test-name en [email protected] test-username test-base y n',
'test-name test-base en [email protected] test-username y y n n\n',
);
done();
});
Expand All @@ -198,7 +200,7 @@ describe('AppController', () => {
delete noLocale.locale;
controller.deployApp(noLocale).subscribe(() => {
expect(mockWs.write).toHaveBeenCalledWith(
'test-name en [email protected] test-username test-base y n',
'test-name test-base en [email protected] test-username y y n n\n',
);
done();
});
Expand Down
16 changes: 10 additions & 6 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { DeploymentInfo } from './deployment-info.dto';
import * as fs from 'fs';
import { HttpService } from '@nestjs/axios';
import { ConfigService } from '@nestjs/config';
import { catchError, mergeMap, Observable, Subject } from 'rxjs';
import { catchError, mergeMap, Observable, of, Subject } from 'rxjs';
import { Tail } from 'tail';

@Controller()
Expand Down Expand Up @@ -69,16 +69,20 @@ export class AppController {
throw new BadRequestException('No spaces allowed in arguments');
}

const args = `${deploymentInfo.name} ${deploymentInfo.locale || 'en'} ${
deploymentInfo.email
} ${deploymentInfo.username} ${deploymentInfo.base} ${
const args = `${deploymentInfo.name} ${deploymentInfo.base} ${
deploymentInfo.locale || 'en'
} ${deploymentInfo.email} ${deploymentInfo.username} ${
deploymentInfo.backend ? 'y' : 'n'
} ${deploymentInfo.monitor ? 'y' : 'n'}`;
} ${deploymentInfo.queryBackend ? 'y' : 'n'} ${
deploymentInfo.monitor ? 'y' : 'n'
} ${deploymentInfo.sentry ? 'y' : 'n'}\n`;
console.log('args', args);
const ws = fs.createWriteStream('dist/assets/arg-pipe');
ws.write(args);
ws.close();
return this.getResult();
return of(true);
// TODO: checking logs may take too long and run into timeouts for user-facing form. Therefore deactivated for now.
// return this.getResult();
}

private getResult() {
Expand Down
11 changes: 11 additions & 0 deletions src/deployment-info.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,22 @@ export class DeploymentInfo {
})
backend: boolean;

@ApiProperty({
description:
'Whether the am-backend-services (query-backend) should be set up.',
})
queryBackend = false;

@ApiProperty({
description: 'Whether the new system should be added to uptime monitoring.',
})
monitor: boolean;

@ApiProperty({
description: 'Whether the new system should be added to sentry monitoring.',
})
sentry = false;

@ApiProperty({
description: 'Name of the Keycloak confidential client.',
})
Expand Down

0 comments on commit 7b00317

Please sign in to comment.