Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Add custom Dockerfile workflow example#228

Merged
dschep merged 2 commits intoserverless:masterfrom
alexjurkiewicz:custom-docker-dependencies
Aug 14, 2018
Merged

Add custom Dockerfile workflow example#228
dschep merged 2 commits intoserverless:masterfrom
alexjurkiewicz:custom-docker-dependencies

Conversation

@alexjurkiewicz
Copy link
Copy Markdown
Contributor

As per #101.

Copy link
Copy Markdown
Contributor

@dschep dschep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! But why not use the dockerFile option? Then you can skip the build step! and the config would be

custom:
  pythonRequirements:
    dockerFile: ./Dockerfile

@alexjurkiewicz
Copy link
Copy Markdown
Contributor Author

Hm, actually the Docker support doesn't quite do what I want. I want to add the file /usr/lib64/mysql57/libmysqlclient.so.1020 to my zipfile (in the root directory). It's accessible in the Docker image, but Pip (obviously) doesn't copy it to /var/task during pip install....

Current build process:

  1. Build custom image with pip dependencies
  2. Run the image with a bind mount to .serverless/ to /var/task, and command pip install ...

After running pip install, I want to copy some files from the image to .serverless/requirements. Does this plugin have a supported way to do so?

@alexjurkiewicz
Copy link
Copy Markdown
Contributor Author

I've updated the docs to handle both cases:

  1. Adding build-time OS dependencies
  2. Adding run-time OS dependencies

If there's a better way to implement 2 than "copy them into your repo" I'm all ears. Couldn't figure it out myself though :(

Copy link
Copy Markdown
Contributor

@dschep dschep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no reason AFAIK not to still use the lambci build image as the base, and it make the dockerfile smaller

FROM lambci/lambda:build-python3.6

# Install your dependencies
yum -y install mysql-devel

@dschep
Copy link
Copy Markdown
Contributor

dschep commented Aug 13, 2018

As for step2. that's fine 👍

@alexjurkiewicz
Copy link
Copy Markdown
Contributor Author

Thanks for the feedback. Unfortunately I had issues installing packages into lambci/lambda:build-python3.6. Here's an example Dockerfile:

FROM lambci/lambda:build-python3.6
RUN yum install -y mysql-devel
WORKDIR /var/task

docker build . output:

Sending build context to Docker daemon  2.048kB
Step 1/3 : FROM lambci/lambda:build-python3.6
 ---> 408b3aae7c81
Step 2/3 : RUN yum install -y mysql-devel
[...]
Running transaction
  Installing : mysql55-libs-5.5.57-1.18.amzn1.x86_64                        1/5
  Installing : mysql-config-5.5.57-1.18.amzn1.x86_64                        2/5
  Installing : mysql55-5.5.57-1.18.amzn1.x86_64                             3/5
  Installing : mysql55-devel-5.5.57-1.18.amzn1.x86_64                       4/5
  Installing : mysql-devel-5.5-1.6.amzn1.noarch                             5/5

Rpmdb checksum is invalid: dCDPT(pkg checksums): mysql-config.x86_64 0:5.5.57-1.18.amzn1 - u

The command '/bin/sh -c yum install -y mysql-devel' returned a non-zero code: 1

There are some workarounds in this thread of the issue:

  • yum install yum-plugin-ovh
  • rpm --rebuilddb && touch /var/lib/rpm/*
  • Append || true to each yum command.

Only the last one helped. If you like, I can change the example to use that (with a comment referencing the bug) with the lambci container?

Copy link
Copy Markdown
Contributor

@dschep dschep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. That's good enough reason for me.

@dschep dschep merged commit 69031d8 into serverless:master Aug 14, 2018
@alexjurkiewicz alexjurkiewicz deleted the custom-docker-dependencies branch September 19, 2019 06:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants