Make usage of Docker for development easier by avoiding COPY operations
This commit is contained in:
parent
38193e43a9
commit
38d49dedb8
5 changed files with 63 additions and 47 deletions
|
@ -14,25 +14,12 @@ ENV PORT=3000 \
|
||||||
\
|
\
|
||||||
CHROMIUM_FLAGS=--no-sandbox \
|
CHROMIUM_FLAGS=--no-sandbox \
|
||||||
\
|
\
|
||||||
BUNDLE_PATH=/home/app/bundle \
|
BUNDLE_PATH=/usr/local/bundle \
|
||||||
BUNDLE_APP_CONFIG=/home/app/bundle/config
|
BUNDLE_APP_CONFIG=/usr/local/bundle/config
|
||||||
|
|
||||||
# Run app and all commands as user 'app'. This avoids changing permissions
|
WORKDIR /app
|
||||||
# for files in mounted volume. Symlink for similarity with production image.
|
|
||||||
RUN adduser --gecos GECOS --disabled-password --shell /bin/bash app && \
|
|
||||||
ln -s /home/app/src /usr/src/app
|
|
||||||
USER app
|
|
||||||
|
|
||||||
WORKDIR /home/app/src
|
RUN bundle config build.nokogiri "--use-system-libraries"
|
||||||
|
|
||||||
# Copy files needed for installing gem dependencies, and install them.
|
|
||||||
COPY Gemfile Gemfile.lock ./
|
|
||||||
COPY plugins ./plugins
|
|
||||||
RUN bundle config build.nokogiri "--use-system-libraries" && \
|
|
||||||
bundle install --frozen -j 4
|
|
||||||
|
|
||||||
# Copy the application code
|
|
||||||
COPY . ./
|
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ Rails.application.configure do
|
||||||
# Mailcatcher config, start mailcatcher from console with 'mailcatcher'
|
# Mailcatcher config, start mailcatcher from console with 'mailcatcher'
|
||||||
# Mailcatcher can be installed by gem install mailcatcher
|
# Mailcatcher can be installed by gem install mailcatcher
|
||||||
config.action_mailer.delivery_method = :smtp
|
config.action_mailer.delivery_method = :smtp
|
||||||
config.action_mailer.smtp_settings = { address: ENV.fetch("MAILCATCHER_PORT_25_TCP_ADDR", "localhost"), port: ENV.fetch("MAILCATCHER_PORT_25_TCP_PORT", 1025) }
|
config.action_mailer.smtp_settings = { address: ENV.fetch("MAILCATCHER_ADDRESS", "localhost"), port: ENV.fetch("MAILCATCHER_PORT", 1025) }
|
||||||
|
|
||||||
# Raises error for missing translations
|
# Raises error for missing translations
|
||||||
# config.action_view.raise_on_missing_translations = true
|
# config.action_view.raise_on_missing_translations = true
|
||||||
|
|
|
@ -28,19 +28,20 @@ afterwards.
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
Then setup foodsoft development (this will take some time, containers needs
|
Then start the database server and setup foodsoft development (this will take
|
||||||
to be pulled from docker registry and a lot dependencies needs to be installed)
|
some time, containers needs to be pulled from docker registry and a lot
|
||||||
|
dependencies needs to be installed)
|
||||||
|
|
||||||
|
docker-compose -f docker-compose-dev.yml up -d mariadb
|
||||||
|
docker-compose -f docker-compose-dev.yml run --rm foodsoft \
|
||||||
|
bundle install
|
||||||
|
docker-compose -f docker-compose-dev.yml run --rm foodsoft \
|
||||||
|
bundle exec rake foodsoft:setup_development_docker
|
||||||
|
|
||||||
|
Optionally an initial database (here seeded with `small.en`) can be loaded by running
|
||||||
|
|
||||||
docker-compose -f docker-compose-dev.yml run --rm foodsoft \
|
docker-compose -f docker-compose-dev.yml run --rm foodsoft \
|
||||||
bundle exec rake foodsoft:setup_development
|
bundle exec rake db:schema:load db:seed:small.en
|
||||||
|
|
||||||
Do not enable mailcatcher, because this is already included as a docker image.
|
|
||||||
|
|
||||||
Then create an initial database (here seeded with `small.en`) by running
|
|
||||||
|
|
||||||
docker-compose -f docker-compose-dev.yml up -d mariadb && sleep 15
|
|
||||||
docker-compose -f docker-compose-dev.yml run --rm foodsoft \
|
|
||||||
bundle exec rake db:create db:schema:load db:seed:small.en
|
|
||||||
|
|
||||||
To avoid having to pass the `-f` argument all the time, it is recommended to setup
|
To avoid having to pass the `-f` argument all the time, it is recommended to setup
|
||||||
an alias, e.g. by adding the following line to your ~/.bashrc
|
an alias, e.g. by adding the following line to your ~/.bashrc
|
||||||
|
@ -66,7 +67,8 @@ Open a rails console
|
||||||
|
|
||||||
Setup the test database
|
Setup the test database
|
||||||
|
|
||||||
docker-compose-dev run --rm foodsoft bundle exec rake db:create db:schema:load RAILS_ENV=test DATABASE_URL=mysql2://root:secret@mariadb/test?encoding=utf8
|
docker-compose-dev run --rm mariadb mariadb --host=mariadb --password=secret --execute="CREATE DATABASE test"
|
||||||
|
docker-compose-dev run --rm foodsoft bundle exec rake db:schema:load RAILS_ENV=test DATABASE_URL=mysql2://root:secret@mariadb/test?encoding=utf8mb4
|
||||||
|
|
||||||
Run the tests
|
Run the tests
|
||||||
|
|
||||||
|
@ -83,6 +85,10 @@ Jump in a running container for debugging.
|
||||||
|
|
||||||
Go to [http://localhost:1080](http://localhost:1080)
|
Go to [http://localhost:1080](http://localhost:1080)
|
||||||
|
|
||||||
|
### Manage database
|
||||||
|
|
||||||
|
Go to [http://localhost:2080](http://localhost:2080)
|
||||||
|
|
||||||
### Gemfile updates
|
### Gemfile updates
|
||||||
|
|
||||||
As the gem bundle is stored in a volume, you can run
|
As the gem bundle is stored in a volume, you can run
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
version: '2'
|
version: '3'
|
||||||
services:
|
services:
|
||||||
|
|
||||||
foodsoft:
|
foodsoft:
|
||||||
|
@ -13,14 +13,16 @@ services:
|
||||||
dockerfile: Dockerfile-dev
|
dockerfile: Dockerfile-dev
|
||||||
command: ./proc-start worker
|
command: ./proc-start worker
|
||||||
volumes:
|
volumes:
|
||||||
- bundle:/home/app/bundle
|
- bundle:/usr/local/bundle
|
||||||
- .:/home/app/src
|
- .:/app
|
||||||
environment:
|
environment:
|
||||||
- DATABASE_URL=mysql2://root:secret@mariadb/development?encoding=utf8
|
- DATABASE_URL=mysql2://root:secret@mariadb/development?encoding=utf8mb4
|
||||||
- REDIS_URL=redis://redis:6379
|
- REDIS_URL=redis://redis:6379
|
||||||
- QUEUE=foodsoft_notifier
|
- QUEUE=foodsoft_notifier
|
||||||
- TEST_DATABASE_URL=mysql2://root:secret@mariadb/test?encoding=utf8
|
- TEST_DATABASE_URL=mysql2://root:secret@mariadb/test?encoding=utf8mb4
|
||||||
- DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL=true
|
- DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL=true
|
||||||
|
- MAILCATCHER_ADDRESS=mailcatcher
|
||||||
|
- MAILCATCHER_PORT=25
|
||||||
|
|
||||||
mailcatcher:
|
mailcatcher:
|
||||||
image: tophfr/mailcatcher
|
image: tophfr/mailcatcher
|
||||||
|
@ -28,14 +30,24 @@ services:
|
||||||
- "1080:80"
|
- "1080:80"
|
||||||
|
|
||||||
mariadb:
|
mariadb:
|
||||||
image: mariadb:10.1
|
image: mariadb:10.5
|
||||||
environment:
|
environment:
|
||||||
- MYSQL_ROOT_PASSWORD=secret
|
- MYSQL_ROOT_PASSWORD=secret
|
||||||
|
- MYSQL_DATABASE=development
|
||||||
volumes:
|
volumes:
|
||||||
- mariadb:/var/lib/mysql
|
- mariadb:/var/lib/mysql
|
||||||
|
|
||||||
|
phpmyadmin:
|
||||||
|
image: phpmyadmin/phpmyadmin
|
||||||
|
environment:
|
||||||
|
- PMA_HOST=mariadb
|
||||||
|
- PMA_USER=root
|
||||||
|
- PMA_PASSWORD=secret
|
||||||
|
ports:
|
||||||
|
- "2080:80"
|
||||||
|
|
||||||
redis:
|
redis:
|
||||||
image: redis:3.2-alpine
|
image: redis:6.2-alpine
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
bundle:
|
bundle:
|
||||||
|
|
|
@ -34,10 +34,19 @@ namespace :foodsoft do
|
||||||
setup_development
|
setup_development
|
||||||
setup_database
|
setup_database
|
||||||
start_mailcatcher
|
start_mailcatcher
|
||||||
puts yellow "All done! Your foodcoft should be running smoothly."
|
puts yellow "All done! Your foodsoft setup should be running smoothly."
|
||||||
start_server
|
start_server
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc "Setup foodsoft"
|
||||||
|
task :setup_development_docker do
|
||||||
|
puts yellow "This task will help you get your foodcoop running in development via docker."
|
||||||
|
setup_app_config
|
||||||
|
setup_development
|
||||||
|
setup_run_rake_db_setup
|
||||||
|
puts yellow "All done! Your foodsoft setup should be running smoothly via docker."
|
||||||
|
end
|
||||||
|
|
||||||
namespace :setup do
|
namespace :setup do
|
||||||
desc "Initialize stock configuration"
|
desc "Initialize stock configuration"
|
||||||
task :stock_config do
|
task :stock_config do
|
||||||
|
@ -65,21 +74,23 @@ def setup_database
|
||||||
database = ask("What kind of database do you use?\nOptions:\n(1) MySQL\n(2) SQLite", ["1", "2"])
|
database = ask("What kind of database do you use?\nOptions:\n(1) MySQL\n(2) SQLite", ["1", "2"])
|
||||||
if database == "1"
|
if database == "1"
|
||||||
puts yellow "Using MySQL..."
|
puts yellow "Using MySQL..."
|
||||||
%x(cp #{Rails.root.join("#{file}.MySQL_SAMPLE")} #{Rails.root.join(file)})
|
%x(cp -p #{Rails.root.join("#{file}.MySQL_SAMPLE")} #{Rails.root.join(file)})
|
||||||
elsif database == "2"
|
elsif database == "2"
|
||||||
puts yellow "Using SQLite..."
|
puts yellow "Using SQLite..."
|
||||||
%x(cp #{Rails.root.join("#{file}.SQLite_SAMPLE")} #{Rails.root.join(file)})
|
%x(cp -p #{Rails.root.join("#{file}.SQLite_SAMPLE")} #{Rails.root.join(file)})
|
||||||
end
|
end
|
||||||
|
|
||||||
reminder(file)
|
reminder(file)
|
||||||
|
|
||||||
puts blue "IMPORTANT: Edit (rake-generated) config/database.yml with valid username and password for EACH env before continuing!"
|
puts blue "IMPORTANT: Edit (rake-generated) config/database.yml with valid username and password for EACH env before continuing!"
|
||||||
finished = ask("Finished?\nOptions:\n(y) Yes", ["y"])
|
finished = ask("Finished?\nOptions:\n(y) Yes", ["y"])
|
||||||
if finished
|
setup_run_rake_db_setup if finished
|
||||||
|
end
|
||||||
|
|
||||||
|
def setup_run_rake_db_setup
|
||||||
Rake::Task["db:setup"].reenable
|
Rake::Task["db:setup"].reenable
|
||||||
db_setup = capture_stdout { Rake::Task["db:setup"].invoke }
|
db_setup = capture_stdout { Rake::Task["db:setup"].invoke }
|
||||||
puts db_setup
|
puts db_setup
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup_app_config
|
def setup_app_config
|
||||||
|
@ -88,7 +99,7 @@ def setup_app_config
|
||||||
return nil if skip?(file)
|
return nil if skip?(file)
|
||||||
|
|
||||||
puts yellow "Copying #{file}..."
|
puts yellow "Copying #{file}..."
|
||||||
%x(cp #{sample} #{Rails.root.join(file)})
|
%x(cp -p #{sample} #{Rails.root.join(file)})
|
||||||
reminder(file)
|
reminder(file)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -97,7 +108,7 @@ def setup_development
|
||||||
return nil if skip?(file)
|
return nil if skip?(file)
|
||||||
|
|
||||||
puts yellow "Copying #{file}..."
|
puts yellow "Copying #{file}..."
|
||||||
%x(cp #{Rails.root.join("#{file}.SAMPLE")} #{Rails.root.join(file)})
|
%x(cp -p #{Rails.root.join("#{file}.SAMPLE")} #{Rails.root.join(file)})
|
||||||
reminder(file)
|
reminder(file)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue