Setup Windows development environment for Tencent-BlueKing Standard OPS

1. Install Python 2.7 and npm tool

2. Clone source code from: https://github.com/Tencent/bk-sops

3. Run cmd shell, change current directory to root path of bk-sops

4. Install required packages by run:

pip install --proxy={proxy if any} -r requirements.txt

5. Open url “http://{BK_PAAS_HOST}/admin/app/app/” of your BlueKing paas platform, copy app-code and token for app “标准运维”(bk_sops)

6. Create a bat file and replace these variables marked with {} to real values in your environment. Run the bat file to setup env variables:

env.bat

set APP_ID=bk_sops
set APP_TOKEN={APP_TOKEN}
set BK_PAAS_HOST={BK_PAAS_HOST}
set BK_CC_HOST={BK_CC_HOST}
set BK_JOB_HOST={BK_JOB_HOST}

7. Other steps please refer to: https://github.com/Tencent/bk-sops/blob/master/docs/install/dev_deploy.md

At last, you canc reate a bat file to run local development environment quickly:

run-local-sops.bat

start cmd.exe /c "env.bat & python manage.py celery worker -l info"
start cmd.exe /c "env.bat & python manage.py celery beat -l info"
env.bat & python manage.py runserver 8000

Create standard component by run:

python manage.py create_atoms_app docker_image_tags

# Issues

1. Please download and install C++ Compiler for Python 2.7: http://aka.ms/vcpython27 if you meet the error below:

    Running setup.py install for ujson ... error
    ERROR: Command errored out with exit status 1:
     command: 'd:\python27\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'c:\\users\\admini~1\\appdata\\local\\temp\\pip-install-jnby9g\\ujson\\setup.py'"'"'; __file__='"'"'c:\\users\\admini~1\\appdata\\local\\temp\\pip-install-jnby9g\\ujson\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'c:\users\admini~1\appdata\local\temp\pip-record-4zcz9a\install-record.txt' --single-version-externally-managed --compile
         cwd: c:\users\admini~1\appdata\local\temp\pip-install-jnby9g\ujson\
    Complete output (5 lines):
    running install
    running build
    running build_ext
    building 'ujson' extension
    error: Microsoft Visual C++ 9.0 is required. Get it from http://aka.ms/vcpython27
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'd:\python27\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'c:\\users\\admini~1\\appdata\\local\\temp\\pip-install-jnby9g\\ujson\\setup.py'"'"'; __file__='"'"'c:\\users\\admini~1\\appdata\\local\\temp\\pip-install-jnby9g\\ujson\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'c:\users\admini~1\appdata\local\temp\pip-record-4zcz9a\install-record.txt' --single-version-externally-managed --compile Check the logs for full command output.

2. Remove double quote sign from env variable values if you meet the kind of error like below:

  File "D:\Projects\BlueKing\bk-sops\blueapps\conf\log.py", line 47, in get_logging_config_dict
    os.makedirs(log_dir)
  File "D:\Python27\lib\os.py", line 157, in makedirs
    mkdir(name, mode)
WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect: 'D:\\Projects\\BlueKing\\logs\\"bk_sops"'

3. Please install python-magic-bin if you meet the issue below:

  File "D:\Projects\BlueKing\bk-sops\gcloud\contrib\appmaker\api.py", line 16, in 
    import magic
  File "D:\Python27\lib\site-packages\magic.py", line 181, in 
    raise ImportError('failed to find libmagic.  Check your installation')
ImportError: failed to find libmagic.  Check your installation

install python-magic-bin

pip install python-magic-bin==0.4.14

4. Run `npm rebuild node-sass` to download node sass binding if you meet error during running: npm run build — –STATIC_ENV=dev

This usually happens because your environment has changed since running `npm install`.
Run `npm rebuild node-sass` to download the binding for your current environment.