Skip to content

Commit ffc547a

Browse files
hkeelerchosak
andauthored
Move root-required bits of drama-free-django build into Dockerfile (#5145)
* Moves OS dependencies into Dockerfile This change was made to make it easier to run the build and test processes as alternate users, which is sometimes necessary to make the volumes permissions line up with the Docker host. Additionally, changes paths using `/`, which was causing permissions issues when running as non-root. * Converts dfd scripts to use docker build, then run * Revert back to centos:6 Docker image * Revert to original `static_out` path * Override PIP_NO_CACHE_DIR on pip upgrade The version of pip that comes with SCL python27 has a bug that fails to process PIP_NO_CACHE_DIR correctly. Adding --no-cache-dir overrides the envvar, preventing the error. * Removes Mac-specific `cached` volume attribute * Removes unneeded `which` package * Removes unneeded question comment * Add headings and "Notes" section to DFD README.md * Add yarn cache warning to DFD Docker README * Fix yarn warnings by setting $HOME in Dockerfile * Fix typo in drama-free-django/Dockerfile Co-Authored-By: Andy Chosak <andy@chosak.org>
1 parent 23f20e3 commit ffc547a

7 files changed

Lines changed: 78 additions & 22 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
FROM centos:6
2+
3+
ENV SCL_PYTHON_VERSION python27
4+
5+
# Disables pip cache, which reduces build time, and suppresses warnings when run as non-root.
6+
ENV PIP_NO_CACHE_DIR true
7+
8+
ENV DFD_DIR /src/cfgov-refresh
9+
10+
# Must be world writable since alternate uid:gid may be patched in at `docker run` time.
11+
RUN mkdir -p ${DFD_DIR} && chmod 777 ${DFD_DIR}
12+
WORKDIR ${DFD_DIR}
13+
14+
# Sets a consistent $HOME no matter which user the container runs under. This prevents
15+
# permissions issues caused by Docker's default `/` home directory.
16+
ENV HOME /tmp/dfd-home
17+
RUN mkdir -p ${HOME} && chmod 777 ${HOME}
18+
19+
# Install dependencies
20+
# NOTE: You MUST upgrade pip before using it further. The version packaged with SCL has issues
21+
# with both setuptools and the PIP_NO_CACHE_DIR envvar (hence the --no-cache-dir override).
22+
RUN yum install -y centos-release-scl && \
23+
curl -sL https://rpm.nodesource.com/setup_10.x | bash - && \
24+
curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | tee /etc/yum.repos.d/yarn.repo && \
25+
yum install -y ${SCL_PYTHON_VERSION} gcc git nodejs yarn && \
26+
echo "source scl_source enable ${SCL_PYTHON_VERSION}" > /etc/profile.d/scl_python.sh && \
27+
source /etc/profile && \
28+
pip install --no-cache-dir -U pip && \
29+
pip install -U git+https://github.com/cfpb/drama-free-django.git
30+
31+
COPY _build.sh _test.sh docker-entrypoint.sh ./
32+
33+
ENTRYPOINT ["./docker-entrypoint.sh"]

docker/drama-free-django/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Docker-based drama-free-django build and test tools
2+
3+
## Build
4+
15
Run the `build.sh` script from the project root:
26

37
```sh
@@ -6,6 +10,8 @@ docker/drama-free-django/build.sh
610

711
This will run a CentOS 6 container to generate a [drama-free-django](https://github.com/cfpb/drama-free-django) release artifact in the project root named `cfgov_current_build.zip`.
812

13+
## Test
14+
915
To run a basic test of the artifact:
1016

1117
```sh
@@ -14,3 +20,13 @@ docker/drama-free-django/test.sh
1420

1521
This will run a CentOS 6 container to validate the built artifact by extracting it and running Django
1622
[`collectstatic`](https://docs.djangoproject.com/en/1.11/ref/contrib/staticfiles/#collectstatic).
23+
24+
## Notes
25+
26+
1. When running the container as a user that exists on the host, but not in the container, you may notice a warning similar to:
27+
28+
```
29+
/usr/bin/id: cannot find name for user ID 502
30+
```
31+
32+
This is not anything to worry about. It simply means the uid/gid don't match any users/groups setup in the container.

docker/drama-free-django/_build.sh

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,6 @@ if [ ! -d "$cfgov_refresh_volume" ]; then
2222
exit 1
2323
fi
2424

25-
# Install build requirements.
26-
yum install -y centos-release-scl
27-
yum install -y gcc git python27
28-
29-
source /opt/rh/python27/enable
30-
31-
pip install -U pip
32-
pip install -U git+https://github.com/cfpb/drama-free-django.git
33-
34-
curl -sL https://rpm.nodesource.com/setup_10.x | bash -
35-
curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | tee /etc/yum.repos.d/yarn.repo
36-
yum install -y nodejs yarn
37-
3825
# Run the frontend build.
3926
pushd "$cfgov_refresh_volume"
4027
./frontend.sh production

docker/drama-free-django/_test.sh

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ set -x
88

99
artifact_filename=cfgov_current_build.zip
1010
artifact_volume=/cfgov
11+
dfd_test_dir=/tmp/dfd-test/release
1112

1213
# Verify that the artifact volume has been mapped.
1314
if [ ! -d "$artifact_volume" ]; then
@@ -16,15 +17,11 @@ if [ ! -d "$artifact_volume" ]; then
1617
exit 1
1718
fi
1819

19-
# Install runtime requirements.
20-
yum install -y centos-release-scl
21-
yum install -y python27
22-
23-
source /opt/rh/python27/enable
2420

2521
# Extract the artifact in /tmp.
26-
cp "$artifact_volume/$artifact_filename" /tmp
27-
cd /tmp
22+
mkdir -p $dfd_test_dir
23+
cp "$artifact_volume/$artifact_filename" $dfd_test_dir
24+
cd $dfd_test_dir
2825
python "./$artifact_filename"
2926

3027
cd current

docker/drama-free-django/build.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
#!/usr/bin/env bash
22

3-
docker run -v `pwd`:/cfgov centos:6 /cfgov/docker/drama-free-django/_build.sh
3+
set -e
4+
5+
docker build -t cfgov-dfd-builder docker/drama-free-django
6+
7+
docker run \
8+
--rm \
9+
-u $(id -u):$(id -g) \
10+
-v $(pwd):/cfgov \
11+
cfgov-dfd-builder ./_build.sh
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash --login
2+
# This entrypoint is used primarily as means of setting up a consistent
3+
# shell environment no matter which user the process runs as. By using
4+
# --login, it guarantees /etc/profile is always sourced, unlike the
5+
# non-login, non-interactive shell you get by default with `docker run`.
6+
7+
exec "$@"

docker/drama-free-django/test.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
#!/usr/bin/env bash
22

3-
docker run -v `pwd`:/cfgov centos:6 /cfgov/docker/drama-free-django/_test.sh
3+
set -e
4+
5+
docker build -t cfgov-dfd-builder docker/drama-free-django
6+
7+
docker run \
8+
--rm \
9+
-u $(id -u):$(id -g) \
10+
-v $(pwd):/cfgov \
11+
cfgov-dfd-builder ./_test.sh

0 commit comments

Comments
 (0)