From 2780abd9449b6988853cf88b58345f353d9c5574 Mon Sep 17 00:00:00 2001 From: Eric Schultz Date: Thu, 6 Sep 2018 16:29:07 -0500 Subject: [PATCH] Update to a more usable Docker format --- .dockerignore | 5 +- Dockerfile | 22 --------- README.md | 1 + config/application.rb | 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 +- 14 files changed, 120 insertions(+), 45 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/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