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

[Static build mode vs Plugin build mode and Private Repos Driver] #343

Closed
powerkimhub opened this issue Apr 6, 2021 · 6 comments
Closed
Assignees
Labels
enhancement New feature or request

Comments

@powerkimhub
Copy link
Member

What would you like to be enhanced

(CC: @innodreamer )

  • CB-Spider는 server 및 driver pkg build 및 연동 방법이 2가지가 있음.

    • static build mode: 일반적인 go build 방법, Server 및 driver들이 하나의 binary로 생성됨.
    • plugin build mode: 각 Driver들을 plugin mode로 개별 build하여 shared library(*.so)로 생성 후 서버에서 동적으로 호출.
    • setup.env에 PLUGIN_SW=ON 또는 OFF로 모든 드라이버를 일괄 적용하고 있음.
    • 참고: static build mode, plugin build mode는 일반적인 용어가 아닐 수 있음.
  • Cloud-Twin Driver 등 community 운영 정책상 Private Repos가 별도 존재함.

    • static build mode의 경우: 별도 repos의 driver pkg 유무에 따라 서버 소스 반영을 위한 편집 선행 작업이 필연적,
      • build path를 위한 symbolic link 등 방법도 취해줘야 함. => 시험시 마다 신경 쓰이는 작업
    • plugin build mode의 경우: driver pkg를 별도 build 후 shared lib(.so)를 특정 경로(./cloud-driver-libs/)에 복사하면 끝.

Why is this needed

  • Go에는 C언어 #define 같은 매크로 없어, 컴파일 시 코드 switching에 어려움이 있음.
  • 현재 동일 코드에 static build mode와 plugin build mode가 공존하여,
    • 여전히 private repos로 운영되는 Driver 통합 시험시 소스 편집 필요.

Proposed solution

@powerkimhub powerkimhub added the enhancement New feature or request label Apr 6, 2021
@powerkimhub powerkimhub self-assigned this Apr 6, 2021
@powerkimhub
Copy link
Member Author

@jihoon-seo

@jihoon-seo
Copy link
Member

shared lib 을 build 할 때 사용한 dep 들의 버전 (e.g. go.mod 에 명시된 dep 들의 버전) 과
binary 를 build 할 때 사용한 dep 들의 버전이 정확히 일치해야 할 것으로 예상됩니다.

전에는 plugin mode 에서 어떤 현상이 있었냐면

  1. 드라이버 빌드 스크립트를 실행했더니 ~/go/pkg/github.com/cloud-barista/cb-spider@v*.. 에 있는 코드를 이용하여 드라이버 빌드를 수행한 것으로 추정됨
  2. cb-spider 바이너리 빌드 명령을 실행했더니 ~/go/src/github.com/cloud-barista/cb-spider 에 있는 코드를 이용하여 바이너리 빌드
  3. 바이너리를 실행하고, cloud info 들을 등록하고, 드라이버를 사용하는 명령을 spider 에 내리니,
    "바이너리와 shared lib 을 빌드할 때 사용된 코드의 버전이 다름"
    과 같은 에러 메시지가 나왔었습니다.

이는 한 개발자의 개발환경에서 발생할 수도 있고
드라이버 파일을 빌드하여 다른 사용자에게 주었을 때에도 발생할 수 있는 문제입니다.

@powerkimhub
Copy link
Member Author

@jihoon-seo

  • 일단, Driver Interface가 다를 경우 나타날수 있을 겁니다.
  • 반영시, 관련 사항도 점검해보도록 하지요.

@powerkimhub
Copy link
Member Author

@innodreamer @jihoon-seo

전에는 plugin mode 에서 어떤 현상이 있었냐면

[현황]

  • 쉽게 해결될 문제가 아니네요.

  • 증상: plugin was built with a different version of package {something package}

    • 오류 메시지 원본
      [CLOUD-BARISTA].[ERROR]: 2021-04-07 08:04:26 CloudDriverHandler.go:251, github.com/cloud-barista/cb-spider/cloud-control-manager.getCloudDriver() - plugin.Open: plugin.Open("/root/go/src/github.com/cloud-barista/cb-spider/cloud-driver-libs/cloudtwin-driver-v1.0"): plugin was built with a different version of package golang.org/x/sys/internal/unsafeheader
      
  • 보고된 관련 Golang Issues들이 많음

    • 대표 이슈: cmd/go: plugin versions do not match when built within vs. outside a module golang/go#31354
      • 요약:
        • plugin mode로 빌드(abc.so 생성, driver)할 때 abc.so에서 사용하는 interface(driver interface)를 포함하는 module pkg(spider server)를
        • 기존 방법처럼, go.mod에 github/.../ path 등 원격지 path로 설정하면(remote plugin?), different version pkg 오류가 발생함
          • 공통으로 사용하는 내부 module의 각 fetch된 버전 차이일 수도 있겠음.
        • 이 문제를 해결하는 현재 알려진 trick은 plugin mod build 시 사용하는 module을 local pkg(local에 spider pkg 소스가 함께 존재)로 go.mod에 설정하는 방법임 (ex) replace github.com/zimnx/central => ../central
        • '야, 이거 원래 하던 데로 go.mod 정의를 사용 할수 없어? 그래야, plugin 이지....'
        • '이런 비슷한 이슈가 많이 올라오는데 아직 딱히 path 계획이 없는거 같아.'

[목표]

  • 목표: Cloud Driver는 Cloud Driver Interface 소스만 있으면, 별도로 개발 가능할 수 있어야 함.
  • 목표: Cloud-Twin과 같은 별도의 private repos driver들의 build 및 driver binary 활용한 운영이 용이해야 함.
    • Go plugin: local 환경에 통합(spider server + drivers)되 있을 경우 잘동작함.
    • 다른 node에서 driver build 후 driver.so만 spider server에 복사 활용하면 위와 같은 오류 발생함.

[계획]

  • Spider Server: plugin mode로 운영

    • setup.env 설정: export PLUGIN_SW=ON
  • built-in Driver 경우: plugin mode로 build (build 결과: shared library, *.so)

    • driver들의 *.so는 github에 관리하지 않음(현재 driver total file size: 약 200MB)
    • 전체 driver 일괄 build: cb-spider/build_all_driver_lib.sh 참고
    • 개별 driver 경로(*-plugin)의 build script 참고
      • 예시)
        aws-plugin/
        |-- AwsDriver-lib.go
        `-- build_driver_lib.sh
  • 별도 개발되는 driver 경우: container 환경으로 build 가능한 방법 및 가이드 제공 예정

    • 별도 repos 및 private repos로 운영되는 driver들의 일관되고 용이한 build 환경
    • 개략 절차
      • VM에 git clone spider.git
      • VM에 container 생성 (필요 volume mount, 환경 변수 등 설정)
      • container 내부에서 git clone driver-repos.git
      • container 내부에서 driver.so build => VM의 cb-spider/cloud-driver-libs/* 위치에 저장
      • container 종료 => 개발 환경 및 driver source clear
    • 시험 운영 후 문제 없을 경우 default 운영 환경을 PLUGIN_SW=ON으로 변경
  • Go runtime 개선 전까지 일단 container 환경으로 운영

@powerkimhub powerkimhub pinned this issue Apr 7, 2021
@powerkimhub
Copy link
Member Author

powerkimhub commented Apr 8, 2021


@innodreamer

  • NCP build 방법 아래 가이드 참고하시기 바랍니다. (Ubuntu 환경)
  • 다음 파일 참고하시어, NCP Script 추가해주시기 바랍니다.
    • $CBSPIDER_ROOT/utils/driver-build-docker/2.build/cloud-twin-build.sh

@jihoon-seo

  • 좀 사용해보다가, 괜찮으면 driver plugin을 default 환경으로 가고자 합니다.
    • setup.env: export PLUGIN_SW=ON
  • cb-operation에 적용을 위해서는 반경 작업이 필요해 보입니다.
    • private repos들의 소스가 공개되는 방법은 안되겠습니다.
    • 그 시점이 되면 방법을 고민해보도록 하지요.

[How to build Cloud-Twin Driver with plugin mode]

---- in Node or VM has CB-Spider Source

  • Check the CBSPIDER_ROOT path
$ vi setup.env
  • Run a docker for driver building
$ cd $CBSPIDER_ROOT/utils/driver-build-docker;
$ ./1.driver-build-container-run.sh

---- in the Container

  • build driver
    root@driver-build:~# cd 2.build/
    root@driver-build:~/2.build# ./cloud-twin-build.sh
    
    $HOME path is /home/ubuntu
    $CBSPIDER_ROOT path is /home/ubuntu/go/src/github.com/cloud-barista/cb-spider
    Cloning into '/home/ubuntu/cloud-twin'...
    Username for 'https://github.com': powerkimhub
    Password for 'https://powerkimhub@github.com':
    remote: Enumerating objects: 2290, done.
    remote: Counting objects: 100% (2290/2290), done.
    remote: Compressing objects: 100% (1842/1842), done.
    remote: Total 2290 (delta 450), reused 2214 (delta 400), pack-reused 0
    Receiving objects: 100% (2290/2290), 33.02 MiB | 16.19 MiB/s, done.
    Resolving deltas: 100% (450/450), done.
    
    
  • exit from the container
    root@driver-build:~/2.build# exit

---- return in Node or VM

ubuntu@nodedev2:driver-build-docker#

@powerkimhub powerkimhub unpinned this issue Apr 17, 2021
@innodreamer
Copy link
Member

NCP driver에 대한 신규 Plugin 방식 driver build 적용을 완료했습니다.
: #358

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants