Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add setup scripts. Fixes #1467 #1627

Merged
merged 20 commits into from
Feb 15, 2018

Conversation

psinghal20
Copy link
Contributor

Fixes #1467. This adds the setup scripts for the repo. The main setup.py looks for the operating system of the user and executes the corresponding script. Right now, the script supports Debian based systems, OSX and Windows systems.

@ragesoss
Copy link
Member

Why is the main script in python?

@psinghal20
Copy link
Contributor Author

psinghal20 commented Jan 22, 2018

@ragesoss I tried to create a single script which could detect the operating system of the user and run the appropriate script/batch file. I thought python was decent option for that as it is widely used. I am not sure if it is the right way but I thought it could work.

setup.py Outdated
shell=True, check=True)

if platform.platform().lower().find('ubuntu') != -1 \
or platform.platform.lower().find('debian') != -1:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be platform()

echo 'Setting up your developmental environment. This may take a while.'

echo '[*] Adding keys...'
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curl may be absent. If so, it should exit at this point with instructions to install curl.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it exit the script or try to install curl also?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way would be okay.

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB && echo '[*] Installing rvm...' && \curl -sSL https://get.rvm.io | bash -s stable

echo '[*] Installing Ruby-2.5.0...'
sudo rvm install ruby-2.5.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ruby 2.5.0 will not yet be active on a fresh install. When RVM installer exits, it provides a necessary step in its output, along the lines of source /home/sage/.rvm/scripts/rvm.

Only once you do that (or log out and log in again) will rvm be active, and then you can install the required ruby version.

echo '[*] Installing GNUpg...'
sudo apt-get install gnupg

echo '[*] Adding Keys for rvm...'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This command both gets keys and installs RVM.

It also overwrites any previous installation and reinstalls it if already present. It should skip installation if rvm is already installed.

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB && echo '[*] Installing rvm...' && \curl -sSL https://get.rvm.io | bash -s stable

echo '[*] Installing Ruby-2.5.0...'
sudo rvm install ruby-2.5.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RVM is not installed with sudo, so this command should not be sudo either.

cp config/database.example.yml config/database.yml

echo '[*] Installing Mysql-server...'
sudo apt-get install mysql-server
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On recent debian, at least, this needs to be mariadb-server or default-mysql-server.

gem install bundler

echo '[*] Installing Gems and dependencies...'
sudo apt-get install libmysqlclient-dev libpq-dev libqtwebkit-dev
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure any of these are actually necessary any more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strike that... libmysqlclient-dev is needed to build the mysql2 gem, but it actually is now provided by libmariadbclient-dev on debian.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they are needed when used with MySQL. At least I needed them when I was setting up my developmental environment.

sudo apt-get install pandoc

echo '[*] Creating configuration files...'
cp config/application.example.yml config/application.yml
Copy link
Member

@ragesoss ragesoss Jan 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two cp steps should only be done if the relevant files already present already. Otherwise, they'll overwrite what is there.


echo '[*] Creating configuration files...'
cp config/application.example.yml config/application.yml
cp config/database.example.yml config/database.yml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what we want to do here is to change the example database.yml file to use a different user instead of root, and then create that user in mysql with the password specified in the file and grant ownership to that user for the new databases.

Otherwise, this will break at the rake step unless the root mysql password has been set to the same one in database.yml.

@psinghal20
Copy link
Contributor Author

Thanks for the review. I will look through all the changes carefully.

bundle install

echo '[*] Installing yarn...'
sudo apt-get install yarn
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work without first adding a repo that has (the right) yarn. On debian, there may be a default package, cmdtest, which provides yarn and conflicts with the yarn deb repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I shifted the command for adding the repo for yarn on the top so that for all the keys required we need to call apt-get update only once.

@ragesoss
Copy link
Member

This is a promising start! I'll merge it once I can run it on a clean debian system, and once we get reports of it working successfully on windows and OSX. (I might be able to test those in a VM once the debian version works.)

A few ideas that would help make this easier to use, maintain, and troubleshoot:

  1. Organize the installations by stack: start with the basic system programs that need to be installed (all the things added via apt on debian), then try to install ruby and bundle install, then create the database and run the migrations, then install the frontend dependencies and build the assets.
  2. Avoid redo-ing any steps that are already done, whenever that can be detected.
  3. Reduce the amount of permanent output, so that the current task is always visible and only errors and warnings end up printed on the terminal at the end. This has some nice tricks to that end: https://robots.thoughtbot.com/shell-script-suggestions-for-speedy-setups
  4. Extract common parts that don't depend on a particular system — the mysql and bundle and rake commands, at least — to their own scripts that can be called from the OS-specific scripts, so that they can be updated in just one place where possible.

This is a big job, so thanks for taking this on!

Makes the script silent ie. script doesn't print unnecessary installation output
statements and prints only the working task. Errors are still logged on the shell
for refrence for the user.
Add the default credentials for the user in database.example.yml and create user in debian setup script.
else
printf "${CLEAR_LINE}Application configurations not found!\n"
printf '[*] Creating Application configurations...'
cp config/application.example.yml config/application.yml && printf "${CLEAR_LINE}Application configurations created!\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must be done before db:migrate, or the migrations will fail.

@psinghal20 psinghal20 force-pushed the setup-script branch 3 times, most recently from 1edc9a9 to dfff87f Compare February 2, 2018 22:09
@psinghal20
Copy link
Contributor Author

Hi @ragesoss , I had made the changes for the ruby error and exit. Please look into this and suggest any changes.

# Add Keys for MariaDB
output_line "sudo apt-get install -y software-properties-common"
output_line "sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8" && \
output_line "sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://sgp1.mirrors.digitalocean.com/mariadb/repo/10.2/ubuntu xenial main'"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the problem. We should rely on whatever package provides mysql from the system default repositories. This repo is not compatible with my debian buster VM.

@ragesoss
Copy link
Member

Got through the migrations this time, but now it's got problems probably because of too-old node (4.8.4 from the debian repo) which is only available via nodejs and not node like expected.

@ragesoss
Copy link
Member

The debian script now works. I think before we merge this, though, we should add some directions for use to the script... something saying 'this is a work in progress; please report your setup results and any error messages at [link to issue on github]'.

It almost certainly doesn't work on Windows or OSX yet, but we can keep the current scripts as starting points.

@ragesoss ragesoss merged commit da6c4d4 into WikiEducationFoundation:master Feb 15, 2018
@psinghal20 psinghal20 deleted the setup-script branch March 5, 2018 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants