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

Redo pipeline stuff for faster deploys #618

Merged
merged 1 commit into from
Oct 9, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Dockerfile-production
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG RUBY_VERSION
FROM ruby:$RUBY_VERSION-alpine AS builder
FROM ruby:$RUBY_VERSION-alpine AS prod-builder

# Build base for gem's native extensions
# tzdata for ruby timezone data
Expand Down Expand Up @@ -27,7 +27,7 @@ WORKDIR /app

COPY Gemfile* package.json yarn.lock ./

RUN bundle install --without development:test \
RUN bundle install -j "$(expr "$(getconf _NPROCESSORS_ONLN)" - 1)" --without development:test \
&& rm -rf $BUNDLE_PATH/cache/*.gem \
&& find $BUNDLE_PATH/gems/ -name "*.c" -delete \
&& find $BUNDLE_PATH/gems/ -name "*.o" -delete
Expand All @@ -45,7 +45,7 @@ RUN rm -rf node_modules/ tmp/cache app/assets vendor/assets spec

#############

FROM ruby:$RUBY_VERSION-alpine
FROM ruby:$RUBY_VERSION-alpine AS prod-runtime

ENV RAILS_ENV=production \
NODE_ENV=production \
Expand All @@ -62,7 +62,7 @@ RUN echo "http://dl-4.alpinelinux.org/alpine/edge/community" >> /etc/apk/reposit
&& apk add -u --no-cache tzdata gcompat postgresql-dev bash nodejs-current \
&& rm -rf /var/cache/apk/*

COPY --from=builder /app /app
COPY --from=builder /bundle /bundle
COPY --from=prod-builder /app /app
COPY --from=prod-builder /bundle /bundle

WORKDIR /app
36 changes: 17 additions & 19 deletions docker-compose-production.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
version: '3.7'
x-args:
&server-args
RUBY_VERSION: '2.6.3' # also update docker-compose.yml & Gemfile
SPLITSIO_CLIENT_ID: $SPLITSIO_CLIENT_ID
STRIPE_PUBLISHABLE_KEY: $STRIPE_PUBLISHABLE_KEY
x-environment:
&server-environment
- ASSET_HOST
Expand Down Expand Up @@ -47,25 +42,28 @@ x-logging:
max-size: 100m
max-file: "1"

x-app: &app
build:
context: .
dockerfile: Dockerfile-production
target: "${DOCKER_BUILD_TARGET:-prod-runtime}"
cache_from:
- "${REPOSITORY_URI:-splitsio-production}:latest"
args:
RUBY_VERSION: '2.6.3' # also update docker-compose.yml & Gemfile
SPLITSIO_CLIENT_ID: $SPLITSIO_CLIENT_ID
STRIPE_PUBLISHABLE_KEY: $STRIPE_PUBLISHABLE_KEY
environment: *server-environment
image: splitsio-production
logging: *default-logging

services:
web:
build:
context: .
dockerfile: Dockerfile-production
args: *server-args
<<: *app
command: bash -c "rm -f /app/tmp/pids/server.pid && bundle exec rails db:migrate && bundle exec rails s -p 3000 -b '0.0.0.0'"
environment: *server-environment
image: web-production
logging: *default-logging
ports:
- 3000:3000
worker:
build:
context: .
dockerfile: Dockerfile-production
args: *server-args
<<: *app
command: bash -c "rm -f /app/tmp/pids/delayed*.pid && bundle exec rake jobs:work" # bin/delayed_job doesn't obey QUEUES
environment: *server-environment
image: worker-production
logging: *default-logging
ports: []
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ x-app: &app
build:
context: .
dockerfile: Dockerfile
cache_from:
- "${REPOSITORY_URI:-splitsio-dev}:latest"
args:
RUBY_VERSION: '2.6.3' # also update docker-compose-production.yml & Gemfile
image: splitsio-dev
tmpfs:
- /tmp
x-backend: &backend
Expand Down Expand Up @@ -80,7 +83,6 @@ services:
<<: *app
command: bash -c "ruby bin/webpack-dev-server"
environment: *client-environment
image: webpacker
logging: *default-logging
ports:
- 3035:3035
Expand All @@ -93,15 +95,13 @@ services:
<<: *backend
command: bash -c "rm -f /app/tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
environment: *server-environment
image: web
logging: *default-logging
ports:
- 3000:3000
worker:
<<: *backend
command: bash -c "rm -f /app/tmp/pids/delayed*.pid && bundle exec rake jobs:work"
environment: *server-environment
image: worker
logging: *default-logging
redis:
image: redis:5.0.5-alpine
Expand Down
7 changes: 5 additions & 2 deletions scripts/after_install.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env bash

cd /app
docker load < dist.tar
rm dist.tar
export REPOSITORY_URI="767531804574.dkr.ecr.us-east-1.amazonaws.com/splitsio-prod-builder"
$(aws ecr get-login --no-include-email --region us-east-1)
docker pull $REPOSITORY_URI:latest
source ~/.env
/usr/local/bin/docker-compose -f docker-compose-production.yml build web