Skip to content

nmvuong92/railsblog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

85 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

railsblog

Development

Bare Metal

migration

rake db:migrate RAILS_ENV=development

build js/css/assets in development

./bin/webpack-dev-server

build js/css/assets in production

rake assets:precompile 

issues

Show me
  1. Your bundle only supports platforms
bundle lock --add-platform ruby
bundle lock --add-platform x86_64-linux
  1. An error occurred while installing pg (1.4.5) with aws linux 1
packages:
  yum:
    postgresql-devel: []

with aws linux 2

packages:
    yum:
        postgresql-devel: []
        amazon-linux-extras: []
        git: []
        patch: []
        gcc: []
        libxml2: []
        libxml2-devel: []
        libxslt: []
        libxslt-devel: []

commands:
    01_postgres_activate:
        command: sudo amazon-linux-extras enable postgresql14
    02_postgres_install:
        command: sudo yum install -y postgresql-devel

Testing

bundle exec rspec

Master key

master.key

.config/credentials.yml.enc

this file is encrypted, so that's why we can push

By default, the credentials file contains the application's secret_key_base. It can also be used to store other secrets such as access keys for external APIs. We can put our other secrets, such as the JWT secret key and API key in here.

regenerate

rails credentials:edit 
# or 
EDITOR=vim rails credentials:edit 
jwt:
   secret_key: hello

api: api-key

# Used as the base secret for all MessageVerifiers in Rails, including the one protecting cookies.
secret_key_base: ca8bae95decfb752601c30aff9bbe5e7f22587341f8b132765f2fb92ddab9d52d0ebf07b9ef840acce5aeeed9ed513c8329bb8cafdd1de06494a0d69c5466ee7

Don't forget to close the file and it will automatically save. The terminal will show this message.

File encrypted and saved

using

Rails.application.credentials.jwt[:secret_key] # hello
Rails.application.credentials.api # api-key

Linter (rubocop)

checking

rubocop

auto fixes

rubocop -A

Containerize (Docker)

up

docker-compose build
docker-compose up -d
# or
docker-compose up --build -d
# next
docker-compose exec app bundle exec rails db:setup db:migrate

down

docker-compose down

rebuild specific service name:

docker-compose up -d --no-deps --build  <service_name>

Deployment

aws Beantalk

to generate aws profile configuration

aws configure --profile eb_deploy

init with profile (no needed)

eb init --profile eb_deploy

deploy with profile

eb deploy --profile eb_deploy
cat ~/.aws/credentials
[eb_deploy]
aws_access_key_id = xxx
aws_secret_access_key = xxx

Debugging production

download logs file from EB -> .elasticbeanstalk/logs/xxx.zip

eb logs -z

Automate releases on github

ref: https://www.conventionalcommits.org/en/v1.0.0/

Commit convention

<type>[optional scope]: <description>

[optional body]

[optional footer(s)]

Example 1: Commit message with description and breaking change footer

feat: allow provided config object to extend other configs

BREAKING CHANGE: `extends` key in config file is now used for extending other config files

Example 2: Commit message with scope

feat(lang): add Polish language

Ref: