From 46d36ed88b491e9ad16ea00010c05b3fadda9364 Mon Sep 17 00:00:00 2001 From: Eric Schultz Date: Thu, 6 Sep 2018 16:26:16 -0500 Subject: [PATCH 01/10] Update ruby to 2.3.7 --- .ruby-version | 2 +- Gemfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.ruby-version b/.ruby-version index e75da3e6..00355e29 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.3.6 +2.3.7 diff --git a/Gemfile b/Gemfile index 88b0285c..30734333 100755 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -ruby '2.3.6' +ruby '2.3.7' gem 'rake' gem 'rails', '3.2.22.5' gem 'rails_12factor' From 2f86f07ba1e8f04c867e3100a5cecefbb0e86e38 Mon Sep 17 00:00:00 2001 From: Eric Schultz Date: Thu, 6 Sep 2018 16:29:07 -0500 Subject: [PATCH 02/10] Update to a more usable Docker format --- .dockerignore | 5 +- Dockerfile | 22 --------- README.md | 1 + config/application.rb | 2 +- db/structure.sql | 2 +- docker/build/Dockerfile | 16 +++++++ docker/build/docker-compose.yml | 23 ++++++++++ docker/debug/Dockerfile | 28 +++++++++++ .../debug/docker-compose.yml | 46 +++++++++++-------- run | 2 +- script/build/debian/java.sh | 4 ++ script/build/debian/node.sh | 6 +++ script/build/debian/postgres.sh | 4 ++ script/build/debian/prebuild.sh | 4 ++ script/debian_setup.sh | 2 +- 15 files changed, 121 insertions(+), 46 deletions(-) delete mode 100644 Dockerfile create mode 100644 docker/build/Dockerfile create mode 100644 docker/build/docker-compose.yml create mode 100644 docker/debug/Dockerfile rename docker-compose.yml => docker/debug/docker-compose.yml (54%) create mode 100755 script/build/debian/java.sh create mode 100755 script/build/debian/node.sh create mode 100755 script/build/debian/postgres.sh create mode 100755 script/build/debian/prebuild.sh diff --git a/.dockerignore b/.dockerignore index b7dded27..cc86e3f0 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,4 +3,7 @@ !Gemfile.lock !package.json !package-lock.json -!script/debian_setup.sh \ No newline at end of file +!script/build/debian/*.sh +!Rakefile +!config/* +!db/* \ No newline at end of file diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 30baac89..00000000 --- a/Dockerfile +++ /dev/null @@ -1,22 +0,0 @@ -FROM ruby:2.3 -ARG USER -RUN mkdir /myapp -COPY Gemfile /myapp/Gemfile -COPY Gemfile.lock /myapp/Gemfile.lock -COPY package.json /myapp/package.json -COPY package-lock.json /myapp/package-lock.json -COPY script/debian_setup.sh /myapp/script/debian_setup.sh -WORKDIR /myapp -RUN script/debian_setup.sh -RUN groupadd -r -g 1000 $USER -RUN useradd -r -m -g $USER -u 1000 $USER -RUN chown -R $USER /usr/local/bundle -RUN chgrp -R $USER /usr/local/bundle -RUN chown -R $USER /myapp -RUN chgrp -R $USER /myapp -RUN chown -R $USER /usr/lib/node_modules -RUN chgrp -R $USER /usr/lib/node_modules -USER $USER -RUN bundle install -EXPOSE 5000 -CMD foreman start diff --git a/README.md b/README.md index 1f87a915..cda0bf49 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ You will likely need to logout and log back in again. #### Build your docker-container and start it up for initial set up. We'll keep this running in the console we'll call **console 1** ``` +cd docker/debug docker-compose build docker-compose up ``` diff --git a/config/application.rb b/config/application.rb index d34386dc..32ee9cec 100755 --- a/config/application.rb +++ b/config/application.rb @@ -5,7 +5,7 @@ require 'rails/all' Bundler.require *Rails.groups(:assets) if defined?(Bundler) -require File.expand_path('lib/htp') # Hamster Table Print +#require File.expand_path('lib/htp') # Hamster Table Print module Commitchange class Application < Rails::Application diff --git a/db/structure.sql b/db/structure.sql index 1aaa1958..5609c55f 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -3,7 +3,7 @@ -- -- Dumped from database version 9.6.5 --- Dumped by pg_dump version 9.6.9 +-- Dumped by pg_dump version 9.6.10 SET statement_timeout = 0; SET lock_timeout = 0; diff --git a/docker/build/Dockerfile b/docker/build/Dockerfile new file mode 100644 index 00000000..49409f39 --- /dev/null +++ b/docker/build/Dockerfile @@ -0,0 +1,16 @@ +FROM ruby:2.3.7-stretch +ARG USER +RUN mkdir /myapp +COPY script/build/debian/prebuild.sh myapp/script/build/debian/prebuild.sh +RUN myapp/script/build/debian/prebuild.sh +COPY script/build/debian/node.sh myapp/script/build/debian/node.sh +RUN myapp/script/build/debian/node.sh +COPY script/build/debian/postgres.sh myapp/script/build/debian/postgres.sh +RUN myapp/script/build/debian/postgres.sh +COPY script/build/debian/java.sh myapp/script/build/debian/java.sh +RUN myapp/script/build/debian/java.sh +WORKDIR /myapp +COPY Gemfile /myapp/Gemfile +COPY Gemfile.lock /myapp/Gemfile.lock +RUN bundle install +CMD rake db:create db:structure:load test:prepare && rake spec && npx jest && npm run build-all diff --git a/docker/build/docker-compose.yml b/docker/build/docker-compose.yml new file mode 100644 index 00000000..2bebe9b1 --- /dev/null +++ b/docker/build/docker-compose.yml @@ -0,0 +1,23 @@ +# License: CC0-1.0 +version: '2' +services: + build: + build: + context: ../.. + dockerfile: docker/build/Dockerfile + depends_on: + - db + - memcached + environment: + - DATABASE_HOST=db + - MEMCACHE_SERVERS=memcached + volumes: + - ../../:/myapp + db: + image: postgres:9.6 + environment: + POSTGRES_USER: "admin" + POSTGRES_PASSWORD: "password" + memcached: + image: memcached + diff --git a/docker/debug/Dockerfile b/docker/debug/Dockerfile new file mode 100644 index 00000000..66785018 --- /dev/null +++ b/docker/debug/Dockerfile @@ -0,0 +1,28 @@ +FROM ruby:2.3.7-stretch +ARG USER +RUN mkdir /myapp +COPY script/build/debian/prebuild.sh myapp/script/build/debian/prebuild.sh +RUN myapp/script/build/debian/prebuild.sh +COPY script/build/debian/node.sh myapp/script/build/debian/node.sh +RUN myapp/script/build/debian/node.sh +COPY script/build/debian/postgres.sh myapp/script/build/debian/postgres.sh +RUN myapp/script/build/debian/postgres.sh +COPY script/build/debian/java.sh myapp/script/build/debian/java.sh +RUN myapp/script/build/debian/java.sh +WORKDIR /myapp +RUN groupadd -r -g 1000 $USER +RUN useradd -r -m -g $USER -u 1000 $USER +RUN chown -R $USER /usr/local/bundle +RUN chgrp -R $USER /usr/local/bundle +RUN chown -R $USER /myapp +RUN chgrp -R $USER /myapp +RUN chown -R $USER /usr/lib/node_modules +RUN chgrp -R $USER /usr/lib/node_modules +COPY Gemfile /myapp/Gemfile +COPY Gemfile.lock /myapp/Gemfile.lock +RUN bundle install +RUN chown -R $USER /myapp/Gemfile +RUN chgrp -R $USER /myapp/Gemfile.lock +USER $USER +EXPOSE 5000 +CMD foreman start diff --git a/docker-compose.yml b/docker/debug/docker-compose.yml similarity index 54% rename from docker-compose.yml rename to docker/debug/docker-compose.yml index 522377b1..4f4378ee 100644 --- a/docker-compose.yml +++ b/docker/debug/docker-compose.yml @@ -1,29 +1,37 @@ # License: CC0-1.0 version: '2' services: + web: + build: + context: ../.. + dockerfile: docker/debug/Dockerfile + args: + - USER + user: ${USER} + + environment: + - DATABASE_HOST=db + - MEMCACHE_SERVERS=memcached + - USER=${USER} + + volumes: + - ../../:/myapp + + ports: + - "5000:5000" + depends_on: + - db + - memcached db: image: postgres:9.6 environment: POSTGRES_USER: "admin" POSTGRES_PASSWORD: "password" - volumes: - - ./postgres-data:/var/lib/postgresql/data - web: - build: - context: . - args: - - USER - volumes: - - .:/myapp - ports: - - "5000:5000" - depends_on: - - db - - memcached - user: ${USER} - environment: - - USER=${USER} - - DATABASE_HOST=db - - MEMCACHE_SERVERS=memcached memcached: image: memcached + + + + + + diff --git a/run b/run index 9bb36460..bf6549c3 100755 --- a/run +++ b/run @@ -1,2 +1,2 @@ #!/usr/bin/env bash -docker-compose run web $@ +docker-compose -f docker/debug/docker-compose.yml run web $@ diff --git a/script/build/debian/java.sh b/script/build/debian/java.sh new file mode 100755 index 00000000..983907ce --- /dev/null +++ b/script/build/debian/java.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -e + +apt-get -yy install default-jre \ No newline at end of file diff --git a/script/build/debian/node.sh b/script/build/debian/node.sh new file mode 100755 index 00000000..29c45c06 --- /dev/null +++ b/script/build/debian/node.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -e + +curl -sL https://deb.nodesource.com/setup_9.x | bash - +apt-get update -qq && apt-get install -y nodejs +npm install npm@^6 -g \ No newline at end of file diff --git a/script/build/debian/postgres.sh b/script/build/debian/postgres.sh new file mode 100755 index 00000000..8f264f84 --- /dev/null +++ b/script/build/debian/postgres.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -e + +apt-get -yy install libpq5=9.6.10-0+deb9u1 libpq-dev=9.6.10-0+deb9u1 postgresql=9.6+181+deb9u1 diff --git a/script/build/debian/prebuild.sh b/script/build/debian/prebuild.sh new file mode 100755 index 00000000..2c8fe862 --- /dev/null +++ b/script/build/debian/prebuild.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -e + +apt-get update -qq && apt-get install -y build-essential \ No newline at end of file diff --git a/script/debian_setup.sh b/script/debian_setup.sh index 5839d3b7..d36dfa9c 100755 --- a/script/debian_setup.sh +++ b/script/debian_setup.sh @@ -2,7 +2,7 @@ set -e curl -sL https://deb.nodesource.com/setup_9.x | bash - -echo 'deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main' > /etc/apt/sources.list.d/pgdg.list + wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs postgresql-9.6 default-jre npm install npm@^6 -g \ No newline at end of file From 7cc58e17ff86d0267b86953bfeb27c66eca0d60c Mon Sep 17 00:00:00 2001 From: Eric Schultz Date: Thu, 6 Sep 2018 16:53:47 -0500 Subject: [PATCH 03/10] Add travis ci file --- .travis.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..0ae3e283 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +sudo: required + +language: ruby + +services: +- docker + +before_install: +- docker-compose -f docker/build/docker-compose.yml build + +script: +- docker-compose -f docker/build/docker-compose.yml up \ No newline at end of file From 1679e9f2ddad9715c01e8333da8d2bf2a4f19d53 Mon Sep 17 00:00:00 2001 From: Eric Schultz Date: Thu, 6 Sep 2018 17:11:22 -0500 Subject: [PATCH 04/10] test two! --- .travis.yml | 2 +- docker/build/Dockerfile | 2 +- script/test.sh | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) create mode 100755 script/test.sh diff --git a/.travis.yml b/.travis.yml index 0ae3e283..2fafe21e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,4 +9,4 @@ before_install: - docker-compose -f docker/build/docker-compose.yml build script: -- docker-compose -f docker/build/docker-compose.yml up \ No newline at end of file +- docker-compose -f docker/build/docker-compose.yml run build script/test.sh \ No newline at end of file diff --git a/docker/build/Dockerfile b/docker/build/Dockerfile index 49409f39..a0052615 100644 --- a/docker/build/Dockerfile +++ b/docker/build/Dockerfile @@ -13,4 +13,4 @@ WORKDIR /myapp COPY Gemfile /myapp/Gemfile COPY Gemfile.lock /myapp/Gemfile.lock RUN bundle install -CMD rake db:create db:structure:load test:prepare && rake spec && npx jest && npm run build-all +CMD diff --git a/script/test.sh b/script/test.sh new file mode 100755 index 00000000..aad0ada2 --- /dev/null +++ b/script/test.sh @@ -0,0 +1,2 @@ +#!/bin/bash +rake db:create db:structure:load test:prepare && rake spec && npx jest && npm run build-all \ No newline at end of file From e25f1f1e48ee4b0c1114a326cc108a103f17f1a1 Mon Sep 17 00:00:00 2001 From: Eric Schultz Date: Fri, 7 Sep 2018 10:19:34 -0500 Subject: [PATCH 05/10] Test 2 --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2fafe21e..f5637993 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,5 @@ sudo: required -language: ruby - services: - docker From 26fb3b95c7a8d65d52740df26a6bb8885ecfb9af Mon Sep 17 00:00:00 2001 From: Eric Schultz Date: Fri, 7 Sep 2018 10:22:31 -0500 Subject: [PATCH 06/10] Test3 --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index f5637993..db4d8a48 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,7 @@ sudo: required +language: minimal + services: - docker From 0aeb4d2f0b20f23db1c9d3dda564dd5a3e1b5430 Mon Sep 17 00:00:00 2001 From: Eric Schultz Date: Fri, 7 Sep 2018 10:32:09 -0500 Subject: [PATCH 07/10] Include required environment variables in .travis.yml --- .travis.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index db4d8a48..f2430441 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,4 +9,13 @@ before_install: - docker-compose -f docker/build/docker-compose.yml build script: -- docker-compose -f docker/build/docker-compose.yml run build script/test.sh \ No newline at end of file +- docker-compose -f docker/build/docker-compose.yml run build script/test.sh + +env: + - DEVISE_SECRET_KEY='-- secret string --' + - SECRET_TOKEN='-- secret string --' + - STRIPE_API_KEY='REPLACE' + - STRIPE_API_PUBLIC='REPLACE' + - S3_BUCKET_NAME='REPLACE' + - AWS_ACCESS_KEY='REPLACE' + - AWS_SECRET_ACCESS_KEY='REPLACE' From b690adf0d693337f6f9098976ac6bd425d554477 Mon Sep 17 00:00:00 2001 From: Eric Schultz Date: Fri, 7 Sep 2018 10:35:28 -0500 Subject: [PATCH 08/10] *shrug* --- .travis.yml | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index f2430441..1bdadf5c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,15 +7,7 @@ services: before_install: - docker-compose -f docker/build/docker-compose.yml build +- cp .env.template .env script: -- docker-compose -f docker/build/docker-compose.yml run build script/test.sh - -env: - - DEVISE_SECRET_KEY='-- secret string --' - - SECRET_TOKEN='-- secret string --' - - STRIPE_API_KEY='REPLACE' - - STRIPE_API_PUBLIC='REPLACE' - - S3_BUCKET_NAME='REPLACE' - - AWS_ACCESS_KEY='REPLACE' - - AWS_SECRET_ACCESS_KEY='REPLACE' +- docker-compose -f docker/build/docker-compose.yml run build script/test.sh \ No newline at end of file From edb8920f278cb375c3ec30b1cbb1bc48835c1a1b Mon Sep 17 00:00:00 2001 From: Eric Schultz Date: Fri, 7 Sep 2018 13:09:20 -0500 Subject: [PATCH 09/10] Updatery --- .travis.yml | 2 +- config/database.yml | 10 ++++++++++ config/environments/ci.rb | 8 ++++++++ script/test.sh | 2 +- 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100755 config/environments/ci.rb diff --git a/.travis.yml b/.travis.yml index 1bdadf5c..ae04358c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,4 +10,4 @@ before_install: - cp .env.template .env script: -- docker-compose -f docker/build/docker-compose.yml run build script/test.sh \ No newline at end of file +- docker-compose -f docker/build/docker-compose.yml -e RACK_ENV=ci -e RAILS_ENV=ci run build script/test.sh \ No newline at end of file diff --git a/config/database.yml b/config/database.yml index 476a7a84..95030c22 100755 --- a/config/database.yml +++ b/config/database.yml @@ -30,6 +30,16 @@ test: username: admin password: password host: <%= ENV['DATABASE_HOST'] || 'localhost' %> +ci: + adapter: postgresql + encoding: unicode + database: commitchange_test + pool: 5 + username: admin + password: password + host: <%= ENV['DATABASE_HOST'] || 'localhost' %> + + # Connect on a TCP socket. Omitted by default since the client uses a # domain socket that doesn't need configuration. Windows does not have diff --git a/config/environments/ci.rb b/config/environments/ci.rb new file mode 100755 index 00000000..d306924c --- /dev/null +++ b/config/environments/ci.rb @@ -0,0 +1,8 @@ +# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later +require 'config/environments/test.rb' + +Commitchange::Application.configure do + + config.log_level = :info + +end diff --git a/script/test.sh b/script/test.sh index aad0ada2..3b28eb5e 100755 --- a/script/test.sh +++ b/script/test.sh @@ -1,2 +1,2 @@ #!/bin/bash -rake db:create db:structure:load test:prepare && rake spec && npx jest && npm run build-all \ No newline at end of file +npm install && rake db:create db:structure:load test:prepare && rake spec && npx jest && npm run build-all \ No newline at end of file From e2bf31e602517f234b5f299c46932ccb9e6b5208 Mon Sep 17 00:00:00 2001 From: Eric Schultz Date: Fri, 7 Sep 2018 13:18:55 -0500 Subject: [PATCH 10/10] Fix order on docker-compose run command --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ae04358c..d1b370da 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,4 +10,4 @@ before_install: - cp .env.template .env script: -- docker-compose -f docker/build/docker-compose.yml -e RACK_ENV=ci -e RAILS_ENV=ci run build script/test.sh \ No newline at end of file +- docker-compose -f docker/build/docker-compose.yml run -e RACK_ENV=ci -e RAILS_ENV=ci build script/test.sh