This repository contains my contribution to EE5 as part of my bachelor's degree. The Git history has been purged for privacy reasons.
https://www.ruby-lang.org/en/documentation/quickstart/ https://guides.rubyonrails.org/getting_started.html
make build: build the server and dbmake up: run server and db in backgroundmake down: stop server and dbmake up?: check if server and/or db are runningmake server: enter inside the server container- Note: Docker containers are stateless, so any changes made inside
the container will be lost when the container stops. Only changes written
to a volume (
/serverinsideserver,//var/lib/postgresql/datainsidedb) will persist.
- Note: Docker containers are stateless, so any changes made inside
the container will be lost when the container stops. Only changes written
to a volume (
make db: enter inside the server containermake .env: generate the.envfile
(Should be installed by default on Ubuntu)
(adapted from: https://docs.docker.com/install/linux/docker-ce/ubuntu/)
NOTE: Make sure to uninstall older versions of Docker (see link)!
- install prerequisites:
sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common - add Docker GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - - make sure GPG key is installed correctly:
apt-key fingerprint 0EBFCD88 - add Docker's repository:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" sudo apt updatesudo apt install docker-ce docker-ce-cli containerd.io- test Docker:
sudo docker run hello-world - add your user to the Docker group:
sudo usermod -aG docker $USER - close current terminal and open a new one (for changes to take effect)
- Test Docker without sudo (admin permissions):
docker run hello-world- If this gives an error, try a complete reboot and the
dockergroup to your user again.
- If this gives an error, try a complete reboot and the
sudo apt install docker-compose
NOTE: this does not install the latest available version, but it will do the job. Alternatively, check Step 2 of: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-compose-on-ubuntu-14-04
- Set up your environment variables, so that the docker container runs as the user on the host machine:
make .env
- Make sure to add an ssh key to your BitBucket account (account settings -> ssh-keys). The instructions to generate such key can be found e.g. here: https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
- get a copy of the git repo:
git clone git@bitbucket.org:c0d0g3n/ee5.git - move into the project folder:
cd ee5 - build the project:
docker-compose build(takes a long time) - install yarn packages:
docker-compose run server rails yarn:install - create a local database (hosted inside Docker):
docker-compose run server rails db:create - start the server:
docker-compose up - visit the homepage at http://localhost:3000 (don't forget port 3000!)
- NOTE: The port can be changed in
.env, generated bymake .env.
- NOTE: The port can be changed in
- stop the server:
docker-compose down(orctrl+cwhen docker-compose is running in the foreground) - Seed the database with demo data:
docker-compose run server rails db:seed.
LINUX TIP: I created a symbolic link for docker-compose: first find where docker-compose is installed (which docker-compose). Move to that folder and create a symbolic link like this: sudo ln -s docker-compose dc. Now instead of docker-compose, type dc.
CODE QUALITY TIP: This repo is configured to use Rubocop (https://docs.rubocop.org/en/stable/). Install the Rubocop plugin for your editor (supported editors: https://docs.rubocop.org/en/stable/integration_with_other_tools/) and help ensure code quality.
- start server:
docker-compose up- start server as daemon:
docker-compose up -d
- start server as daemon:
- stop server:
docker-compose down- alternatively press
ctrl+cwhen Docker is running in the foreground
- alternatively press
- run arbitrary command on server:
docker-compose run server <command>- interactive shell:
docker-compose run server bash
- interactive shell:
- rebuild server (e.g. to install extra components):
docker-compose build
- Atomic commits: https://www.freshconsulting.com/atomic-commits/
- Clear and concise commit messages: https://chris.beams.io/posts/git-commit/
- NOTE: If you're inclined to write
andin your commit message, that may be a sign that your commit is not really atomic.
- NOTE: If you're inclined to write
- Commit often = loose less work
- Create a feature branch for each new feature
- The master branch contains only working code
- Communicate what you are working on, to reduce the chance of complex merges and redundant work
- Team members work on different features to reduce the chance of merges
- Change your terminal's prompt ($PS1 on Linux) to show git status and the current branch name
- When starting a coding session, execute
git pull <remote> <branch>to start with the most up-to-date version of our code base. (Fetch other's work from the cloud) - (May have to migrate the database after some changes, I don't know yet how rails handles this exactly)
- Do some work
- Test your work
- Check what changes you've made, what is (not) staged, what branch, ahead/behind...:
git status - Stage your work:
git add <path to file or folder>- to stage all changes in your working directory:
git add .
- to stage all changes in your working directory:
- Commit your work:
git commit(This opens your editor and allows you to type a commit message, the commit will go through after the file is saved and closed. It is always possible to abort before committing by hittingctrl+cin the terminal.)- Atomic and concise commits!
- Forgot to add something to your commit?
git commit -amend
- Push your work so the team can see it:
git push <remote> <branch> - When behind on the remote branch, rebase:
git pull --rebase <remote> <branch>(afterwards try to push again) - View the most recent commits:
git log - View a particular commit in detail:
git show <first few letters of commit hash> - Find more help about a command:
man <command>,<command> --help,git help <git command>...
Use a separate branch for each new feature
concept explained: https://youtu.be/0iuqXh0oojo The ideal world: https://nvie.com/posts/a-successful-git-branching-model/ More workflows: https://www.atlassian.com/git/tutorials/comparing-workflows
- create a new branch:
git branch <new branch name>- e.g.
git branch feature/user-login(note the convention; start a feature branch withfeature/)
- e.g.
- change branches:
git checkout <branch>- create and move to branch at once:
git checkout -b <branch>
- create and move to branch at once:
- merge branches (run while the destination branch is active):
git merge --no-ff <branch from which commits will be imported>--no-ffdisables fast forwarding and hence preserves as much of the branches history as possible
- remove a branch:
git branch -d <branch>
Best practice is to create a new branch. That way you are not bothered by the changes of other people and the master branch remains uncluttered and stable.
- Create and move to a new branch:
git checkout -b feature/<your-feature-name>. - Develop the feature and create atomic commits during the process.
- You can even mirror your feature on Bitbucket:
git push -u origin feature/<your-feature-name> - [TODO: Ask for a merge]
-
Run
git status -u, this will give you an overview of the changes you've made.- Note: the
-uflag (optional) ensures that all new/changed files are shown, instead of being grouped by the parent folder.
- Note: the
-
Check the new/edited files to make sure they relate to each other (ensure that your commit will be atomic: https://www.freshconsulting.com/atomic-commits/).
-
Make sure that no unwanted changes are present. (E.g. debug statements like
puts "test 123", or files that you do not need anymore.) -
Stage your files:
git add <file path>.- Stage all changes in your working directory
(the one shown in the prompt of the termina):
git add .(think about atomic commits!)
- Stage all changes in your working directory
(the one shown in the prompt of the termina):
-
Create the commit:
git commit. This opens a file calledCOMMIT_EDITMSGin the default git editor.- How to change your default git editor: https://www.git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#_code_core_editor_code (and other config options)
-
Type a commit message. The commit goes through after you save and close the file.
- If you decide you do not want to commit, leave the file open, go to the terminal
and hit
ctrl + cto abort the commit process. - Write proper commit messages, see: https://chris.beams.io/posts/git-commit/.
(By using
git log, you can see how other teammates format their messages (hopefully correctly).)
- If you decide you do not want to commit, leave the file open, go to the terminal
and hit
-
In case you want to change your latest commit, go through staging again and commit the additional changes with
git commit -amend. Note this is not possible after you have pushed! -
You are now ready to push your commit! (see FAQ)
You need to push your work to Bitbucket,
so your team members can pull in the changes: git push <remote> <branch>.
During the process, you may be prompted to enter the password of your ssh key (the one you added to BitBucket).
Your "error" looks similar to the following:
> git push <remote> <branch>
To bitbucket.org:c0d0g3n/ee5.git
! [rejected] <branch> -> <branch> (fetch first)
error: failed to push some refs to 'git@bitbucket.org:c0d0g3n/ee5.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
This means somebody from your team was first to push a new commit to the server. (Nice - a lot of work is being done!)
You will have to download (pull) their work first, and add your work on top of their changes.
Use the following command: git pull --rebase <remote> <branch>
(replace <remote> and branch with the values that apply to your system.)
Feel free to check the latest commits to see what your team has been working on
(and to assure the rebase was successful): git log.
Check the FAQ if pulling results in a merge conflict.
After you successfully rebased your commit on top of your team's work,
you can try to push again: git push <remote> <branch>.
[TODO - put a message in the chat to get help]
-
Try if the command has a help flag:
your-command --help. Usually this allows you to get very granular instructions for subcommands (e.g.rails generate controller --help).- Note most commands return a man page when asked for help, see below how to navigate them.
-
Try if the command has a help subcommand: e.g.
git help branch. -
Try the manual page of a command: e.g.
man git,man git branch.- While on a man page, hit
hto show help about how to navigate a man page (as said in the bottom left corner of every man page). E.g. man pages are searchable! - Hit
qto close the man page.
- While on a man page, hit
-
Ask a teammate.
-
Use the internet.