eabglobal / juniper

Juniper is a cli based tool used to package lambda functions
Apache License 2.0
67 stars 9 forks source link

Enable different python docker images #21

Closed pdiazvargas closed 5 years ago

pdiazvargas commented 5 years ago

What

While using juniper for build purposes, I am unable to create an artifact for anything other than python3.6. I need to have the ability to specify the python base image the container will use when packaging my lambda functions.

The default image juniper is currently using is: lambci/lambda:build-python3.6

How

Update the manifest file to take a few docker specific parameters. Either add a docker specific section in the manifest file like:

docker:
  image: python:3.6-alpine

functions:
  router:
    include:
      - ./src/router_lambda

Or create a more global set of parameters:

global:
  docker_image: python:3.6-alpine

functions:
  router:
    include:
      - ./src/router_lambda

Why

Having a developer change the runtime of a lambda function to python 3.6 due to juniper's inability to package using python 3.7 is not acceptable.

positiveintent commented 5 years ago

It looks to me like the proposal is trying to solve 2 issues at once:

  1. The ability to specify a docker container for any given function
  2. The ability to specify common parameters applying to ALL functions: docker, requirements, and common includes

I would advise that the two separate concerns be split and tackled individually since there is no concept in Juniper now which addresses hierarchy/inheritance.

For Docker specification (issue part 1), you could take the simplest approach:

functions:
  router:
    image: python:3.6-alpine
    include:
      - ./src/router_lambda
    requirements: ./src/requirements.txt

For common parameter values (issue part 2):

There are 2 approaches you could take:

  1. Specify a global set of parameters (with properties matching those of individual functions)
    global:
    image: python:3.6-alpine
    include:
    - ./src/common/constants.py
    requirements: ./src/requirements.txt
  2. Introduce hierarchy - this is the one I favor (since you can have groups of lambdas each with a separate set of common properties), and might actually work out-of-the-box with YAML
functions:

  .globals: &global_template
    image: python:3.6-alpine
    requirements: ./src/requirements.txt

  my_function:
    <<: *global_template
    include:
      - ./src/my_function

  your_function:
    <<: *global_template
    include:
      - ./src/your_function
pdiazvargas commented 5 years ago

Taking a mixed approached, for this particular feature, we should implement the global parameter setting with an override at a function level. That way a developer will have the following options:

  1. Build all functions using the default image
  2. Specify a global docker image to build all functions
  3. Override the image at function level

With this in mind the manifest would look like:

global:
  image: python:3.6-alpine

functions:
  edge:
    image: python:3.8-alpine
    requirements: ./src/edge/requirements.txt
    include:
      - ./src/edge/

  sequential-worker:
    include:
      - ./src/worker/sequential_worker