Skip to content

Commit

Permalink
Add docker-compose based development environment
Browse files Browse the repository at this point in the history
  • Loading branch information
hennevogel committed Mar 24, 2022
1 parent f6d4a54 commit e894897
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ locale/*/software.po.time_stamp
vendor/

.byebug_history
docker-compose.override.yml
62 changes: 39 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,46 @@
FROM opensuse/leap:15.2
ARG IMAGE_USERID

# Update distro
RUN zypper -q --non-interactive update

# Install some system requirements
RUN zypper -q --non-interactive install timezone vim aaa_base glibc-locale sudo nodejs

# Install ruby
RUN zypper -q --non-interactive install ruby2.5 ruby2.5-devel

# Setup gem & sudo
FROM registry.opensuse.org/opensuse/leap:15.3
ARG CONTAINER_USERID

# Install our requirements
RUN zypper -n ar -f \
https://download.opensuse.org/repositories/devel:/languages:/ruby/openSUSE_Leap_15.3/devel:languages:ruby.repo; \
zypper -n --gpg-auto-import-keys refresh; \
zypper -n install --no-recommends timezone glibc-locale sudo \
vim git-core \
gcc gcc-c++ make \
nodejs16 ruby3.1-devel \
libxml2-devel libxslt-devel

# Setup ruby in PATH & sudo
RUN echo 'install: --no-format-executable' >> /etc/gemrc; \
echo 'vagrant ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers

# Install bundler
RUN gem install bundler

# Install requirements for our rubygems
RUN zypper -q --non-interactive install --no-recommends sqlite3-devel gcc gcc-c++ make libxml2-devel libxslt-devel git-core
echo 'software ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers; \
ln -s /usr/bin/gem.ruby3.1 /usr/local/bin/gem; \
ln -s /usr/bin/ruby.ruby3.1 /usr/local/bin/ruby; \
ln -s /usr/bin/bundle.ruby3.1 /usr/local/bin/bundle; \
ln -s /usr/bin/bundler.ruby3.1 /usr/local/bin/bundler; \
ln -s /usr/bin/irb.ruby3.1 /usr/local/bin/irb; \
ln -s /usr/bin/rake.ruby3.1 /usr/local/bin/rake

# Add our user
RUN useradd -m vagrant -u $IMAGE_USERID -p vagrant
RUN useradd -m software -u $CONTAINER_USERID -p software

# We copy the Gemfiles into this intermediate build stage so it's checksum
# changes and all the subsequent stages (a.k.a. the bundle install call below)
# have to be rebuild. Otherwise, after the first build of this image,
# docker would use it's cache for this and the following stages.
ADD Gemfile /software/Gemfile
ADD Gemfile.lock /software/Gemfile.lock
RUN chown -R software /software

USER vagrant
WORKDIR /vagrant
USER software
WORKDIR /software

# Setup bundler
RUN bundle config build.nokogiri --use-system-libraries

# Refresh our bundle
RUN bundle install --jobs=3 --retry=3

# Run our command
CMD ["rails", "server", "-b", "0.0.0.0"]

4 changes: 3 additions & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
# Enable server timing
config.server_timing = true

config.cache_store = :memory_store
memcached_host = ENV['MEMCACHED_HOST'] || 'localhost:11211'
config.cache_store = :mem_cache_store, memcached_host, {namespace: 'software-dev', compress: true}

# Enable/disable caching. By default caching is disabled.
# Run rails dev:cache to toggle caching.
if Rails.root.join("tmp/caching-dev.txt").exist?
Expand Down
3 changes: 2 additions & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
config.log_tags = [ :request_id ]

# Use a different cache store in production.
config.cache_store = :mem_cache_store, 'localhost:11211', {namespace: 'software', compress: true}
memcached_host = ENV["MEMCACHE_SERVERS"] || "localhost:11211"
config.cache_store = :mem_cache_store, memcached_host, {namespace: 'software', compress: true}

# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
Expand Down
9 changes: 9 additions & 0 deletions docker-compose.override.yml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: '2.1'
services:
software:
build:
args:
CONTAINER_USERID: 1000
environment:
- API_USERNAME=yourusername
- API_PASSWORD=password123
19 changes: 19 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: "2.1"
services:
memcached:
image: registry.opensuse.org/opensuse/memcached:latest
software:
build:
dockerfile: Dockerfile
context: .
args:
CONTAINER_USERID: 1000
command: bundle exec rails s -b 0.0.0.0
volumes:
- .:/software
ports:
- "3000:3000"
depends_on:
- memcached
environment:
- MEMCACHED_HOST="memcached:11211"

0 comments on commit e894897

Please sign in to comment.