Skip to content

Commit a4888cf

Browse files
committed
Slim down the image
* Test-related code is moved out of tha main image
1 parent b905d96 commit a4888cf

File tree

5 files changed

+50
-15
lines changed

5 files changed

+50
-15
lines changed

Diff for: Dockerfile

+24-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
1-
FROM codeclimate/alpine-ruby:b38
1+
FROM alpine:3.6
2+
3+
RUN adduser -u 9000 -D app
24

35
WORKDIR /usr/src/app
4-
RUN apk --update add ruby ruby-bundler git
56

6-
COPY Gemfile* /usr/src/app/
7-
RUN bundle install --jobs 4 && \
8-
rm -rf /usr/share/ri
7+
RUN apk add --no-cache ruby ruby-json git && \
8+
gem install --no-ri --no-rdoc bundler && \
9+
rm -r ~/.gem
910

10-
RUN adduser -u 9000 -D app
11-
USER app
11+
COPY Gemfile* /usr/src/app/
12+
RUN bundle install --without=test --no-cache && \
13+
rm -rf ~/.bundle /usr/lib/ruby/gems/2.4.0/cache/* /usr/share/ri
1214

1315
COPY DATABASE_VERSION /usr/src/app/DATABASE_VERSION
1416

15-
RUN bundle-audit update
17+
COPY bin bin/
18+
COPY lib lib/
19+
RUN chown -R app:app .
20+
21+
USER app
1622

17-
COPY . /usr/src/app
23+
# The following step has to be ran by app user aas it depends on $HOME
24+
RUN bundle-audit update && \
25+
for f in ~/.local/share/ruby-advisory-db/* ~/.local/share/ruby-advisory-db/.*; do \
26+
name="$(basename "$f")"; \
27+
test "$name" = "gems" || \
28+
test "$name" = "." || \
29+
test "$name" = ".." || \
30+
test "$name" = ".git" || \
31+
rm -r "$f"; \
32+
done
1833

1934
CMD ["/usr/src/app/bin/bundler-audit"]

Diff for: Dockerfile.test

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM codeclimate/codeclimate-bundler-audit
2+
3+
USER root
4+
5+
RUN bundler install --no-cache --with="development test"
6+
7+
COPY Rakefile ./
8+
COPY spec spec/
9+
RUN chown -R app:app Rakefile spec
10+
11+
user app
12+
13+
CMD ["bundle", "exec", "rake"]

Diff for: Makefile

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
.PHONY: image test citest update_version
22

33
IMAGE_NAME ?= codeclimate/codeclimate-bundler-audit
4+
TEST_IMAGE_NAME ?= $(IMAGE_NAME)-test
45

56
image:
67
docker build --rm -t $(IMAGE_NAME) .
78

8-
test: image
9-
docker run -e PAGER=more --tty --interactive --rm $(IMAGE_NAME) bundle exec rake
9+
test-image: image
10+
docker build --rm -t $(TEST_IMAGE_NAME) -f Dockerfile.test .
1011

11-
citest:
12-
docker run --rm $(IMAGE_NAME) bundle exec rake
12+
test:
13+
@$(MAKE) test-image > /dev/null
14+
docker run \
15+
-e PAGER=more \
16+
--tty --interactive --rm \
17+
$(TEST_IMAGE_NAME)
1318

1419
update_database:
1520
date > DATABASE_VERSION

Diff for: circle.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ dependencies:
1212
--env GCR_JSON_KEY
1313
--volume /var/run/docker.sock:/var/run/docker.sock
1414
codeclimate/patrick pull || true
15-
- make image
15+
- make test-image
1616

1717
test:
1818
override:
19-
- make citest
19+
- make test
2020

2121
deployment:
2222
registry:

Diff for: lib/cc/engine/bundler_audit/analyzer.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require "tmpdir"
2+
13
module CC
24
module Engine
35
module BundlerAudit

0 commit comments

Comments
 (0)