Sunday, July 28, 2019

Getting started with Ruby (on Rails)

Ruby language basics

  • Ruby in 20 minutes
    •  the Ruby REPL is irb
    • expressions in a string are escaped with "#{expression}"
    • print function is puts
    • functions are defined like:
      def myfun(somearg = "default")
        # do something with somearg
      end
      • arguments can have default value
      • functions can be called like:
        myfun
        myfun()
        myfun "some other arg"
        myfun("some other arg")
    • classes are defined like:
      class MyClass
        attr_accessor :somearg
        def initialize(somearg = "default")
          @somearg = somearg
        end
        # do something with @somearg anywhere in the class
      end
      • class instantiation is done with the "new" keyword:
        myclass = MyClass.new("some other arg")
      • the instance variable @somearg is private
      • the methods defined in the class are public by default
      • the attribute accessor :somearg allows to get and set the instance variable (public). Usage: myclass.somearg and myclass.somearg= "something new"
    • information about a class can be retrieved with MyClass.instance_methods(show_inherited = true)
    • iterations
      • for each loop
        @names.each do |name|
          puts "Hello #{name}!"
        end
    • conditionals
      • if-else block
        def say_bye
          if @names.nil?
            puts "..."
          elsif @names.respond_to?("join")
            # Join the list elements with commas
            puts "Goodbye #{@names.join(", ")}.  Come back soon!"
          else
            puts "Goodbye #{@names}.  Come back soon!"
          end
        end
Some additional info:

Ruby on Rails basics

rspec testing framework basics

...coming up...
in the meantime here are some resources:


My IDE choice

Monday, July 1, 2019

Developing Gitlab: Setting up a development environment with Vagrant

FYI, I abandoned the Vagrant approach in favor of a VirtualBox machine with Ubuntu.

---
Versions in use:
  • Vagrant 2.2.4
  • VirtualBox 6.0.8-130520
  • gitlab-development-kit revision e519656ac3101770622d9451f500a6c2a08c5250

Set up GDK for the first time

  1. open a CMD with "Run as Administrator" (aka. "elevated") in the gitlab-development-kit directory
  2. follow instructions for Vagrant installation:
    vagrant up --provider=virtualbox --provision

    Troubleshooting
  3. when ready:
    vagrant ssh
  4. cd gitlab-development-kit
  5. follow instructions from gdk install: Option 1 develop in fork
    gdk install gitlab_repo=https://gitlab.com/MY-FORK/gitlab-ce.git

    Troubleshooting
    • fix line endings (because the repo was cloned on a Windows host with windows line endings, but is used on linux)
      1. set the git line endings to retrieve any updates unix style for the gdk repo
        git config core.autocrlf input
      2. install dos2unix on the virtual machine
        sudo apt-get install dos2unix
      3. change the line endings in the support and bin directories
        cd support
        find ./ -type f -exec dos2unix {} \;
        cd ..
        cd bin
        find ./ -type f -exec dos2unix {} \;
        cd ..
  6. Set up tracking of original upstream repo
    support/set-gitlab-upstream
  7. run the server
    gdk run

    Troubleshooting
    • if the run command fails, stop node manually before trying again
      pkill -f node
      gdk run
      
  8. reach it from the Host on localhost:3000 and use the given credentials

Everyday commands

  • vagrant up: starts the virtual machine
  • vagrant ssh: connects the virtual machine
  • cd gitlab-development-kit
  • gdk run: starts the server
  • Ctrl+C: exits the server
  • Ctrl+D: exits the virtual machine
  • vagrant halt: stops the virtual machine
  • How to put a process into background

Restart the whole thing because something went amiss

  • clean your git repos from untracked and ignored files and directories
    • use git clean -ndx to see what would be deleted
    • use git clean -fdx to actually do the deletion
    • don't worry, repositories within a repository are not cleaned by git clean.
      there are 3 repositories in gitlab-development-kit:
      • gitlab-development-kit/gitlab
      • gitlab-development-kit/gitlab-workhorse/src/gitlab.com/gitlab-org/gitlab-workhorse
      • gitlab-development-kit/go-gitlab-shell/src/gitlab.com/gitlab-org/gitlab-shell
    • delete these directories too:
      • gitlab-development-kit/gitlab-workhorse/src
      • gitlab-development-kit/go-gitlab-shell
  • do the "Set up GDK for the first time" part again