Preparing VSCode environment for Bitnami Redmine

##Introduction
This article is for a beginner developer of redmine plugin who is going to ...

- build environement with Bitnami redmine on Windows
- use VScode
- wants to know the easiest way and capable for buy another PC


condition : 
- Windows10 64bit
- bitnami-redmine-4.1.1-0-windows-x64-installer.exe
bitnami redmine 3.x will be also fine 


##Procedure
### 1. Install redmine

### 1.1. Package installation
Basic installation will be completed with bitnami redmine package installer.
https://bitnami.com/stack/redmine/installer

#### 1.2. Configure DB setting
Change "development" databese configuration to use "production" database table. This is quite easy way and easy to understand. open config file in `C:¥Bitnami¥redmine-4.1.1-0¥apps¥redmine¥htdocs¥config¥database.yml`

```database.yml
production:
  adapter: mysql2
  database: bitnami_redmine
  host: 127.0.0.1
  username: bitnami
  password: 5a6e5788be
  encoding: utf8
  port: 3306
development:
  adapter: mysql2
  database: bitnami_redmine
  host: localhost
  username: bitnami
  password: 5a6e5788be
  encoding: utf8
```

DB password is hashed password specified in bitnami installer.


#### 1.3. Disable relative_url_root
Edit config file as follow.
`C:¥Bitnami¥redmine-4.1.1-0¥apps¥redmine¥htdocs¥config¥additional_environment.rb` を開きます。

```additional_environment.rb
#config.action_controller.relative_url_root = '/redmine'
```

Note: 
Please enable this option when runs as production environment.
This is example for this congfig.
![relative_url_root.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/434780/964d0a57-4bcf-6ca1-a422-f1a72b7d72ca.png)



#### 1.4. Restart
Restart all services with using bitnami console.
![server_restart all.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/434780/c5adfbeb-34c4-7b3d-4ba6-dbb617c22514.png)



### 2. VSCode

#### 2.1. VSCode extensions
Find and install **Rails** and **Ruby** extensions.
![VSCode extensions.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/434780/1f5a932d-6f5a-afd7-8302-0739690576f4.png)

**Ruby Solargraph** will be installed. If not, please install it.


#### 2.2. Set home directory
Open application menu "File > Open Folder" and set redmine home directory "htdocs" (C:\Bitnami\redmine-4.1.1-0\apps\redmine\htdocs). 
![VSCode.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/434780/fa0032ef-a2dd-8a03-ef27-b1ca79d4df53.png)


#### 2.3. Set launch.json configuration
Write launch.json config as follows. Launch.json can be initialized with some config file such as node.js.

```launch.json
{
    "version": "0.2.0",
    "configurations": [

        {
            "name": "launch rails server",
            "type": "Ruby",
            "request": "launch",
            "cwd": "${workspaceRoot}",
            "program": "bin/rails",
            "args": ["server"],
            "useBundler": false
        }
    ]
}
```

![VSCode launch.jsonlaunch_json.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/434780/ccb302ea-e5a1-fe9c-c354-657ee351379e.png)



### 3. Configuration
This is the most difficult part. When you face another error message, please read error message in debug console and debug it.


#### 3.1. Add PATH to system variables
Please set bitnami_redmine path "C:\Bitnami\redmine-4.1.1-0\ruby\bin" to windows system variables.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/434780/39bd2ec7-d534-21a2-4835-491806259017.png)

Restart windows and run VSCode.
Check some ruby command with VSCode Terminal window. You will get ruby version with **ruby -v** command.

```
ruby -v
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/434780/b327f79f-a638-c825-3fa0-e19745d4e241.png)



#### 3.2. [redmine3.x only] Install bundler 
old redmine version does not include "bundler" gem. Please install specific version manually. Bundler 2.x.x is not for redmine 3.x.

```
gem install bundler -v 1.17.3
```


#### 3.3. Install gems
Install following gems. When old

```
gem install solargraph
gem install ruby-debug-ide
gem install debase
```

You can check install gems.

```
gem list --local
```


#### 3.7. Bundle install
Before bundle install, add "railties" to your Gemfile in redmine home directory.

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/434780/7901233f-29ed-ec33-2028-8f6e3b08a28b.png)


Bundle install Gemfile. Type "bundle install --no-deployment" in VSCode terminal.

```
> bundle install --no-deployment
```
![VSCode bundle install.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/434780/9cec7a78-62bc-f299-ca6a-067d21e477ce.png)





### 4. Start debug!
#### 4.1. Run as development environment
Start debugging with ">" button. This is successful capture.
![Successful.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/434780/8c5162b9-e4eb-0ff9-d228-413e56f02677.png)


Open browser and access http://localhost:3000. You can see live logs in debug console.
![VSCode_redmine_development.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/434780/e64b5c6c-f088-b2ac-0d3c-31f3dca8af2c.png)


#### 4.2. Debug
Enjoy your development job with VSCode!
![Debug_mode.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/434780/8a16c2ab-3a67-aa75-4efe-861011d9e475.png)


#### 4.3. Stop debug
Stop server with stop button.
![Stop.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/434780/9b59c1e1-b992-310c-0fb2-14484195c37f.png)




## Let's try 
I'm looking forward to seeing new plugin or up-to-date existing.


## reference
This is my old article, when you have trouble "rmagik" or "ImageMagick" please check it. 
[【旧】Bitnami Redmineをdevelopmentで起動する(VSCode編) ](https://qiita.com/aki360P/items/bbfdf28d17fb35c0d9bb)

I released sample plugin that has "project setting tab" and empty view. 
https://github.com/aki360P/redmine_empty_plugin