Wednesday, December 01, 2021

Rails 7 Sample Project

1. gem install rails -v v7.0.0.alpha2

2. rails new blog --css tailwind

3. rails g scaffold post title

4. rails action_text:install
5. rails db:create db:migrate

        Monday, November 29, 2021

        Share Folder in Mac with Multipass Ubuntu Instance

         Share Folder


        multipass mount local/folder/path multipass-instance-name

        multipass mount /Users/bparanj/cloud gold


        multipass info gold

        Name:           gold

        State:          Running

        IPv4:           192.168.64.2

        Release:        Ubuntu 20.04.3 LTS

        Image hash:     91740d72ffff (Ubuntu 20.04 LTS)

        Load:           0.71 0.53 0.32

        Disk usage:     2.6G out of 4.7G

        Memory usage:   241.0M out of 981.3M

        Mounts:         /Users/bparanj/cloud => /Users/bparanj/cloud

                            UID map: 501:default

                            GID map: 20:default

        Saturday, November 27, 2021

        ssh into multipass instance

         Launch Ubuntu instance:

        multipass launch --name gold   

        Copy the IP address from:

        multipass list 

        Log in to multipass instance:

        sudo ssh -i /var/root/Library/Application\ Support/multipassd/ssh-keys/id_rsa ubuntu@192.168.64.2



        Friday, November 19, 2021

        Tuesday, November 09, 2021

        Postgresql Post Install Message

         To migrate existing data from a previous major version of PostgreSQL run:

          brew postgresql-upgrade-database


        This formula has created a default database cluster with:

          initdb --locale=C -E UTF-8 /opt/homebrew/var/postgres

        For more details, read:

          https://www.postgresql.org/docs/14/app-initdb.html


        To restart postgresql after an upgrade:

          brew services restart postgresql

        Or, if you don't want/need a background service you can just run:

          /opt/homebrew/opt/postgresql/bin/postgres -D /opt/homebrew/var/postgres


        Zoom Link:

        sqlite3 install

        After brew install, the output: 

        If you need to have sqlite first in your PATH, run:

          echo 'export PATH="/opt/homebrew/opt/sqlite/bin:$PATH"' >> ~/.zshrc


        For compilers to find sqlite you may need to set:

          export LDFLAGS="-L/opt/homebrew/opt/sqlite/lib"

          export CPPFLAGS="-I/opt/homebrew/opt/sqlite/include"


        For pkg-config to find sqlite you may need to set:

          export PKG_CONFIG_PATH="/opt/homebrew/opt/sqlite/lib/pkgconfig"

        Monday, November 08, 2021

        Warning! PATH is not properly set up

        Warning! PATH is not properly set up, /Users/n1576925/.rvm/gems/ruby-3.0.2/bin is not at first place.

                 Usually this is caused by shell initialization files. Search for PATH=... entries.

                 You can also re-add RVM to your profile by running: rvm get stable --auto-dotfiles

                 To fix it temporarily in this shell session run: rvm use ruby-3.0.2

                 To ignore this error add rvm_silence_path_mismatch_check_flag=1 to your ~/.rvmrc file.


        In MacOS Monterey, add the following to .bash_profile:


        # RVM can encounter errors if it's not the last thing in .bash_profile

        export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to path for scripting (to manage Ruby versions)

        export PATH="$GEM_HOME/bin:$PATH"


        [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*


        The .zshrc has only one line:

        source ~/.bash_profile


        Tuesday, September 07, 2021

        Rails on Docker Tips

        1. Reduce size of the image

        RUN apt-get clean && rm -f /var/lib/apt/lists/*_*

        2. Combine update, install and clean:

        RUN apt-get update -y \

        && apt-get install -y -q package-name \

        && apt-get clean \

        && rm -f /var/lib/apt/lists/*_*

        3. Use a separate build stage

        FROM base-image AS builder

        COPY . /app

        RUN apt-get install build-essential \

        && bundle install --deployment


        FROM base-image

        COPY --from=builder /app /app

        4. Set the system locale

        RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \

        && locale-gen en_US.UTF-8

        ENV LANG en_US.UTF-8

        ENV LANGUAGE en_US:en

        5. Create an unprivileged user

        # After build

        RUN adduser -s /bin/sh -u 1001 -G root \

        -h /app -S -D rails \

        && chown -R rails /app

        USER rails

        6. Prefer exec form for CMD

        CMD ["bundle", "exec", "rails", "s"]

        7. Specify resource constraints in production

        requests:

          memory: "100Mi"

          cpu: 0.5

         limits:

          memory: "200Mi"

          cpu: 1.0

        8. Log to STDOUT or an external agent

        ENV RAILS_LOG_STDOUT=true