Skip to content

Commit

Permalink
More into go support
Browse files Browse the repository at this point in the history
  • Loading branch information
gwdp committed Feb 9, 2024
1 parent a148c07 commit b536980
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/hybridless-registry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
- node:18-slim
- webdevops/php-nginx:alpine-php5
- webdevops/php-nginx:alpine-php7
- go:latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Sync Docker Image to Registry
Expand Down
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.13",
"version": "0.1.15-alpha4",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
13 changes: 13 additions & 0 deletions src/assets/task-httpd/Dockerfile-Httpd-Go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM ghcr.io/hybridless/go:latest

# Set the working directory inside the container
WORKDIR /app

# Expose
EXPOSE $PORT

# Copy files
COPY /app/ /app/

# Command to run the executable
CMD ["./$ENTRYPOINT"]
4 changes: 3 additions & 1 deletion src/core/Globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class Globals {
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';
public static Go_Build_Command = 'go mod tidy && go build -o ./build/';
//Defaults
public static DefaultLogsMultilinePattern = '(([a-zA-Z0-9\-]* \[[a-zA-Za-]*\] )|(\[[a-zA-Za -]*\] ))';
public static DefaultHealthCheckInterval = 15;
Expand Down Expand Up @@ -44,6 +44,8 @@ export default class Globals {
return 'task-httpd/Dockerfile-Httpd-PHP5'
} else if (environment == OFunctionHttpdTaskRuntime.php7) {
return 'task-httpd/Dockerfile-Httpd-PHP7'
} else if (environment == OFunctionHttpdTaskRuntime.go) {
return 'task-httpd/Dockerfile-Httpd-Go'
} else if (environment == OFunctionHttpdTaskRuntime.container) {
throw new Error(`Container environments requires dockerFile to be set!`);
} throw new Error(`Unknown event *httpd* environment type! ${environment} is not a valid environment, can't continue!`);
Expand Down
2 changes: 2 additions & 0 deletions src/resources/Function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ export class Function {
noFuncHandler.splice(noFuncHandler.length - 1, 1);
noFuncHandler = noFuncHandler.join('/');
return noFuncHandler;
} else if (event && event.runtime && event.runtime.toLowerCase().indexOf('go') != -1) {
return (event.handler || this.funcOptions.handler);
} else if (event && event.runtime && event.runtime.toLowerCase().indexOf('node') != -1) { //NodeJS event
//get handler without last component (function)
let noFuncHandler: any = (event.handler || this.funcOptions.handler).split('.');
Expand Down
14 changes: 14 additions & 0 deletions src/resources/FunctionHttpdTaskEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class FunctionHTTPDTaskEvent extends FunctionContainerBaseEvent {
//Envs
const isNodeJS = (event && event.runtime && event.runtime.toLowerCase().indexOf('node') != -1);
const isPHP = (event && event.runtime && event.runtime.toLowerCase().indexOf('php') != -1);
const isGo = (event && event.runtime && event.runtime.toLowerCase().indexOf('go') != -1);
const isPureContainer = (event.runtime == OFunctionHttpdTaskRuntime.container);
//Get build directory
let safeDir: any = __dirname.split('/');
Expand Down Expand Up @@ -56,6 +57,15 @@ export class FunctionHTTPDTaskEvent extends FunctionContainerBaseEvent {
{ name: handleRootFolder, dir: serverlessDir, dest: '/app/' },
...additionalDockerFiles
];
} else if (isGo) {
return [
(customDockerFile ?
{ name: customDockerFile, dir: serverlessDir, dest: 'Dockerfile' } :
{ name: Globals.HTTPD_ImageByRuntime(event.runtime), dir: safeDir + '/resources/assets', dest: 'Dockerfile' }
),
{ name: 'build', dir: serverlessDir, dest: '/app/' },
...additionalDockerFiles
];
} else if (isPureContainer) {
return [
{ name: customDockerFile, dir: serverlessDir, dest: 'Dockerfile' },
Expand All @@ -69,6 +79,7 @@ export class FunctionHTTPDTaskEvent extends FunctionContainerBaseEvent {
const event: OFunctionHTTPDTaskEvent = (<OFunctionHTTPDTaskEvent>this.event);
const isPHP = (event && event.runtime && event.runtime.toLowerCase().indexOf('php') != -1)
const isNodeJS = (event && event.runtime && event.runtime.toLowerCase().indexOf('node') != -1);
const isGo = (event && event.runtime && event.runtime.toLowerCase().indexOf('go') != -1);
const isPureContainer = (event.runtime == OFunctionHttpdTaskRuntime.container);
return {
//Plataform specific
Expand All @@ -79,6 +90,9 @@ export class FunctionHTTPDTaskEvent extends FunctionContainerBaseEvent {
// Proxy
...(event.cors ? { 'CORS': JSON.stringify(event.cors) } : {}),
}),
...(isGo && {
'ENTRYPOINT': `./${this.func.getEntrypoint(this.event)}`,
}),
...(isPHP && {
'WEB_DOCUMENT_INDEX': this.func.getEntrypointFunction(this.event)
}),
Expand Down

0 comments on commit b536980

Please sign in to comment.