Skip to content

Commit b8d1035

Browse files
authored
Merge pull request heroku#799 from heroku/build-cleanup
Build cleanup
2 parents 05b7ceb + 006ea77 commit b8d1035

23 files changed

+227
-123
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ repos/*
77

88
#Venv
99
buildpack/*
10+
11+
builds/dockerenv.staging*
12+
builds/dockerenv.production

.travis.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ before_script:
99
- bundle exec hatchet ci:setup
1010

1111
script:
12-
- docker build --pull --tag heroku-python-build-heroku-16 --file $(pwd)/Dockerfile .
13-
- docker run --rm -e "STACK=heroku-16" heroku-python-build-heroku-16 bash $TESTFOLDER
14-
- docker build --pull --tag heroku-python-build-heroku-18 --file $(pwd)/Dockerfile.heroku-18 .
15-
- docker run --rm -e "STACK=heroku-18" heroku-python-build-heroku-18 bash $TESTFOLDER
12+
- docker build --pull --tag travis-build-cedar-14 --file $(pwd)/builds/cedar-14.Dockerfile .
13+
- docker run --rm -e "STACK=cedar-14" travis-build-cedar-14 bash $TESTFOLDER
14+
- docker build --pull --tag travis-build-heroku-16 --file $(pwd)/builds/heroku-16.Dockerfile .
15+
- docker run --rm -e "STACK=heroku-16" travis-build-heroku-16 bash $TESTFOLDER
16+
- docker build --pull --tag travis-build-heroku-18 --file $(pwd)/builds/heroku-18.Dockerfile .
17+
- docker run --rm -e "STACK=heroku-18" travis-build-heroku-18 bash $TESTFOLDER
1618

1719
jobs:
1820
include:

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ check:
88
@shellcheck -x bin/steps/collectstatic bin/steps/eggpath-fix bin/steps/eggpath-fix2 bin/steps/gdal bin/steps/geo-libs bin/steps/mercurial bin/steps/nltk bin/steps/pip-install bin/steps/pip-uninstall bin/steps/pipenv bin/steps/pipenv-python-version bin/steps/pylibmc bin/steps/python
99
@shellcheck -x bin/steps/hooks/*
1010

11+
test-cedar-14:
12+
@echo "Running tests in docker (cedar-14)..."
13+
@docker run -v $(shell pwd):/buildpack:ro --rm -it -e "STACK=cedar-14" heroku/cedar-14 bash -c 'cp -r /buildpack /buildpack_test; cd /buildpack_test/; test/run;'
14+
@echo ""
15+
1116
test-heroku-16:
1217
@echo "Running tests in docker (heroku-16)..."
1318
@docker run -v $(shell pwd):/buildpack:ro --rm -it -e "STACK=heroku-16" heroku/heroku:16-build bash -c 'cp -r /buildpack /buildpack_test; cd /buildpack_test/; test/run;'
@@ -21,7 +26,7 @@ test-heroku-18:
2126
buildenv-heroku-16:
2227
@echo "Creating build environment (heroku-16)..."
2328
@echo
24-
@docker build --pull -t python-buildenv-heroku-16 .
29+
@docker build --pull -f $(shell pwd)/builds/heroku-16.Dockerfile -t python-buildenv-heroku-16 .
2530
@echo
2631
@echo "Usage..."
2732
@echo
@@ -34,7 +39,7 @@ buildenv-heroku-16:
3439
buildenv-heroku-18:
3540
@echo "Creating build environment (heroku-18)..."
3641
@echo
37-
@docker build --pull -f Dockerfile.heroku-18 -t python-buildenv-heroku-18 .
42+
@docker build --pull -f $(shell pwd)/builds/heroku-18.Dockerfile -t python-buildenv-heroku-18 .
3843
@echo
3944
@echo "Usage..."
4045
@echo

builds/README.md

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,57 @@
11
# Python Buildpack Binaries
22

3-
For Cedar-14 stack
4-
------------------
3+
## Building the Docker Images
54

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:
76

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 .
1310

11+
## Using the Image
1412

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:
1614

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
2018

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`:
2320

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
2822

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.
3024

31-
To speed things up drastically, it'll usually be a good idea to `heroku run bash --size PX` instead.
25+
## Configuration
3226

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`.
3528

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.
3930

40-
For Heroku-18 stack
41-
-------------------
31+
### Passing AWS credentials to the container
4232

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.
4634

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

builds/cedar-14.Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM heroku/cedar:14
2+
3+
WORKDIR /app
4+
ENV WORKSPACE_DIR="/app/builds" \
5+
S3_BUCKET="lang-python" \
6+
S3_PREFIX="cedar-14/" \
7+
DEBIAN_FRONTEND=noninteractive \
8+
STACK="cedar-14"
9+
10+
RUN apt-get update && apt-get install -y python-pip && rm -rf /var/lib/apt/lists/*
11+
12+
COPY requirements.txt /app/
13+
RUN pip install -r /app/requirements.txt
14+
15+
COPY . /app

builds/dockerenv.default

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
AWS_ACCESS_KEY_ID
2+
AWS_SECRET_ACCESS_KEY
3+
S3_BUCKET
4+
S3_PREFIX
5+
S3_REGION

Dockerfile renamed to builds/heroku-16.Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ WORKDIR /app
44
ENV WORKSPACE_DIR="/app/builds" \
55
S3_BUCKET="lang-python" \
66
S3_PREFIX="heroku-16/" \
7-
DEBIAN_FRONTEND=noninteractive
7+
DEBIAN_FRONTEND=noninteractive \
8+
STACK="heroku-16"
89

910
RUN apt-get update && apt-get install -y python-pip && rm -rf /var/lib/apt/lists/*
1011

Dockerfile.heroku-18 renamed to builds/heroku-18.Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ WORKDIR /app
44
ENV WORKSPACE_DIR="/app/builds" \
55
S3_BUCKET="lang-python" \
66
S3_PREFIX="heroku-18/" \
7-
DEBIAN_FRONTEND=noninteractive
7+
DEBIAN_FRONTEND=noninteractive \
8+
STACK="heroku-18"
89

910
RUN apt-get update && apt-get install --no-install-recommends -y python-pip-whl=9.0.1-2 python-pip=9.0.1-2 python-setuptools python-wheel && rm -rf /var/lib/apt/lists/*
1011

builds/runtimes/pypy

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
# fail hard
4+
set -o pipefail
5+
# fail harder
6+
set -eu
7+
8+
OUT_PREFIX=$1
9+
10+
dep_formula=${0#$WORKSPACE_DIR/} # this is the original script, e.g. pypy-5.3.1
11+
dep_name=$(basename $BASH_SOURCE) # this is us
12+
dep_version=${dep_formula##*"/${dep_name}-"} # "subtract" our name from full version name
13+
dep_package=${dep_name}2-v${dep_version} # it's always "pypy2-…"
14+
dep_dirname=${dep_package}-linux64
15+
dep_archive_name=${dep_dirname}.tar.bz2
16+
dep_url=https://bitbucket.org/pypy/pypy/downloads/${dep_archive_name}
17+
18+
echo "Building PyPy…"
19+
20+
curl -L "${dep_url}" | tar jx -C "${OUT_PREFIX}" --strip-components 1 # extract to $OUT_PREFIX, drop the first directory level, which is the archive name
21+
22+
ln "$OUT_PREFIX/bin/pypy" "$OUT_PREFIX/bin/python"

builds/runtimes/pypy-5.3.1

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,4 @@
22
# Build Path: /app/.heroku/python/
33
# Build Deps: libraries/sqlite
44

5-
# NOTICE: This formula only works for the cedar-14 stack, not cedar.
6-
7-
OUT_PREFIX=$1
8-
9-
echo "Building PyPy…"
10-
SOURCE_TARBALL='https://bitbucket.org/pypy/pypy/downloads/pypy2-v5.3.1-linux64.tar.bz2'
11-
curl -L $SOURCE_TARBALL | tar jx
12-
cp -R pypy2-v5.3.1-linux64/* $OUT_PREFIX
13-
14-
ln $OUT_PREFIX/bin/pypy $OUT_PREFIX/bin/python
5+
source $(dirname $0)/pypy

0 commit comments

Comments
 (0)