|
1 |
| -# |
2 |
| -# To build this Docker image: docker build -t fpm . |
3 |
| -# |
4 |
| -# To run this Docker container interactively: docker run -it fpm |
5 |
| -# |
6 |
| -FROM alpine:3.12 |
7 |
| - |
8 |
| -RUN apk add --no-cache \ |
9 |
| - ruby \ |
10 |
| - ruby-dev \ |
11 |
| - ruby-etc \ |
12 |
| - gcc \ |
13 |
| - libffi-dev \ |
14 |
| - make \ |
15 |
| - libc-dev \ |
16 |
| - rpm \ |
17 |
| - && gem install --no-document fpm |
| 1 | +# Are we running against the minimal container, or the everything |
| 2 | +# container? Minimal is mostly the compiled package tools. Everything |
| 3 | +# pulls in scripting langauges. |
| 4 | +ARG BASE_ENV=everything |
| 5 | + |
| 6 | +# Are we running tests, or a release? Tests build and run against the |
| 7 | +# CWD, where release will use the downloaded gem. |
| 8 | +ARG TARGET=test |
| 9 | + |
| 10 | +# Container to throw an error if called with a bare `docker build .` |
| 11 | +FROM ubuntu:18.04 as error |
| 12 | +RUN echo "\n\n\nHey! Use buildkit. See the Makefile or docs\n\n\n" |
| 13 | +RUN false |
| 14 | + |
| 15 | +# Base container is used for various release and test things |
| 16 | +FROM ubuntu:18.04 as minimal-base |
| 17 | + |
| 18 | +# Runtime deps. Build deps go in the build or test containers |
| 19 | +RUN apt-get update \ |
| 20 | + && apt-get -y dist-upgrade \ |
| 21 | + && apt-get install --no-install-recommends -y \ |
| 22 | + ruby rubygems rubygems-integration \ |
| 23 | + bsdtar \ |
| 24 | + cpio \ |
| 25 | + debsigs \ |
| 26 | + pacman \ |
| 27 | + rpm \ |
| 28 | + squashfs-tools \ |
| 29 | + xz-utils \ |
| 30 | + zip \ |
| 31 | + && rm -rf /var/lib/apt/lists/* \ |
| 32 | + && apt-get clean |
| 33 | +RUN adduser fpm |
| 34 | + |
| 35 | +# everything container includes all the scripting languages. These |
| 36 | +# greatly embiggen the underlying docker container, so they're |
| 37 | +# conditionalized. |
| 38 | +FROM minimal-base AS everything-base |
| 39 | +RUN apt-get update \ |
| 40 | + && apt-get install --no-install-recommends -y \ |
| 41 | + cpanminus \ |
| 42 | + npm \ |
| 43 | + perl \ |
| 44 | + python3-pip \ |
| 45 | + && pip3 --no-cache-dir install setuptools \ |
| 46 | + && pip3 --no-cache-dir install wheel \ |
| 47 | + && pip3 --no-cache-dir install virtualenv virtualenv-tools3 \ |
| 48 | + && update-alternatives --install /usr/bin/python python /usr/bin/python3 10 \ |
| 49 | + && rm -rf /var/lib/apt/lists/* |
| 50 | + |
| 51 | + |
| 52 | +# Run tests against the current working directory. This is a bit |
| 53 | +# orthogonal to the container release process, but it has a lot of |
| 54 | +# same dependancies, so we reuse it. This uses COPY to allow rspect to |
| 55 | +# initall the gems, but runtime usage expects you to mount a volume |
| 56 | +# into /src |
| 57 | +FROM ${BASE_ENV}-base AS test |
| 58 | +WORKDIR /src |
| 59 | +RUN apt-get update \ |
| 60 | + && apt-get install --no-install-recommends -y \ |
| 61 | + gcc make ruby-dev libc-dev lintian git |
| 62 | +# installing ffi here is a bit of an optimization for how COPY and layer reuse works |
| 63 | +RUN gem install --no-ri --no-rdoc ffi |
| 64 | + |
| 65 | +RUN install -d -o fpm /origsrc |
| 66 | +COPY --chown=fpm . /origsrc |
| 67 | +ENV HOME=/origsrc |
| 68 | +ENV BUNDLE_PATH=/origsrc/.bundle |
| 69 | +# Install a specific version of bundler |
| 70 | +WORKDIR /origsrc |
| 71 | +RUN gem install -v "$(grep -A1 '^BUNDLED WITH' Gemfile.lock | tail -1)" bundler |
| 72 | +USER fpm |
| 73 | +RUN bundle install |
| 74 | +CMD bundle exec rspec |
| 75 | + |
| 76 | +# build a container from a released gem. install build deps here, so |
| 77 | +# we can omit them from the final release package |
| 78 | +FROM ${BASE_ENV}-base AS build |
| 79 | +RUN apt-get update |
| 80 | +RUN apt-get install --no-install-recommends -y \ |
| 81 | + gcc make ruby-dev libc-dev |
| 82 | +ENV GEM_PATH /fpm |
| 83 | +ENV PATH "/fpm/bin:${PATH}" |
| 84 | +RUN gem install --no-ri --no-rdoc --install-dir=/fpm fpm |
| 85 | + |
| 86 | +FROM build as release |
| 87 | +COPY --from=build /fpm /fpm |
| 88 | +ENV GEM_PATH /fpm |
| 89 | +ENV PATH "/fpm/bin:${PATH}" |
| 90 | +WORKDIR /src |
| 91 | +ENTRYPOINT ["/fpm/bin/fpm"] |
| 92 | + |
| 93 | +# This target is to help docker buildkit in resolving things. |
| 94 | +FROM ${TARGET} as final |
0 commit comments