Skip to content

Commit

Permalink
Further cleanups of docker image
Browse files Browse the repository at this point in the history
plus adding a health check
  • Loading branch information
Dan Buch committed Nov 1, 2018
1 parent 4bc5cda commit 00b0bc5
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 10 deletions.
27 changes: 25 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
*.log
/.bundle
/.docker
/.env
/.git
.travis.yml
/.rake_tasks
/.rspec
/.rubocop.yml
/.rubocop_todo.yml
/.simplecov
/.travis.yml
/.vagrant
/CONTRIBUTING.md
/Dockerfile
/Procfile
/README.md
/coverage
/docker-compose.yml
/example_payloads
/examples
/init.rb
/script/build-s3-index-html
/script/docker-build-and-push
/script/handle-docker-config
/script/validate-example-payloads-with-docker
/spec
/tmp
/vendor
12 changes: 7 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ WORKDIR /usr/src/app

ARG GITHUB_OAUTH_TOKEN=notset

RUN bundle config --global frozen 1

COPY . .

RUN bundle install
RUN git describe --always --dirty --tags | tee VERSION
RUN bundle install --frozen --deployment --without='development test' --clean
RUN bundle exec rake assets:precompile GITHUB_OAUTH_TOKEN=$GITHUB_OAUTH_TOKEN
RUN tar -cjf public.tar.bz2 public && rm -rf public

FROM ruby:2.5.3-slim
LABEL maintainer Travis CI GmbH <[email protected]>
Expand All @@ -18,7 +18,9 @@ ENV TRAVIS_BUILD_DUMP_BACKTRACE true
ENV PORT 4000

COPY --from=builder /usr/src/app /usr/src/app
COPY --from=builder /usr/local/bundle /usr/local/bundle
COPY --from=builder /root/.bundle /root/.bundle
COPY --from=builder /usr/local/bundle/config /usr/local/bundle/config
RUN rm -rf .git

HEALTHCHECK --interval=5s CMD script/healthcheck
EXPOSE 4000/tcp
CMD ["script/server"]
9 changes: 7 additions & 2 deletions lib/travis/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ def top

class << self
def version
@version ||= `git rev-parse HEAD 2>/dev/null || \\
echo "${HEROKU_SLUG_COMMIT:-unknown}"`.strip
return @version if @version
@version ||= `git describe --always --dirty --tags 2>/dev/null`.strip
@version = nil unless $?.success?
@version ||= ENV.fetch('HEROKU_SLUG_COMMIT', nil)
@version ||= top.join('VERSION').read if top.join('VERSION').exist?
@version ||= 'unknown'
@version
end

def self.register(key)
Expand Down
6 changes: 6 additions & 0 deletions script/healthcheck
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env ruby
require 'net/http'
require 'uri'
Net::HTTP.get(
URI("http://localhost:#{ENV.fetch('PORT', '4000')}/uptime")
)
8 changes: 7 additions & 1 deletion script/server
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ main() {
-w "${PUMA_WORKERS:-2}"
)

if [[ "${RACK_ENV}" == development && ! "${DISABLE_RERUN}" ]]; then
if [[ -f public.tar.bz2 && ! -d public ]]; then
tar -xf public.tar.bz2
fi

if [[ "${RACK_ENV}" == development ]] &&
[[ ! -f /.dockerenv ]] &&
[[ ! "${DISABLE_RERUN}" ]]; then
cmd=(bundle exec rerun -p '**/*.{rb,ru}' -- "${cmd[@]}")
fi

Expand Down

0 comments on commit 00b0bc5

Please sign in to comment.