Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce Docker image #164

Merged
merged 1 commit into from Feb 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions .dockerignore
@@ -0,0 +1,18 @@
.env*
.git
.gitignore
.codeclimate.yml
.dockerignore
.hound.yml
.travis.yml
LICENSE.md
README.md
docker-compose.*
duduribeiro marked this conversation as resolved.
Show resolved Hide resolved
Dockerfile
log/*
node_modules/*
public/assets/*
storage/*
public/packs/*
public/packs-test/*
tmp/*
45 changes: 36 additions & 9 deletions Dockerfile
@@ -1,14 +1,14 @@
FROM ruby:2.5.0-alpine

LABEL maintainer="opensanca@opensanca.com"
# build stage
FROM ruby:2.5.0-alpine AS builder

ARG build_without
ARG rails_env="development"
ARG build_without=""
ARG to_remove

ENV SECRET_KEY_BASE=dumb
ENV EXECJS_RUNTIME=Node

RUN apk update \
&& apk add \
RUN apk add --update --no-cache \
openssl \
tar \
build-base \
Expand All @@ -21,10 +21,37 @@ RUN apk update \
&& tar -xf latest.tar.gz -C /opt/yarn --strip 1 \
&& mkdir -p /var/app

ENV PATH="$PATH:/opt/yarn/bin" BUNDLE_PATH="/gems" BUNDLE_JOBS=2 RAILS_ENV=${rails_env} BUNDLE_WITHOUT=${bundle_without}
ENV PATH="$PATH:/opt/yarn/bin" BUNDLE_JOBS=4 RAILS_ENV=${rails_env} BUNDLE_WITHOUT=${bundle_without}

COPY . /var/app
WORKDIR /var/app

RUN bundle install && yarn && bundle exec rake assets:precompile
CMD rails s -b 0.0.0.0
RUN bundle install && yarn && bundle exec rake assets:precompile \
&& rm -rf /usr/local/bundle/cache/*.gem \
&& find /usr/local/bundle/gems/ -name "*.c" -delete \
&& find /usr/local/bundle/gems/ -name "*.o" -delete \
&& rm -rf $to_remove

# final stage
FROM ruby:2.5.0-alpine
LABEL maintainer="contato@opensanca.com.br"

ARG extra_packages

RUN apk add --update --no-cache \
openssl \
tzdata \
postgresql-dev \
postgresql-client \
$extra_packages

COPY --from=builder /usr/local/bundle/ /usr/local/bundle/
COPY --from=builder /var/app /var/app

ENV RAILS_LOG_TO_STDOUT true

WORKDIR /var/app

EXPOSE 3000

CMD bin/rails s -b 0.0.0.0
24 changes: 13 additions & 11 deletions docker-compose.yml
Expand Up @@ -21,8 +21,12 @@ services:
timeout: 5s
retries: 3

web:
build: .
web: &base_image
build:
context: .
args:
- extra_packages=nodejs
- rails_env=development
depends_on:
- db
- redis
Expand All @@ -33,15 +37,16 @@ services:
- 3000:3000
volumes:
- .:/var/app
- gemdata:/gems
command: rails s -b '0.0.0.0'
- gemdata:/usr/local/bundle/
command: bin/rails s -b '0.0.0.0'
environment:
DATABASE_URL: postgres://postgres:@db/
EXECJS_RUNTIME: Node
REDIS_URL: redis://redis:6379
SMTP_ADDRESS: mail

jobs:
build: .
<<: *base_image
depends_on:
- db
- redis
Expand All @@ -50,12 +55,9 @@ services:
- redis
volumes:
- .:/var/app
- gemdata:/gems
command: sidekiq -q critical,2 -q default
environment:
DATABASE_URL: postgres://postgres:@db/
REDIS_URL: redis://redis:6379
SMTP_ADDRESS: mail
- gemdata:/usr/local/bundle/
command: bundle exec sidekiq -q critical,2 -q default
ports: []

mail:
image: mailhog/mailhog:latest
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"name": "opensanca_jobs",
"private": true,
"engines": {
"node": "8.10.0"
"node": "8.9.3"
},
"dependencies": {
"autoprefixer": "^7.1.1",
Expand Down