eabglobal / juniper

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

Leftover empty requirements.txt file after build #24

Closed gumuz closed 5 years ago

gumuz commented 5 years ago

Hi,

After I run juni build, an empty requirements.txt file appears in src folder. I think it's related to the way the src & requirements.txt volume are attached to the docker container, but I'm not sure. It's especially puzzling how it can be empty (since my reqs file is not empty).

My project structure looks like this:

~/ tree
.
├── manifest.yml
├── requirements.txt
├── src
│   ├── bootstrap.py
│   ├── handlers
│   │   ├── __init__.py
│   │   └── initialise_tasks.py
│   └── services
│       ├── __init__.py
│       └── tasks.py

My manifest looks like this:

functions:
  initialise_tasks: 
    requirements: ./requirements.txt
    include:
      - ./src/

The resulting Docker compose file looks like this:

version: '3.6'

services:

  initialise_tasks-lambda:
    image: lambci/lambda:build-python3.6
    environment:
      - AWS_DEFAULT_REGION=us-east-1
    volumes:
      - ./dist:/var/task/dist
      - ./.juni/bin:/var/task/bin
      - ./src/:/var/task/common/
      - ./requirements.txt:/var/task/common/requirements.txt
    command: sh /var/task/bin/package.sh initialise_tasks

Let me know if you need more details and/or if you can point me in the right direction of solving this. Thanks!

pdiazvargas commented 5 years ago

Hey @gumuz, That's definitely puzzling, from the information you're providing at a first glance it looks like everything should be working as expected. I'll try to reproduce it locally and if I need anything else I'll let you know! Thanks for the feedback.

pdiazvargas commented 5 years ago

@gumuz, you're absolutely right! The issue is the trailing slash in the definition of the includes block. With this manifest.yml

functions:
  initialise_tasks: 
    requirements: ./requirements.txt
    include:
      - ./src

The resulting docker-compose file is the following:

version: '3.6'

services:

  initialise_tasks-lambda:
    image: lambci/lambda:build-python3.6
    environment:
      - AWS_DEFAULT_REGION=us-east-1
    volumes:
      - ./dist:/var/task/dist
      - ./.juni/bin:/var/task/bin
      - ./src:/var/task/common/src
      - ./requirements.txt:/var/task/common/requirements.txt

    command: sh /var/task/bin/package.sh initialise_tasks

Note that in this case, the src will be mapped to its own folder inside of the common directory. In this case, you don't get the bleeding of the requirements in your filesystem. I'll create a PR to address that issue.

Cheers!