Skip to content

Commit

Permalink
feat: add env vars to service
Browse files Browse the repository at this point in the history
  • Loading branch information
retgits committed Feb 6, 2021
1 parent 72b2569 commit f971a50
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 10 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ functions:
tag: '1.0.0' ## tag to add to the docker container
skipBuild: true ## skips the build if set to true
proxyHostPort: 9001
environment: ## environment variables that you want to set
hello: world
msg: the warehouse is stocked

plugins:
- '@retgits/akkasls-serverless-framework'
Expand Down
16 changes: 8 additions & 8 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
Expand Up @@ -45,6 +45,6 @@
"typescript": "^4.1.3"
},
"dependencies": {
"@retgits/akkasls-nodewrapper": "^0.1.1"
"@retgits/akkasls-nodewrapper": "^0.1.5"
}
}
3 changes: 3 additions & 0 deletions src/datatypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export interface Function {
tag: string;
proxyHostPort: number;
skipBuild: boolean;
environment?: {
[key: string]: any;
};
}

/**
Expand Down
11 changes: 10 additions & 1 deletion src/plugins/deploy/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,21 @@ export class ASDeployPlugin extends BasePlugin {

f.name = removeStageFromName(f.name, this._provider.stage);

const envvars : string[] = [];

if(f.environment) {
Object.keys(f.environment).forEach(function (key) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
envvars.push(`${key}="${f.environment![key]}"`);
});
}

const tag = getDockerTag(f.tag);
if (tag === config.defaults.tag) {
this.warn(`${f.name} does not have a tag. Adding ${tag} for now, but this might cause issues...`);
}

const res = await deployService(f.name, `${this.serverless.service.provider.docker.imageUser}/${f.name}:${tag}`, project, {dryrun: this._dryrun, silent: this._provider.quiet, configFile: this._provider.config, context: this._provider.context});
const res = await deployService(f.name, `${this.serverless.service.provider.docker.imageUser}/${f.name}:${tag}`, project, {vars: envvars}, {dryrun: this._dryrun, silent: this._provider.quiet, configFile: this._provider.config, context: this._provider.context});
this.log(res.stdout);
}

Expand Down
3 changes: 3 additions & 0 deletions src/provider/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ export const validationSchema = {
},
proxyHostPort: {
type: 'number'
},
environment: {
type: 'object',
}
}
}
Expand Down

0 comments on commit f971a50

Please sign in to comment.