Import mysql db from docker container.
To use this tool you need a docker container on the server with your db.
For visualize progress on the cli you need to install pv: https://man7.org/linux/man-pages/man1/pv.1.html.
# Install PV in your Dockerfile
RUN apt-get update && apt-get install -y pv
RUN apt-get update && apt-get install -y mariadb-client
Add this line to your application's Gemfile:
gem 'amico-db', git: 'https://github.com/rubynetti/amico-db.git'
For example inside a rails initializer (config/initializers/amico-db.rb).
dev = Rails.configuration.database_configuration["production"]
production = Rails.configuration.database_configuration["production"]
AmicoDb.configure do |config|
config.ssh_user = 'root'
config.host = 'your_host'
config.remote_app_path = '/var/www/yourproject'
config.folder_dump = '/dumps/db.sql'
config.local_path = './dumps/db.sql'
config.db_name = production['database']
config.db_user = production['username']
config.db_dev_dbname = dev['database']
config.db_dev_username = dev['username']
end
Your dev configuration need to copy ssh folder inside. Example:
services:
web:
build: .
command: ['rails', 'server', '-b', '0']
volumes:
- .:/app
- ~/.ssh:/home/rails/.ssh
Database service need MYSQL_ROOT_PASSWORD and share dumps folder.
services:
db:
environment:
- MYSQL_ROOT_PASSWORD=$DB_PASSWORD
volumes:
- ./dumps:/dumps
rake db:dump_and_download
rake db:import_from_sql
docker-compose up
runrake test
command