How I auto-start my dev environment on Windows 10
Developers face lot of challenges with infrastructure setup and other non-dev activities for local development. For non-local environments you should have infrastructure provisioning knowledge or DevOps support.
Whenever I start development of any new project I start with creation of virtual environment for the same, you can provision virtual environment on any operating system but I prefer Unix/Linux based OS for development and can rely on windows for other tooling. So I prefer installing windows and making virtual machine with Linux based OS for development.
Let's list out all software's and tools required for development:
- Windows 10 - Base operating system for booting machine
- Virtual Box - Virtualization software for installing Linux
- Docker - For running my software in container
- Putty - For accessing linux shell from windows
Everytime whenever you start your machine you need to start all components to start the development. In DevOps world we have saying "Automate the task which you are doing twice!"
Start virtual machine:
We can configure to start each component in a bash script. First of all we need to start our virtual box machine.
- Add virtualbox bin path to PATH variable. It is virtualbox installation directory and should look like: C:\Program Files\Oracle\VirtualBox. This path should have VBoxManage executable. For more information on adding path variable, click here
- After adding path variable you should be able to run VBoxManage command from the command prompt, if the command is not recognized try to restart command prompt and recheck path variable.
- Using VBoxManage you can manage your virtual machines i.e. Start, Stop, Restart particular virtual machine
Enabling Docker on Virtual Machine
Once virtual machine is started you need to start docker and other required services which are needed for you development.
Once you have installed docker you can enable it's service to start it on boot-up using below command:
Setup password-less SSH Connection
Password less connectivity between windows machine and Linux is required for having prompt-less connection.
- Generate public-private key pair on windows machine using ssh-keygen utility
- Copy public key id_rsa.pub and paste at the bottom of authorized_keys file on linux machine
Configuring Putty
Once your virtual machine is started we need shell to interact with the machine. For that we need to first configure session in putty and load the configuration with it.
- Open putty, enter username@ip-address of your virtual machine in host name section
- Enter name for saved session in Saved Sessions box and hit save
- Go to Connection > SSH > Auth and select private key which you have created while setting up password-less connection
- Go to Session and save it
Configure Startup script in windows
Now all setup is done you can create a text file with extension ".bat" which is executable script in windows, you can instruct machine to do automated things using batch script.
- Make output silent and start virtual machine, here you need to mention virtualbox machine name in my case it's ubuntu-devops, you can find it in settings window
- Headless start will make the machine start in background without any UI (Dont' worry we will access terminal from Putty)
- This command will trigger startup of machine and we need to make sure if it's started or not for that we can use ping mechanism till machine starts.
- If machine is not pingable then we need to try it again and if it's up and running then we need to open putty session. For this purpose we need to use looping in batch script like below
- For starting up putty session get the path of putty executable and with load option you can start the saved session from putty. Note that this will be password-less as we have set it up to use password-less ssh.
- Our final batch script will look like below, save it.
Configure script to start at Windows Startup
You can configure any software or batch script to start at windows startup by copying the script in Startup program.
To open configuration for startup goto run and type shell:startup, one window with startup programs will open, you can copy created batch script in this directory.
All Set! Just restart your windows machine and test the configuration. For any issues you can reach out to me.