Skip to content
This repository has been archived by the owner on Mar 21, 2020. It is now read-only.

Commit

Permalink
Circle CI Improvements (#245)
Browse files Browse the repository at this point in the history
* Add yarn install steps and run all of rake

* Fix yml error

* Get db url in test too

* Wait for DB and add .node-version file

* Try to setup db

* Add some postgres env vars

* See if database url is set

* Try this set of env vars

* I think this is the secret sauce

* Try test prepare

* Take db setup from glassy

* Try db reset at the end

* Add junit formatters for circleci

* Can I get away without this require?

* No more output cause it wasn't working

* Try migrating db

* Try this, I think the new rails version didn't like my schema version syntax

* Try test prepare

* I don't know why I need to migrate here

* Only migrate

* Fix deploy and try to deploy from this branch

* Get Dockerfile working and no more procompile outside Docker

* Only deploy on master again
  • Loading branch information
coreyja authored Feb 9, 2019
1 parent 7de530f commit b293cd2
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 14 deletions.
50 changes: 44 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ jobs:
test:
working_directory: ~/package-tracker
docker:
- image: pawurb/ruby-jemalloc-node-yarn:latest
- image: circleci/ruby:2.5.3-node-browsers
environment:
RAILS_ENV: test
RACK_ENV: test
- image: circleci/postgres:9.4.12-alpine
steps:
- checkout

# Restore bundle cache
- type: cache-restore
key: package-tracker-v1-{{ checksum "Gemfile.lock" }}
key: package-tracker-v1-bundler-{{ checksum ".ruby-version" }}-{{ checksum "Gemfile.lock" }}

# Bundle install dependencies
- run: bundle config --local path "vendor/bundle"
Expand All @@ -23,12 +24,49 @@ jobs:

# Store bundle cache
- type: cache-save
key: package-tracker-v1-{{ checksum "Gemfile.lock" }}
key: package-tracker-v1-bundler-{{ checksum ".ruby-version" }}-{{ checksum "Gemfile.lock" }}
paths:
- vendor/bundle


# Restore yarn cache
- type: cache-restore
key: package-tracker-v1-yarn-{{ checksum ".node-version" }}-{{ checksum "yarn.lock" }}

# Bundle install dependencies
- run: yarn install --frozen-lockfile

# Store bundle cache
- type: cache-save
key: package-tracker-v1-yarn-{{ checksum ".node-version" }}-{{ checksum "yarn.lock" }}
paths:
- node_modules

- type: shell
command: |
bundle exec rubocop \
--config .rubocop.yml \
--format progress \
--force-exclusion \
$(bundle exec rubocop --list-target-files | circleci tests split --split-by=filesize)
- run:
name: Wait for DB
command: dockerize -wait tcp://localhost:5432 -timeout 1m

- run:
name: Setup DB
command: bundle exec rake db:create db:schema:load db:migrate --trace

# Run rspec in parallel
- type: shell
command: bundle exec rubocop
command: |
bundle exec rspec --profile 10 \
--format RspecJunitFormatter \
--out /tmp/test-results/rspec.xml \
--format progress \
$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
# Save artifacts
- type: store_test_results
Expand All @@ -39,9 +77,9 @@ jobs:
steps:
- add_ssh_keys:
fingerprints:
- "27:70:c5:09:00:c4:03:97:13:2e:f5:47:e4:a2:3f:97"
- "05:78:af:2e:79:4d:c9:bf:ac:ca:8e:70:c1:e7:28:0a"
- run: |
echo 'dokku.coreyja.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBG2yW0ZfNQWo1fXW1Tca2rTJE9dcN+8uCadvIp0YSsrgFd/6qv14KCR+ClmmIpBqXQV04yjZ3b09P6APJrQm3wg=' >> ~/.ssh/known_hosts
echo 'dokku.coreyja.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBP6nGreJURW3y+sMBMJFcZz1/Ne58qmLWATp/dhqqSiN9fU70ZqupHe4V6aCD7jLyGOY2EXGVAHM3LQbYB50QhQ=' >> ~/.ssh/known_hosts
- checkout
- run:
name: Deploy with git push
Expand Down
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11.9.0
13 changes: 9 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ FROM pawurb/ruby-jemalloc-node-yarn:latest

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata && apt-get clean

COPY Gemfile* /tmp/
WORKDIR /tmp
RUN bundle install --jobs 5 --retry 5 --without development test

RUN mkdir /app
COPY Gemfile* /app/
COPY package.json /app/
COPY yarn.lock /app/
WORKDIR /app
RUN bundle install --frozen --jobs 5 --retry 5 --without development test
RUN yarn install --frozen-lockfile

COPY . /app

ENV RAILS_ENV production
ENV RACK_ENV production
RUN bundle exec rake assets:precompile

CMD ["bin/run-dev.sh"]
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,10 @@ group :development do
gem 'spring-watcher-listen', '~> 2.0.0'
end

group :test do
gem 'rspec_junit_formatter'
gem 'rubocop-junit-formatter'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ GEM
rspec-mocks (~> 3.8.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
rspec_junit_formatter (0.4.1)
rspec-core (>= 2, < 4, != 2.12.0)
rubocop (0.58.2)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
Expand All @@ -306,6 +308,7 @@ GEM
rubocop-coreyja (0.2.0)
rubocop (= 0.58.2)
rubocop-rspec (= 1.27.0)
rubocop-junit-formatter (0.1.4)
rubocop-rspec (1.27.0)
rubocop (>= 0.56.0)
ruby-progressbar (1.10.0)
Expand Down Expand Up @@ -412,7 +415,9 @@ DEPENDENCIES
rest-client
rspec
rspec-rails
rspec_junit_formatter
rubocop-coreyja (= 0.2.0)
rubocop-junit-formatter
sass-rails (~> 5.0)
simple_form
skylight
Expand Down
1 change: 0 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
],
"scripts": {
"dokku": {
"predeploy": "bundle exec rake assets:precompile",
"postdeploy": "bundle exec rake db:migrate"
}
}
Expand Down
6 changes: 4 additions & 2 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
default: &default
adapter: postgresql
encoding: unicode
host: localhost
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
host: localhost
user: postgres
password:

development:
<<: *default
Expand Down Expand Up @@ -58,7 +60,7 @@ development:
# Do not set this db to the same as development or production.
test:
<<: *default
database: package-tracker_test
url: <%= ENV['DATABASE_URL'] %>

# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
Expand Down
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20180922231837) do
ActiveRecord::Schema.define(version: 2018_09_22_231837) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down

0 comments on commit b293cd2

Please sign in to comment.