weixu365 / serverless-scriptable-plugin

Adding script support to Serverless 1.x which enables you to customize Serverless behavior without writing a plugin.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue running this plugin with docker

AnthonyWC opened this issue · comments

Will able to do more testing later but I had issue getting the plugin to trigger within a docker environment that only has ash shell (alpine). Does the plugin make certain assumption about the shell environment? I had a bash script that had a shebang pointing to the bash installed inside docker but it wasn't launched from bash.

Hi @AnthonyWC , could you please provide more information? e.g.

  • What's the error message?
  • What's your file structure?
  • What's in the serverless.yml config file?
  • What node version are you using?
  • What docker image are you using?

I did a quick test and it works on my machine. I'm using node:alpine docker image

A few things to check:

  • File is executable
  • Add ./ before file name if it's in the current folder
  • Make sure you can run the script manually in docker shell

Here's my testing commands:

$ docker run -it -v `pwd`:/code -w /code node:alpine sh
/code # ls -l
total 192
-rw-r--r--    1 root     root            17 Aug 16 04:46 Dockerfile
-rwxr-xr-x    1 root     root            24 Aug 15 23:49 build.sh
-rw-r--r--    1 root     root            87 Aug 15 23:53 handler.js
drwxr-xr-x  422 root     root         13504 Aug 16 04:57 node_modules
-rw-r--r--    1 root     root        172162 Aug 15 23:49 package-lock.json
-rw-r--r--    1 root     root           304 Aug 15 23:49 package.json
-rw-r--r--    1 root     root           257 Aug 16 04:49 serverless.yml

/code # cat serverless.yml 
service: demo

provider:
  name: aws
  runtime: nodejs8.10
  region: ap-southeast-2

plugins:
  - serverless-scriptable-plugin

custom:
  scriptHooks:
    before:package:createDeploymentArtifacts: ./build.sh

functions:
  test:
    handler: handler.handle

/code # cat build.sh 
echo my own build script

/code # npx serverless package
Running command: ./build.sh
my own build script
Serverless: Packaging service...
Serverless: Excluding development dependencies...

Sorry user error. :)