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

Add docker-compose #1666

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ log/
*.log
*.history

# Ignore all docker-compose files created by users, except docker-compose.yaml
*docker-compose*.yaml
!docker-compose.yaml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docker-compose.env

같은걸 추가해서, 사용자용 env 구성을 지원하면 좋을 것 같네요. :)

아래와 같은 구분자로, 각 ENV 들을 구분 및 활용하면 어떨까 싶습니다.

TB_XXXX
SP_XXXX
MAP_XXX

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

helm 스타일을 차용해서 ignore를 아래와 같은 스타일로 적용해보겠습니다 ^^

*docker-compose*.yaml
!docker-compose.yaml
*value*.env
!value.env

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

파일명으로 .env 는 어떨까요? 많이 사용하는 방식이라고는 하는데.. 음..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코멘트 주신 내용이 일반적인 .env과는 다르다고 느껴져 위와 같이 제안 드렸던 부분입니다.

다른 방법을 찾아보도록 하겠습니다.

94 changes: 94 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
version: "3.6"
services:
# CB-Spider
cb-spider:
image: cloudbaristaorg/cb-spider:0.9.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
image: cloudbaristaorg/cb-spider:0.9.0
image: cloudbaristaorg/cb-spider:${SP_TAG}

SP_TAG=0.9.0
SP_TAG=latest

환경변수로 지정할 수 있게하면 어떨까요?

Copy link
Member Author

@yunkon-kim yunkon-kim Jul 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seokho-son 말씀주신 의견에 대해 검토 의견을 말씀드립니다.

docker-compose.yaml은 container를 구동 및 연관 관계를 명시해 놓은 파일이라고 생각합니다.

예를 들어, docker-composel.yaml의 envrionment에는 container 구동에 필요한 환경 변수(Dockerfile에 명시된 환경 변수)를 명시하고 있습니다. 이를 환경 변수로 만들면 재차 환경변수를 뽑는 상황이 되는 것으로 보이고 가독성이 상당히 떨어지는 것 같습니다. (아래 적용 버전을 참고하시면 될 것 같습니다.)

그래서 API_USERNAME, API_PASSWORD, DB_USER, DB_PASSWROD 등과 같이 민감함 정보에 대해서만 .env에서 읽도록만들고, GitHub 상에 오픈되지 않도록 하는 방법이 좋겠습니다.

(docker-compose의 TB environment sample)

    environment:
      - CBTUMBLEBUG_ROOT=${TB_CBTUMBLEBUG_ROOT}
      - CBSTORE_ROOT=${TB_CBSTORE_ROOT}
      - CBLOG_ROOT=${TB_CBLOG_ROOT}
      - SPIDER_CALL_METHOD=${TB_SPIDER_CALL_METHOD}
      - SPIDER_REST_URL=${TB_SPIDER_REST_URL}
      # - DRAGONFLY_CALL_METHOD=${TB_RAGONFLY_CALL_METHOD}
      # - DRAGONFLY_REST_URL=${TB_DRAGONFLY_REST_URL}
      - DB_URL=${TB_DB_URL}
      - DB_DATABASE=${TB_DB_DATABASE}
      - DB_USER=${TB_DB_USER}
      - DB_PASSWORD=${TB_DB_PASSWORD}
      - ALLOW_ORIGINS=${TB_ALLOW_ORIGINS}
      - ENABLE_AUTH=${TB_ENABLE_AUTH}
      - API_USERNAME=${TB_API_USERNAME}
      - API_PASSWORD=${TB_API_PASSWORD}
      - AUTOCONTROL_DURATION_MS=${TB_AUTOCONTROL_DURATION_MS}
      - SELF_ENDPOINT=${TB_SELF_ENDPOINT}
      - API_DOC_PATH=${TB_API_DOC_PATH}
      - DEFAULT_NAMESPACE=${TB_DEFAULT_NAMESPACE}
      - DEFAULT_CREDENTIALHOLDER=${TB_DEFAULT_CREDENTIALHOLDER}
      - LOGFILE_PATH=${TB_LOGFILE_PATH}
      - LOGFILE_MAXSIZE=${TB_LOGFILE_MAXSIZE}
      - LOGFILE_MAXBACKUPS=${TB_LOGFILE_MAXBACKUPS}
      - LOGFILE_MAXAGE=${TB_LOGFILE_MAXAGE}
      - LOGFILE_COMPRESS=${TB_LOGFILE_COMPRESS}
      - LOGLEVEL=${TB_LOGLEVEL}
      - LOGWRITER=${TB_LOGWRITER}
      - NODE_ENV=${TB_NODE_ENV}

(.env sample)

# 'latest' indicates the most recent release tag (e.g., 0.9.0), 
# which is the stable version. `--force-recreate` option required when executing `docker-compose up` command.
TB_CONTAINER_TAG=latest 
TB_HOST_PORT_OF_REST=1323

TB_CBTUMBLEBUG_ROOT=/app
TB_CBSTORE_ROOT=/app \
TB_CBLOG_ROOT=/app \
TB_SPIDER_CALL_METHOD=REST
TB_SPIDER_REST_URL=http://cb-spider:1025/spider
# TB_RAGONFLY_CALL_METHOD=REST
# TB_DRAGONFLY_REST_URL=http://cb-dragonfly:9090/dragonfly
TB_DB_URL=localhost:3306 
TB_DB_DATABASE=cb_tumblebug 
TB_DB_USER=cb_tumblebug 
TB_DB_PASSWORD=cb_tumblebug 
TB_ALLOW_ORIGINS=*
TB_ENABLE_AUTH=true
TB_API_USERNAME=default
TB_API_PASSWORD=default
TB_AUTOCONTROL_DURATION_MS=10000
TB_SELF_ENDPOINT=localhost:1323
TB_API_DOC_PATH=/app/src/api/rest/docs/swagger.json
TB_DEFAULT_NAMESPACE=ns01
TB_DEFAULT_CREDENTIALHOLDER=admin
TB_LOGFILE_PATH=/app/log/tumblebug.log
TB_LOGFILE_MAXSIZE=10
TB_LOGFILE_MAXBACKUPS=3
TB_LOGFILE_MAXAGE=30
TB_LOGFILE_COMPRESS=false
TB_LOGLEVEL=debug
TB_LOGWRITER=both
TB_NODE_ENV=development

Copy link
Member Author

@yunkon-kim yunkon-kim Jul 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seokho-son

#1661 의 제안 취지에 부합하기 위해서,
이 부분에 대해서는 시간을 가지고 정리하는 편이 좋을 것 같습니다.

그래서, 이번 PR에서는 환경변수 관련 사항을 제외한 부분에 대해서 보완하고, 별도의 사안(PR)으로 환경변수 관련 사항을 다루고자 합니다.

관련하여 검토 및 의견을 부탁드립니다.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yunkon-kim 넵 동의합니다. 현재도 대부분의 기능을 갖추고 있으니, PR 대략 정리되시면 알려주세요! :)

container_name: cb-spider
platform: linux/amd64
ports:
- "1024:1024"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- "1024:1024"
- "${SP_HOST_PORT}:1024"

컨테이너 컴포넌트의 호스트 포트를 환경변수로 제공하면 좋을 것 같습니다.

- "2048:2048"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- "2048:2048"

grpc 관련된 사항이라서 이제 필요없는 것 같습니다.

volumes:
# - ./conf/log_conf.yaml:/root/go/src/github.com/cloud-barista/cb-spider/conf/log_conf.yaml
- ./conf/store_conf.yaml:/root/go/src/github.com/cloud-barista/cb-spider/conf/store_conf.yaml
- ./container-volume/cb-spider-container/meta_db/:/root/go/src/github.com/cloud-barista/cb-spider/meta_db/
- ./container-volume/cb-spider-container/log/:/root/go/src/github.com/cloud-barista/cb-spider/log/
environment:
- PLUGIN_SW=OFF
# - SERVER_ADDRESS=localhost
# if you leave these values empty, REST Auth will be disabled.
- API_USERNAME=
- API_PASSWORD=
- SPIDER_LOG_LEVEL=error
- SPIDER_HISCALL_LOG_LEVEL=error
- ID_TRANSFORM_MODE=ON
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

마찬가지로 SP_XXX 형태로 외부 환경변수로 주입하면 좋지 않을까 싶습니다.

healthcheck: # for CB-Spider
test: [ "CMD", "curl", "-f", "http://localhost:1323/tumblebug/readyz" ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
test: [ "CMD", "curl", "-f", "http://localhost:1323/tumblebug/readyz" ]
test: [ "CMD", "curl", "-f", "http://localhost:1323/tumblebug/readyz" ]

spider readyz 체크여야 할까요?

interval: 5s
timeout: 1s
retries: 3
start_period: 5s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
interval: 5s
timeout: 1s
retries: 3
start_period: 5s
interval: 60s
timeout: 5s
retries: 3
start_period: 10s

healthcheck를 빈번하게 확인할 필요는 없을 것 같아서, 여유있게 조정해보았습니다.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seokho-son
10초 뒤 수행(start_period: 10s)하는 첫 healthcheck을 실패하면, 1분(interval: 60s)을 기다려야 하는 상황에 놓입니다. 괜찮을지 확인 부탁드립니다.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yunkon-kim 음.. 넵. 일단 현재는 health check 결과에 따라서 특별히 수행하는 액션을 없으니, 크게 문제 없을 것 같습니다.

CB-TB에서 SP health check 결과에 따라, 시스템을 종료시키는 로직이 있으니, TB에서 제어하게 된다고 봐도 될 것 같습니다.

Copy link
Member Author

@yunkon-kim yunkon-kim Jul 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

말씀하신 것 처럼 큰 이슈는 없을 것 같습니다. 제안 주신대로 적용해 놓도록 하겠습니다.
다만 이슈가 없음에도 불구하고, docker-compose 로 전체를 구동하는 것이 지연될 수 있습니다. 이점 참고 바랍니다.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yunkon-kim 넵. 실제 활용해보면서, 필요하면 조정하면 될 것 같습니다. ^^


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
profiles:
- sp

env 파일로 dockercopomse up 시에 동작하는 컴포넌트를 조정할 수 있게 하면 어떨까요?

# .env 파일
COMPOSE_PROFILES=sp,tb,map

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

COMPOSE_PROFILES=sp,map docker-compose up
이런식으로도 조작 가능

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seokho-son

profiles을 사용해본 경험이 없어서 찾아봤는데요. 목적이 살짝 다른 것으로 보입니다.
Ref: https://docs.docker.com/compose/profiles/

말씀주신 내용은 아래와 같이 구동하면 될 것 같습니다. (이후 리뷰의견들을 반영 후 마지막에 테스트해보겠습니다.)

docker compose up -d [서비스명]
docker compose up -d cb-spider

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yunkon-kim 음.. 넵!
docker compose up -d [서비스1명] [서비스2명]
로 해도 크게 다르지 않을 것 같네요. ^^

# CB-Tumblebug
cb-tumblebug:
image: cloudbaristaorg/cb-tumblebug:0.9.0
# build:
# context: .
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# build:
# context: .
build:
context: .

docker-compose up --build 했을때, 공용 컨테이너 이미지가 아니라, 현재 소스기준으로 컨테이너 구동하게 하려고 하셨던거죠?
활성화하면 매우 유용할 것 같습니다.

# dockerfile: Dockerfile
container_name: cb-tumblebug
platform: linux/amd64
ports:
- "1323:1323"
depends_on:
- cb-spider
volumes:
- ./conf/:/app/conf/
- ./container-volume/cb-tumblebug-container/meta_db/:/app/meta_db/
- ./container-volume/cb-tumblebug-container/log/:/app/log/
environment:
- SPIDER_CALL_METHOD=REST
- SPIDER_REST_URL=http://cb-spider:1024/spider
# - DRAGONFLY_CALL_METHOD=REST
# - DRAGONFLY_REST_URL=http://cb-dragonfly:9090/dragonfly
- DB_URL=localhost:3306
- DB_DATABASE=cb_tumblebug
- DB_USER=cb_tumblebug
- DB_PASSWORD=cb_tumblebug
- ALLOW_ORIGINS=*
- ENABLE_AUTH=true
- API_USERNAME=default
- API_PASSWORD=default
- AUTOCONTROL_DURATION_MS=10000
- SELF_ENDPOINT=localhost:1323
- API_DOC_PATH=/app/src/api/rest/docs/swagger.json
- DEFAULT_NAMESPACE=ns01
- DEFAULT_CREDENTIALHOLDER=admin
- LOGFILE_PATH=$CBTUMBLEBUG_ROOT/log/tumblebug.log
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- LOGFILE_PATH=$CBTUMBLEBUG_ROOT/log/tumblebug.log
- LOGFILE_PATH=$CBTUMBLEBUG_ROOT/log/tumblebug.log

$CBTUMBLEBUG_ROOT 는 의도하신 사항일까요?

- LOGFILE_MAXSIZE=10
- LOGFILE_MAXBACKUPS=3
- LOGFILE_MAXAGE=30
- LOGFILE_COMPRESS=false
- LOGLEVEL=debug
- LOGWRITER=both
- NODE_ENV=development
healthcheck: # for CB-Tumblebug
test: [ "CMD", "curl", "-f", "http://localhost:1323/tumblebug/readyz" ]
interval: 5s
timeout: 1s
retries: 3
start_period: 5s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
interval: 5s
timeout: 1s
retries: 3
start_period: 5s
interval: 60s
timeout: 5s
retries: 3
start_period: 10s


# cb-mapui
cb-mapui:
image: cloudbaristaorg/cb-mapui:0.9.0
container_name: cb-mapui
ports:
- "1324:1324"
depends_on:
- cb-tumblebug
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
depends_on:
- cb-tumblebug

의존성 없이 동작 가능하므로, 의존성을 제외해도 좋을 것 같습니다.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seokho-son

의존성 없이 동작 될 수 있는 서비스가 맞습니다. 다만, docker-compose로 일괄 구동하는 것을 가정했을 때, Tumblebug이 떠 있지 않다면 정상적으로 구동되지 않을 것이라는 생각에 의존성 체크를 추가하였습니다.

혹시, docker compse up -d cb-mapui 처럼 개별 구동을 고려하시는 것일까요?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yunkon-kim 개별 구동에도 영향이 없도록 하는 제안이 맞습니다. 아무튼 의존성 없이 별개로 구동 가능하니까요. ^^ 실제 TB 연동 및 활용 가능여부는 MapUI 내부 로직에서 잘 처리해주고 있습니다.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵! 해당 부분은 주석 처리해 놓겠습니다.

healthcheck: # for cb-mapui
test: ["CMD", "nc", "-vz", "localhost", "1324"]
interval: 5s
timeout: 1s
retries: 3
start_period: 5s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
interval: 5s
timeout: 1s
retries: 3
start_period: 5s
interval: 60s
timeout: 5s
retries: 3
start_period: 10s