TLDR: Only 15 steps, your all envorionment about Rails(local develoment and remote server production) is all setup and ready to go.
Server side
Clone https://github.com/sherllochen/dockers.git. All related files is in rails directory.
Port 22 and 80 port must be open in server.
Install Docker and Docker compose. Docke offical install docs
Change username and password of OS for deploy.
1
2
3# nginx/Dockerfile
# System deploy username and password is set here. Don't forget to also change in your deploy.rb file.
RUN useradd -rm -d /home/deploy -s /bin/bash -g root -G sudo -u 1000 your-deploy-username -p "$(openssl passwd -1your-password)"Change database name, username and password(set in docker-compose.yml). For postgres, related setting is in ‘environment’ section of backend service. For mysql, related setting is in mysql service.
Edit nginx site config.
1
2# nginx/app_config
root /your-app-deploy-path/current/public;Run docker compose and all things done.
1
sudo docker-compose run --service-ports production
Local development side
Step 1,2,3 is the same with server side.
- Run docker compose to start development environment.
1
sudo docker-compose run --service-ports dev
- Copy gits below to lib/capistrano/tasks/tasks.rb. These are customize tasks for capistrano, your more tasks can be defined here and call in deploy.rb
- Edit server address and username. The username must be the same as setting in server’s nginx/Dockerfile.
1
2# config/deploy/production.rb
server "your.server.domain", user: "your-deploy-username", roles: %w{app db web} - Edit deploy setting.
1
2
3
4
5
6# config/deploy.rb
set :application, "your-app-name"
set :repo_url, "git@github.com:your-app-repo.git"
# Every file about config info must be set here, and copy to deply_path/shared/config manully.
# All variable write in these files directly.
append :linked_files, "config/database.yml", "config/master.key", "config/wechat.yml" - Execute deploy command.
1
2
3cap production deploy
# run seed_fu task if you need.(I use SeedFu for data seed).
cap production rails:seed_fuTIPS
- All environment version change be changed in docker-compose.yml.