|
| 1 | +# We use Debian as base image for the reasons given on |
| 2 | +# https://pythonspeed.com/articles/base-image-python-docker-images/ |
| 3 | +# see https://www.debian.org |
| 4 | +FROM debian:10.5-slim |
| 5 | + |
| 6 | +################## |
| 7 | +# As user `root` # |
| 8 | +################## |
| 9 | + |
| 10 | +# When you are on a Linux machine and when you run `docker build`, then set the |
| 11 | +# `--build-arg`s `GID` and `UID` to your user id and its primary group id. This |
| 12 | +# makes it seamless to use and generate files from within the shell of |
| 13 | +# a running docker container based on this image and access those files later |
| 14 | +# on the host. |
| 15 | +ARG UID=1000 |
| 16 | +ARG GID=1000 |
| 17 | + |
| 18 | +#-------------------------------------------# |
| 19 | +# Create non-root user `me` and group `us` # |
| 20 | +#-------------------------------------------# |
| 21 | +# which are used to run commands in later for security reasons, |
| 22 | +# see https://medium.com/@mccode/processes-in-containers-should-not-run-as-root-2feae3f0df3b |
| 23 | +RUN \ |
| 24 | + addgroup --system --gid ${GID} us && \ |
| 25 | + adduser --system --uid ${UID} --ingroup us me |
| 26 | + |
| 27 | +#-------------------------------# |
| 28 | +# Make `bash` the default shell # |
| 29 | +#-------------------------------# |
| 30 | +# In particular, `ln ... bash /bin/sh` makes Python's `subprocess` module use |
| 31 | +# `bash` by default. If we want to make sure that `bash` is always used |
| 32 | +# regardless of the default shell, we can pass `executable="/bin/bash"` to |
| 33 | +# Python's `subprocess#run` function. |
| 34 | +RUN \ |
| 35 | + ln --symbolic --force \ |
| 36 | + bash /bin/sh && \ |
| 37 | + sed --in-place --expression \ |
| 38 | + "s#bin/dash#bin/bash#" \ |
| 39 | + /etc/passwd |
| 40 | + |
| 41 | +#---------------------# |
| 42 | +# Install `dumb-init` # |
| 43 | +#---------------------# |
| 44 | +# a minimal init system for Linux containers, see https://github.com/Yelp/dumb-init |
| 45 | +RUN \ |
| 46 | + # Retrieve new lists of packages |
| 47 | + apt-get update && \ |
| 48 | + # Install `dumb-init` |
| 49 | + apt-get install --assume-yes --no-install-recommends \ |
| 50 | + dumb-init && \ |
| 51 | + # Remove unused packages, erase archive files, and remove lists of packages |
| 52 | + apt-get autoremove --assume-yes && \ |
| 53 | + apt-get clean && \ |
| 54 | + rm --recursive --force /var/lib/apt/lists/* |
| 55 | + |
| 56 | +#---------------------------# |
| 57 | +# Install development tools # |
| 58 | +#---------------------------# |
| 59 | +# * GNU Make to run often needed commands, see |
| 60 | +# https://www.gnu.org/software/make |
| 61 | +# * Node package manager to install Node development tools, see |
| 62 | +# https://www.npmjs.com |
| 63 | +# * Another JSON Schema Validator (AJV) command-line interface to validate |
| 64 | +# schemas and files, see https://github.com/ajv-validator/ajv-cli |
| 65 | +RUN \ |
| 66 | + # Retrieve new lists of packages |
| 67 | + apt-get update && \ |
| 68 | + # Install system development tools |
| 69 | + apt-get install --assume-yes --no-install-recommends \ |
| 70 | + make \ |
| 71 | + npm && \ |
| 72 | + # Upgrade Node package manager to version 6.14.7 |
| 73 | + npm install npm@6.14.7 --global && \ |
| 74 | + # Install Node development tools |
| 75 | + npm install --global ajv-cli@3.2.1 && \ |
| 76 | + npm install --global format-graphql@1.4.0 && \ |
| 77 | + npm install --global graphql-schema-linter@0.5.0 && \ |
| 78 | + npm install --global prettier@2.0.5 && \ |
| 79 | + # Remove unused packages, erase archive files, and remove lists of packages |
| 80 | + apt-get autoremove --assume-yes && \ |
| 81 | + apt-get clean && \ |
| 82 | + rm --recursive --force /var/lib/apt/lists/* |
| 83 | + |
| 84 | +#-------------------------# |
| 85 | +# Set-up `/app` directory # |
| 86 | +#-------------------------# |
| 87 | +# Make the `/app` directory link to the `/home/me/app` directory and make both |
| 88 | +# be owned by the user `me` and the group `us`. |
| 89 | +RUN \ |
| 90 | + mkdir /home/me/app && \ |
| 91 | + chown me:us /home/me/app && \ |
| 92 | + ln --symbolic /home/me/app /app && \ |
| 93 | + chown me:us --no-dereference /app |
| 94 | + |
| 95 | +################ |
| 96 | +# As user `me` # |
| 97 | +################ |
| 98 | +# Switch to the user `me` |
| 99 | +USER me |
| 100 | +ENV USER=me |
| 101 | +# Make `/app` the default directory |
| 102 | +WORKDIR /app |
| 103 | + |
| 104 | +#-------------------------------------------# |
| 105 | +# Set-up for containers based on this image # |
| 106 | +#-------------------------------------------# |
| 107 | +# Create mount points to mount the project and the installed Python |
| 108 | +# dependencies. |
| 109 | +VOLUME /app/ |
| 110 | + |
| 111 | +# Run commands within the process supervisor and init system `dumb-init` |
| 112 | +ENTRYPOINT ["/usr/bin/dumb-init", "--"] |
| 113 | +# Make `bash` the default command |
| 114 | +CMD ["bash"] |
0 commit comments