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

Commit

Permalink
Merge pull request #10 from danprueitt/Update-dependencies-and-node-v…
Browse files Browse the repository at this point in the history
…ersion

Update node version to 20 and update dependencies. Add al2023 to supp…
  • Loading branch information
danprueitt authored Nov 17, 2023
2 parents 74dd701 + 03fbf0f commit b48326f
Show file tree
Hide file tree
Showing 9 changed files with 2,187 additions and 1,826 deletions.
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ updates:
groups:
minor_patch_dependencies:
patterns:
- '*'
- "*"
update-types:
- minor
- patch
Expand All @@ -22,7 +22,7 @@ updates:
groups:
minor_patch_dependencies:
patterns:
- '*'
- "*"
update-types:
- minor
- patch
20 changes: 10 additions & 10 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v1
with:
node-version: 12
- run: npm install
- run: |
npm test
npm run report-coverage
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm install
- run: |
npm test
npm run report-coverage
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![npm](https://img.shields.io/npm/v/serverless-golang-plugin)](https://www.npmjs.com/package/serverless-golang-plugin)
[![codecov](https://codecov.io/gh/mthenw/serverless-go-plugin/branch/master/graph/badge.svg)](https://codecov.io/gh/mthenw/serverless-go-plugin)

`serverless-golang-plugin` is a Serverless Framework plugin that compiles Go functions on the fly. You don't need to do it manually before `serverless deploy`. Once the plugin is installed it will happen automatically. *The plugin works with Serverless Framework version 1.52 and above.*
`serverless-golang-plugin` is a Serverless Framework plugin that compiles Go functions on the fly. You don't need to do it manually before `serverless deploy`. Once the plugin is installed it will happen automatically. _The plugin works with Serverless Framework version 1.52 and above._

### [dev.to: A better way of deploying Go services with Serverless Framework](https://dev.to/mthenw/a-better-way-of-deploying-go-services-with-serverless-framework-41c4)

Expand All @@ -19,28 +19,27 @@

## Install


1. Install the plugin

```
npm i --save-dev serverless-golang-plugin
```
```
npm i --save-dev serverless-golang-plugin
```

1. Add it to your `serverless.yaml`

```
plugins:
- serverless-golang-plugin
```
```
plugins:
- serverless-golang-plugin
```

1. Replace every Go function's `handler` with `*.go` file path or a package path. E.g.

```
functions:
example:
runtime: go1.x
handler: functions/example/main.go # or just functions/example
```
```
functions:
example:
runtime: go1.x
handler: functions/example/main.go # or just functions/example
```

## Configuration

Expand All @@ -54,7 +53,7 @@ custom:
cgo: 0 # CGO_ENABLED flag
cmd: GOOS=linux go build -ldflags="-s -w"' # compile command
monorepo: false # if enabled, builds function every directory (useful for monorepo where go.mod is managed by each function
supportedRuntimes: ["go1.x"] # the plugin compiles a function only if runtime is declared here (either on function or provider level)
supportedRuntimes: ["go1.x"] # the plugin compiles a function only if runtime is declared here (either on function or provider level)
buildProvidedRuntimeAsBootstrap: false # if enabled, builds and archive function with only single "bootstrap" binary (useful for runtimes like provided.al2)
```

Expand All @@ -77,10 +76,11 @@ include:
1. Add `provided.al2` to `supportedRuntimes` and enable `buildProvidedRuntimeAsBootstrap` in plugin config
2. Append `GOARCH=arm64` to your compile command (`cmd` line)
3. Change architecture and runtime in global config:

```yaml
provider:
architecture: arm64
runtime: provided.al2
```
architecture: arm64
runtime: provided.al2
```
**Warning!** First deploy may result in small downtime (~few seconds) of lambda, use some deployment strategy like canary for safer rollout.
16 changes: 8 additions & 8 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

1. If you haven't already, switch to the master branch, ensure that you have no changes, and pull from origin.

```sh
$ git checkout master
$ git status
$ git pull <remote> master --rebase
```
```sh
$ git checkout master
$ git status
$ git pull <remote> master --rebase
```

1. Bump package version

```sh
$ npm version [major | minor | patch]
```
```sh
$ npm version [major | minor | patch]
```

1. `postversion` script will push tags to the repo, publish NPM package, and open GitHub release page.
2 changes: 1 addition & 1 deletion example/serverless.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
service: example-service

frameworkVersion: '>=1.52.0 <2.0.0'
frameworkVersion: ">=1.52.0 <2.0.0"

provider:
name: aws
Expand Down
38 changes: 20 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const ConfigDefaults = {
};

// amazonProvidedRuntimes contains Amazon Linux runtimes. Update this array after each new version release.
const amazonProvidedRuntimes = ["provided.al2"];
const amazonProvidedRuntimes = ["provided.al2", "provided.al2023"];

module.exports = class Plugin {
constructor(serverless, options) {
Expand All @@ -30,14 +30,12 @@ module.exports = class Plugin {

this.hooks = {
"before:deploy:function:packageFunction": this.compileFunction.bind(this),
"before:package:createDeploymentArtifacts": this.compileFunctions.bind(
this
),
"before:package:createDeploymentArtifacts":
this.compileFunctions.bind(this),
// Because of https://github.com/serverless/serverless/blob/master/lib/plugins/aws/invokeLocal/index.js#L361
// plugin needs to compile a function and then ignore packaging.
"before:invoke:local:invoke": this.compileFunctionAndIgnorePackage.bind(
this
),
"before:invoke:local:invoke":
this.compileFunctionAndIgnorePackage.bind(this),
"go:build:build": this.compileFunctions.bind(this),
};

Expand Down Expand Up @@ -65,8 +63,8 @@ module.exports = class Plugin {

this.serverless.cli.consoleLog(
`Go Plugin: ${chalk.yellow(
`Compilation time (${name}): ${prettyHrtime(timeEnd)}`
)}`
`Compilation time (${name}): ${prettyHrtime(timeEnd)}`,
)}`,
);
}

Expand All @@ -84,12 +82,14 @@ module.exports = class Plugin {
const func = this.serverless.service.functions[name];
await this.compile(name, func);
},
{ concurrency: os.cpus().length }
{ concurrency: os.cpus().length },
);
const timeEnd = process.hrtime(timeStart);

this.serverless.cli.consoleLog(
`Go Plugin: ${chalk.yellow("Compilation time: " + prettyHrtime(timeEnd))}`
`Go Plugin: ${chalk.yellow(
"Compilation time: " + prettyHrtime(timeEnd),
)}`,
);
}

Expand Down Expand Up @@ -123,22 +123,22 @@ module.exports = class Plugin {
}
try {
const [env, command] = parseCommand(
`${config.cmd} -o ${compileBinPath} ${handler}`
`${config.cmd} -o ${compileBinPath} ${handler}`,
);
await exec(command, {
cwd: cwd,
env: Object.assign(
{},
process.env,
{ CGO_ENABLED: config.cgo.toString() },
env
env,
),
});
} catch (e) {
this.serverless.cli.consoleLog(
`Go Plugin: ${chalk.yellow(
`Error compiling "${name}" function (cwd: ${cwd}): ${e.message}`
)}`
`Error compiling "${name}" function (cwd: ${cwd}): ${e.message}`,
)}`,
);
process.exit(1);
}
Expand All @@ -150,10 +150,12 @@ module.exports = class Plugin {
this.serverless.service.functions[name].handler = binPath;
const packageConfig = this.generatePackageConfig(runtime, config, binPath);

if (this.serverless.service.functions[name].package
&& this.serverless.service.functions[name].package.include) {
if (
this.serverless.service.functions[name].package &&
this.serverless.service.functions[name].package.include
) {
packageConfig.include = packageConfig.include.concat(
this.serverless.service.functions[name].package.include
this.serverless.service.functions[name].package.include,
);
}
this.serverless.service.functions[name].package = packageConfig;
Expand Down
Loading

0 comments on commit b48326f

Please sign in to comment.