Skip to content

Feature request: Add pre/post command for docker build #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rokoroku opened this issue Aug 6, 2018 · 5 comments
Closed

Feature request: Add pre/post command for docker build #225

rokoroku opened this issue Aug 6, 2018 · 5 comments

Comments

@rokoroku
Copy link

rokoroku commented Aug 6, 2018

In case of a dependency that requires native binaries before pip install command,
so currently I'm handling it like this way:

    pythonBin: >-
      curl --silent -L https://example.com/source.tar.gz | tar xzf &&
      docker run -v "$(pwd):/var/task:z" -u 0 sls-py-reqs-custom ./source/make install &&
      docker run -v "$(pwd):/var/task:z" -u 0 sls-py-reqs-custom python3
    pipCmdExtraArgs:
      - && docker run --rm -v "$(pwd):/var/task:z" -u 0 cp -R /build .serverless/requirements   

but if we have something like preDockerCmd / postDockerCmd, we can achieve it like this way:

    preDockerCmd:
      - curl --silent -L https://example.com/source.tar.gz | tar xzf
      - ./source/make install

    postDockerCmd:
      - cp -R /build .serverless/requirements   

reference:

https://stackoverflow.com/a/26274399/2305379

@dschep
Copy link
Contributor

dschep commented Aug 8, 2018

Not a bad idea. For situations like yours where you seem to be ok with separate docker run invocations, it might make sense to add have the plugin fire off custom lifecycle events which can then be more easily tapped into with plugins like serverless-plugin-scripts.

then you could (with that plugin) do something like this:

custom:
  scripts:
    hooks:
      'before:requirements:pip:install': curl --silent -L https://example.com/source.tar.gz | tar xzf && docker run -v "$(pwd):/var/task:z" -u 0 sls-py-reqs-custom ./source/make install
      'after:requirements:pip:install': cp -R /build .serverless/requirements

@rokoroku
Copy link
Author

rokoroku commented Aug 9, 2018

@dschep Yeah but things like sls-py-reqs-custom and .serverless/requirements is kind of a hack into serverless-python-requirements's internal (which means they might be highly likely changed without any announcement.)

So it's better to have that hooks with custom.pythonRequirements variable.
I think it can be applied to both docker / without docker environment

e.g.

custom:
  pythonRequirements:
    # hooks can be applied to both environment with/without docker
    hooks:
       # accepting both string or string array 
      'before:requirements:pip:install': ...
      'after:requirements:pip:install': 
         - ...
         - ...

@MrTeale
Copy link

MrTeale commented Aug 28, 2018

+1 on this. Are there any updates on if we'll see this in the near future?

@dschep
Copy link
Contributor

dschep commented Aug 28, 2018

@MrTeale, AFAIK no one is working on this. Sorry.

@pgrzesik
Copy link
Contributor

Hey 👋 I'm closing this ticket as it looks like it's heavily outdated, we can of course reopen it if needed 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants