Skip to content

Commit e1ef157

Browse files
directionlessjordansissel
authored andcommitted
fpm tests can now be run through docker.
This changes the Dockerfile to create docker images suitable for running tests (fpm rspec suite in docker) and also as a normal release (using fpm through docker). Fixes #1682, #1453
1 parent db9db67 commit e1ef157

File tree

4 files changed

+113
-17
lines changed

4 files changed

+113
-17
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@ Gemfile.lock
4242

4343
docs/_build
4444
docs/.work
45+
46+
.docker-test-everything
47+
.docker-test-minimal

CONTRIBUTORS

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ sbuss
2121
Brett Gailey (github: dnbert)
2222
Daniel Haskin (github: djhaskin987)
2323
Richard Grainger (github: liger1978)
24+
seph (github: directionless)
2425

2526
If you have contributed (bug reports, feature requests, help in IRC, blog
2627
posts, code, etc) and aren't listed here, please let me know if you wish to be

Dockerfile

+94-17
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,94 @@
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

Makefile

+15
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,18 @@ clean:
5252

5353
publish-docs:
5454
$(MAKE) -C docs publish
55+
56+
# Testing in docker.
57+
# The dot file is a sentinal file that will built a docker image, and tag it.
58+
# The normal make target runs said image, mounting CWD against it.
59+
SECONDARY: .docker-test-minimal .docker-test-everything
60+
.docker-test-%: Gemfile.lock fpm.gemspec Dockerfile
61+
DOCKER_BUILDKIT=1 docker build -t fpm-test-$* --build-arg BASE_ENV=$* --build-arg TARGET=test .
62+
touch "$@"
63+
64+
docker-test-%: .docker-test-%
65+
docker run -v `pwd`:/src fpm-test-$*
66+
67+
docker-release-%:
68+
DOCKER_BUILDKIT=1 docker build -t fpm --build-arg BASE_ENV=$* --build-arg TARGET=release --squash .
69+

0 commit comments

Comments
 (0)