All Case Studies Design Development Interviews Our Way Project Management

How To Automate Local App Setup Process Using bin/setup

Recently I did some research on creating an interactive bin/setup script that can lead developer, who joined a new project, through app local setup process.

 

The new bin/setup script was supposed to create a sec_config.yml file from sample, while asking developer to provide necessary missing values and saving them to the new file.

The script I created is a sample one with a possibility to change it when needed. I created support for standard sec_config/secrets files in yaml format, as well as for standard .env file format.

Script is divided into few sections.

 

Section #1

[code]

Here you'd want to add commands that install/update gems, install required ruby version, npm/bower dependencies etc.

 

Section #2

[code]

This section is responsible for all config files logic.

In the first block you can create database.yml from sample file. If the database.yml.sample file has two keys: username and password, you can replace them like above.

You can also replace code with gsub_file method like here:

[code]

[code]

In this block you can create a new config file from sample or edit the existing one (if it's present). You need to set config path in CONFIG_FILE constant. Script will ask the user to provide required values (keys are present in sample file, but they have no value).

[code]

For this sec_config.yml.sample file the script will work like this:

[code]

And that results in following sec_config.yml:

[code]

[code]

The block above is for creating standard .env file from sample:

[code]

This will ask the user for values that are missing. You need to get value for each key that is present and has no value in sample file.

 

Section #3

[code]

This section is taking care of database setup. You can just use bin/rake db:setup here or add additional commands like bin/rake db:test:prepare. Of course you can add beautiful and colourful messages like in example.

 

Section #4

[code]

 

Section #5

[code]

Here you can add messages for developers.

 

Feel free to use and customize this script in your projects. I hope this will help developers set up projects faster and easier.

Follow Netguru
Join our Newsletter

READ ALSO FROM Dev
Read also
Need a successful project?
Estimate project or contact us