Skip to content

Commit

Permalink
Fixes to batch job under esm, go lang support
Browse files Browse the repository at this point in the history
  • Loading branch information
gwdp committed Feb 9, 2024
1 parent 4b9793d commit a148c07
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 13 deletions.
4 changes: 0 additions & 4 deletions options.json
Original file line number Diff line number Diff line change
Expand Up @@ -15775,9 +15775,5 @@
]
}
},
"required": [
"functions",
"images"
],
"type": "object"
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hybridless/hybridless",
"version": "0.1.11",
"version": "0.1.13",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/assets/job-batch/Dockerfile-Job-Nodejs18
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM ghcr.io/hybridless/node:18-alpine

# Copy files
COPY /usr/src/app/ /usr/src/app/
COPY proxy.js /usr/src/hybridless-runtime/proxy.js
COPY proxy.js /usr/src/hybridless-runtime/proxy.mjs

# Set the working directory
WORKDIR /usr/src/app
Expand Down
19 changes: 17 additions & 2 deletions src/core/DepsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default class DepsManager {
private requiresECSRolePermission: boolean;
private requiresECS: boolean;
private requiresMvn: boolean;
private requiresGo: boolean;
private requiresLogsRetention: boolean;
//
private readonly plugin: Hybridless;
Expand All @@ -24,12 +25,14 @@ export default class DepsManager {
public enableECSPlugin(): void { this.requiresECS = true; }
public enableECSRolePermission(): void { this.requiresECSRolePermission = true; }
public enableMvn(): void { this.requiresMvn = true; }
public enableGo(): void { this.requiresGo = true; }
//
public isLogsRetentionRequired(): boolean { return this.requiresWebpack; }
public isWebpackRequired(): boolean { return this.requiresWebpack; }
public isECSRolePermissionRequired(): boolean { return this.requiresECSRolePermission; }
public isECSRequired(): boolean { return this.requiresECS; }
public isMvnRequired(): boolean { return this.requiresMvn; }
public isGoRequired(): boolean { return this.requiresGo; }
//
public async loadDependecies(): BPromise {
const pluginsList = this.plugin.service.plugins;
Expand All @@ -55,8 +58,9 @@ export default class DepsManager {
// // .then(() => (!this.depManager.isWebpackRequired() ? BPromise.resolve() : this.serverless.pluginManager.spawn('webpack:compile')))
// // .then(() => (!this.depManager.isWebpackRequired() ? BPromise.resolve() : this.serverless.pluginManager.spawn('webpack:package')));
// }
return BPromise.resolve()
.then(() => (!this.isMvnRequired() ? BPromise.resolve() : this._compileJava()));
if (this.isMvnRequired()) return BPromise.resolve().then(() => this._compileJava());
if (this.isGoRequired()) return BPromise.resolve().then(() => this._compileGo());
return BPromise.resolve();
}
/* private */
private _isPluginInstalledServerless(pluginsList: Array<string>, dependency: string): boolean {
Expand All @@ -74,6 +78,17 @@ export default class DepsManager {
}
});
}
private async _compileGo(): BPromise {
return new BPromise(async (resolve, reject) => {
this.plugin.logger.info('Go is required to compile GoLang code, compiling...');
const exec = await this._runCommand(Globals.Go_Build_Command);
if (exec && exec.stderr && exec.stderr.toLowerCase().indexOf('error')) reject(exec.stderr);
else {
// if (exec && exec.stdout) this.plugin.logger.debug(exec.stdout); -- Maven output seems huge enough to desconsider it and just output on errors
resolve();
}
});
}
private async _runCommand(command, params = []): BPromise {
return new BPromise(async (resolve, reject) => {
if (!params) params = [];
Expand Down
3 changes: 2 additions & 1 deletion src/core/Globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ export default class Globals {
//Dependecies
public static Deps_Webpack = 'serverless-webpack';
public static Deps_ECS = '@hybridless/serverless-ecs-plugin';
public static Deps_LambdaLogsRetention = 'serverless-plugin-log-retention';
public static Deps_LambdaLogsRetention = '@hybridless/serverless-plugin-log-retention';
//Java support
public static Mvn_Build_Command = 'mvn clean install';
public static Go_Build_Command = 'go mod tidy';
//Defaults
public static DefaultLogsMultilinePattern = '(([a-zA-Z0-9\-]* \[[a-zA-Za-]*\] )|(\[[a-zA-Za -]*\] ))';
public static DefaultHealthCheckInterval = 15;
Expand Down
5 changes: 3 additions & 2 deletions src/options.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//Plugin
export interface OPlugin {
functions: { [key: string]: OFunction } | { [key: string]: OFunction }[];
images: { [key: string]: OImage } | { [key: string]: OImage }[];
functions?: { [key: string]: OFunction } | { [key: string]: OFunction }[];
images?: { [key: string]: OImage } | { [key: string]: OImage }[];
disableWebpack?: boolean;
buildConcurrency?: number;
tags?: { [key: string]: any } | { [key: string]: any }[];
Expand Down Expand Up @@ -75,6 +75,7 @@ export enum OFunctionHttpdTaskRuntime {
nodejs18 = 'nodejs18',
php5 = 'php5',
php7 = 'php7',
go = 'go',
container = 'container'
};
export enum OFunctionProcessTaskRuntime {
Expand Down
1 change: 1 addition & 0 deletions src/resources/BaseEvents/FunctionContainerBaseEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class FunctionContainerBaseEvent extends FunctionBaseEvent<OFunctionConta
public async checkDependencies(): BPromise {
return new BPromise(async (resolve, reject) => {
if (this.event.runtime && this.event.runtime.toLowerCase().indexOf('java') != -1) this.plugin.depManager.enableMvn();
if (this.event.runtime && this.event.runtime.toLowerCase().indexOf('go') != -1) this.plugin.depManager.enableGo();
if (this.event.runtime && this.event.runtime.toLowerCase().indexOf('node') != -1 && !this.plugin.options.disableWebpack) this.plugin.depManager.enableWebpack();
if (this.event.eventType != OFunctionEventType.lambda && this.event.eventType != OFunctionEventType.lambdaContainer) {
this.plugin.depManager.enableECSPlugin();
Expand Down
1 change: 1 addition & 0 deletions src/resources/FunctionLambdaEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class FunctionLambdaEvent extends FunctionBaseEvent<OFunctionLambdaEvent>
return new BPromise(async (resolve, reject) => {
if (this.event.runtime && this.event.runtime.toLowerCase().indexOf('node') != -1 && !this.plugin.options.disableWebpack) this.plugin.depManager.enableWebpack();
if (this.event.runtime && this.event.runtime.toLowerCase().indexOf('java') != -1 && !this.plugin.options.disableWebpack) this.plugin.depManager.enableMvn();
if (this.event.runtime && this.event.runtime.toLowerCase().indexOf('go') != -1 && !this.plugin.options.disableWebpack) this.plugin.depManager.enableGo();
if (this.event.logsRetentionInDays) this.plugin.depManager.enableLogsRetention();
resolve();
});
Expand Down

0 comments on commit a148c07

Please sign in to comment.