|
1 | 1 | # Python Buildpack Binaries
|
2 | 2 |
|
3 |
| -For Cedar-14 stack |
4 |
| ------------------- |
| 3 | +## Building the Docker Images |
5 | 4 |
|
6 |
| -To get started with it, create an app on Heroku inside a clone of this repository, and set your S3 config vars: |
| 5 | +**After every change to your formulae, perform the following** from the root of the Git repository (not from `builds/`) to rebuild the images for each stack: |
7 | 6 |
|
8 |
| - $ heroku create --buildpack https://github.com/heroku/heroku-buildpack-python#not-heroku |
9 |
| - $ heroku config:set WORKSPACE_DIR=builds |
10 |
| - $ heroku config:set AWS_ACCESS_KEY_ID=<your_aws_key> |
11 |
| - $ heroku config:set AWS_SECRET_ACCESS_KEY=<your_aws_secret> |
12 |
| - $ heroku config:set S3_BUCKET=<your_s3_bucket_name> |
| 7 | + $ docker build --pull --tag heroku-python-build-cedar-14 --file $(pwd)/builds/cedar-14.Dockerfile . |
| 8 | + $ docker build --pull --tag heroku-python-build-heroku-16 --file $(pwd)/builds/heroku-16.Dockerfile . |
| 9 | + $ docker build --pull --tag heroku-python-build-heroku-18 --file $(pwd)/builds/heroku-18.Dockerfile . |
13 | 10 |
|
| 11 | +## Using the Image |
14 | 12 |
|
15 |
| -Then, shell into an instance and run a build by giving the name of the formula inside `builds`: |
| 13 | +You can e.g. `bash` into each of the images you built using their tag: |
16 | 14 |
|
17 |
| - $ heroku run bash |
18 |
| - Running `bash` attached to terminal... up, run.6880 |
19 |
| - ~ $ bob build runtimes/python-2.7.6 |
| 15 | + docker run --rm -ti heroku-python-build-cedar-14 bash |
| 16 | + docker run --rm -ti heroku-python-build-heroku-16 bash |
| 17 | + docker run --rm -ti heroku-python-build-heroku-18 bash |
20 | 18 |
|
21 |
| - Fetching dependencies... found 2: |
22 |
| - - libraries/sqlite |
| 19 | +You then have a shell where you can run `bob build`, `bob deploy`, and so forth. You can of course also invoke these programs directly with `docker run`: |
23 | 20 |
|
24 |
| - Building formula runtimes/python-2.7.6: |
25 |
| - === Building Python 2.7.6 |
26 |
| - Fetching Python v2.7.6 source... |
27 |
| - Compiling... |
| 21 | + docker run --rm -ti heroku-python-build-heroku-18 bob build runtimes/python-2.7.15 |
28 | 22 |
|
29 |
| -If this works, run `bob deploy` instead of `bob build` to have the result uploaded to S3 for you. |
| 23 | +In order to `bob deploy`, AWS credentials must be set up, as well as name and prefix of your custom S3 bucket (unless you're deploying to the Heroku production buckets that are pre-defined in each `Dockerfile`); see next section for details. |
30 | 24 |
|
31 |
| -To speed things up drastically, it'll usually be a good idea to `heroku run bash --size PX` instead. |
| 25 | +## Configuration |
32 | 26 |
|
33 |
| -For Heroku-16 stack |
34 |
| -------------------- |
| 27 | +File `dockerenv.default` contains a list of required env vars; most of these have default values defined in `Dockerfile`. You can copy this file to a location outside the buildpack and modify it with the values you desire and pass its location with `--env-file`, or pass the env vars to `docker run` using `--env`. |
35 | 28 |
|
36 |
| -1. Ensure GNU Make and Docker are installed. |
37 |
| -2. From the root of the buildpack repository, run: `make buildenv-heroku-16` |
38 |
| -3. Follow the instructions displayed! |
| 29 | +Out of the box, each `Dockerfile` has the correct values predefined for `S3_BUCKET`, `S3_PREFIX`, and `S3_REGION`. If you're building your own packages, you'll likely want to change `S3_BUCKET` and `S3_PREFIX` to match your info. Instead of setting `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` into that file, you may also pass them to `docker run` through the environment, or explicitly using `--env`, in order to prevent accidental commits of credentials. |
39 | 30 |
|
40 |
| -For Heroku-18 stack |
41 |
| -------------------- |
| 31 | +### Passing AWS credentials to the container |
42 | 32 |
|
43 |
| -1. Ensure GNU Make and Docker are installed. |
44 |
| -2. From the root of the buildpack repository, run: `make buildenv-heroku-18` |
45 |
| -3. Follow the instructions displayed! |
| 33 | +If you want to deploy packages and thus need to pass `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`, you can either pass them explicitly, through your environment, or through an env file. |
46 | 34 |
|
47 |
| -Enjoy :) |
| 35 | +#### Passing credentials explicitly |
| 36 | + |
| 37 | + docker run --rm -ti -e AWS_ACCESS_KEY_ID=... -e AWS_SECRET_ACCESS_KEY=... heroku-python-build-heroku-18 bash |
| 38 | + |
| 39 | +#### Passing credentials through the environment |
| 40 | + |
| 41 | +The two environment variables `AWS_ACCESS_KEY_ID`and `AWS_SECRET_ACCESS_KEY` are defined in `builds/dockerenv.default`, without values. This will cause Docker to "forward" values for these variables from the current environment, so you can pass them in: |
| 42 | + |
| 43 | + AWS_ACCESS_KEY_ID=... AWS_SECRET_ACCESS_KEY=... docker run --rm -ti --env-file=builds/dockerenv.default heroku-python-build-heroku-18 bash |
| 44 | + |
| 45 | +or |
| 46 | + |
| 47 | + export AWS_ACCESS_KEY_ID=... |
| 48 | + export AWS_SECRET_ACCESS_KEY=... |
| 49 | + docker run --rm -ti --env-file=builds/dockerenv.default heroku-python-build-heroku-18 bash |
| 50 | + |
| 51 | +#### Passing credentials through a separate env file |
| 52 | + |
| 53 | +This method is the easiest for users who want to build packages in their own S3 bucket, as they will have to adjust the `S3_BUCKET` and `S3_PREFIX` environment variable values anyway from their default values. |
| 54 | + |
| 55 | +For this method, it is important to keep the credentials file in a location outside the buildpack, so that your credentials aren't accidentally committed. Copy `builds/dockerenv.default` **to a safe location outside the buildpack directory**, and insert your values for `AWS_ACCESS_KEY_ID`and `AWS_SECRET_ACCESS_KEY`. |
| 56 | + |
| 57 | + docker run --rm -ti --env-file=../SOMEPATHOUTSIDE/s3.env heroku-python-build-heroku-18 bash |
0 commit comments