cp config/database.yml.example config/database.ymlcp config/database.yml.example config/database.yml.dockercp config/redis.conf.example config/redis.confcp .env.example .env.dockerThe default environment file is in .env.example. Rename it to .env to apply
default environment variables.
With development environment, set LABHOK_CORS_ALLOW_HOST="localhost:4200"
Run EDITOR=cat rails credentials:edit. It will create master.key and
credentinals.yml.ync.
credential.yml.example is the example file for credentials.yml.enc when
decrypted. It contains variables required for rails to work properly
Optionally, do cp .firebaserc.example .firebaserc, and set the appropriate
default project name in .firebaserc. By setting the default project,
firebase CLI commands can now be issued without using the --project flag.
firebase.<RAILS_ENV>.json and drop in the
config directory.env) as a
value for the FIREBASE_WEB_API_KEY variableimagemagick on your machine to work with uploading
attachment on Communication sectionPlease make sure mailcatcher is running SMTP on port 1025 before starting
the application.
To install mailcatcher: gem install mailcatcher
To run mailcatcher: mailcatcher
Install Graphviz to support the ERD generator.
firebase-tools using any of the following methods.
$ npm install -g firebase-tools
$ yarn global add firebase-tools
firebase loginfirebase login:ciFrom Firebase console > Project settings > Cloud messaging > Project credentials, collect Server key and Sender ID.
Now, deploy the fetched credentials.
$ cd firebase
$ firebase functions:config:set messaging.sender=<SENDER_ID> messaging.key=<SERVER_KEY> # Development
$ firebase functions:config:set messaging.sender=<SENDER_ID> messaging.key=<SERVER_KEY> --project=<PROJECT_ID> --token=<CLI_KEY> # Staging and Production
And, finally, deploy the cloud functions.
$ firebase deploy --only functions # Development
$ firebase deploy --only functions --force --project=<PROJECT_ID> --token=<CLI_KEY> # Staging and Production
To run application on Docker, run the following commands:
NOTE: Before building the image, please make sure config/master.key and
config/credentials.yml.enc is properly configured for the application
To build necessary image for the project, run make build-all. This command
will build image for the application and haproxy for load-balancing
To start the application for the first time, run make up. This command will
build images, create and migrate database and then startup the application
To run test, run make test. This command will run rubocop and rspec on this
project
Server logs are stored in /data/labhok/log
docker-compose run --rm server-1 bundle exec rake db:create
docker-compose run --rm server-1 bundle exec rake db:migrate
docker-compose run --rm server-1 bundle exec rails console
We can upgrade the application by running deploy.sh script. In this script, we
can deploy by tag or by branch name. The syntax for deploy.sh script is
./deploy.sh [tag|branch] [tag_name|branch_name]
For example: To deploy develop branch, run ./deploy.sh branch develop
NOTE: This script also tag the docker image of the current deploy by git tag
or git branch. For example: labhok-backend:branch-[branch_name]-20180101000000
or labhok-backend:tag-[tag_name]
Using gem switch_point: https://github.com/eagletmt/switch_point
How to test gem switch_point with docker ?
Step 1: create docker with 2 mysql in docker-compose.yml
mysql:
image: mysql:5.7
restart: always
volumes:
- "/data/labhok/mysql:/var/lib/mysql"
ports:
- 3307:3306
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 1
mysql2:
image: mysql:5.7
restart: always
ports:
- 3308:3306
volumes:
- "/data/labhok/mysql2:/var/lib/mysql"
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 1
Step 2: Install gem switch_point with doc: https://github.com/eagletmt/switch_point
Step 3: Config database.yml.docker, example:
development: &common
<<: *default
database: development_write
development_reader:
<<: *common
database: labhok_backend_api_development
host: <%= ENV["DEVELOPMENT_READER_LABHOK_DATABASE_HOST"] %>
Step 4: change host reader ENV["DEVELOPMENT_READER_LABHOK_DATABASE_HOST"], <%= ENV["LABHOK_DATABASE_HOST"] %> in file .env.docker
Example:
DEVELOPMENT_READER_LABHOK_DATABASE_HOST = "development_reader_host"
LABHOK_DATABASE_HOST = "development_host"
NOTE: create new database test ("development_write") with host LABHOK_DATABASE_HOST
Step 5: Test switch_point in 2 databases development_write and labhok_backend_api_development
irb(main):020:0> u = User.first
D, [2018-11-30T08:26:40.330831 #1] DEBUG -- : User Load (0.6ms) SELECT `users`.* FROM `users` ORDER BY `users`.`id` ASC LIMIT 1
=> #<Teacher id: 1, first_name: "xxxxxx", last_name: "Phạm Nhật", avatar: "https://static.giantbomb.com/uploads/scale_medium/...", password_digest: "$2a$10$rk9rOxLxZ9NUsHxS2QEPrupki9J.8Kz1ts1q31PGjyg...", date_of_birth: "1986-01-01", identity: "12345670", phone: "12345678", type: "Teacher", username: "teacher1", gender: "male", created_at: "2018-11-28 09:09:40", updated_at: "2018-11-30 03:51:33", study_class_id: nil, national: "Kinh", job: nil, email: nil, student_id: nil, nationality: nil, place_of_identity: nil, date_of_identity: nil, blood_group: nil, place_of_birth: nil>
irb(main):023:0> u.update first_name: "xxx"
D, [2018-11-30T08:38:18.363681 #1] DEBUG -- : (0.4ms) BEGIN
D, [2018-11-30T08:38:18.365004 #1] DEBUG -- : User Exists (0.4ms) SELECT 1 AS one FROM `users` WHERE `users`.`username` = BINARY 'teacher1' AND `users`.`id` != 1 LIMIT 1
D, [2018-11-30T08:38:18.365868 #1] DEBUG -- : User Exists (0.3ms) SELECT 1 AS one FROM `users` WHERE `users`.`identity` = BINARY '12345670' AND `users`.`id` != 1 LIMIT 1
D, [2018-11-30T08:38:18.367189 #1] DEBUG -- : (0.3ms) ROLLBACK
Traceback (most recent call last):
1: from (irb):23
Mysql2::Error (MySQL client is not connected)
NOTE: Mysql2::Error because development_write hasn't tables
Content type
Image
Digest
Size
498.4 MB
Last updated
over 7 years ago
docker pull quyetlq/labhok_backend_api