환경 변수 설정

:notebook_with_decorative_cover: 이는 자체 호스팅 Discourse 설치에서 환경 변수를 설정하는 방법(how-to)에 대한 가이드입니다.

:person_raising_hand: 필요한 사용자 권한: 관리자

환경 변수는 Discourse 인스턴스를 구성하는 데 중요한 역할을 합니다. API 키와 데이터베이스 비밀번호와 같은 민감한 데이터를 저장할 수 있어 설치를 더 안전하고 유연하게 만들어 줍니다. Discourse에서 환경 변수는 Docker 컨테이너 설정 내의 app.yml 파일에 설정됩니다.

.yml(YAML) 파일에 환경 변수를 추가하는 것은 간단합니다. 다음은 기본적인 예시입니다:

# This is a YAML file with environmental variables
env:
  VARIABLE_NAME: "Variable Value"
  ANOTHER_VARIABLE: "Another Value"

Discourse Docker 컨테이너의 맥락에서 환경 변수는 app.yml 파일의 env 섹션에 저장됩니다.

다음은 app.yml 파일의 예시입니다:
## this is the all-in-one, standalone Discourse Docker container template
##
## After making changes to this file, you must rebuild
## /var/discourse/launcher rebuild app
##
templates:
  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/web.template.yml"
  - "templates/web.ratelimited.template.yml"
## Uncomment these two lines if you wish to add Lets Encrypt (https)
  #- "templates/web.ssl.template.yml"
  #- "templates/web.letsencrypt.ssl.template.yml"

## which TCP/IP ports should this container expose?
## If you want Discourse to share a port with another webserver like Apache or nginx,
## see https://meta.discourse.org/t/17247 for details
expose:
  - "80:80"   # http
  - "443:443" # https

params:
  db_default_text_search_config: "pg_catalog.english"

  ## Set db_shared_buffers to a max of 25% of the total memory.
  ## will be set automatically by bootstrap based on detected RAM, or you can override
  db_shared_buffers: "256MB"

env:
  LANG: en_US.UTF-8
  # DISCOURSE_DEFAULT_LOCALE: en

  ## How many concurrent web requests are supported? Depends on memory and CPU cores.
  ## will be set automatically by bootstrap based on detected CPUs, or you can override
  UNICORN_WORKERS: 3

  ## TODO: The domain name this Discourse instance will respond to
  DISCOURSE_HOSTNAME: 'discourse.example.com'

  ## Uncomment if you want the container to be started with the same
  ## hostname (-h option) as specified above (default "$hostname-$config")
  #DOCKER_USE_HOSTNAME: true

  ## TODO: List of comma delimited emails that will be made admin and developer
  ## on initial signup example 'user1@example.com,user2@example.com'
  DISCOURSE_DEVELOPER_EMAILS: 'user@example.com'

  ## TODO: The SMTP mail server used to validate new accounts and send notifications
  DISCOURSE_SMTP_ADDRESS: smtp.example.com         # (mandatory)
  DISCOURSE_SMTP_PORT: 587                        # (optional)
  DISCOURSE_SMTP_USER_NAME: user@example.com      # (optional)
  DISCOURSE_SMTP_PASSWORD: a_s3cr3t_p@ssword      # (optional)
  #DISCOURSE_SMTP_ENABLE_START_TLS: true           # (optional, default true)

  ## If you added the Lets Encrypt template, uncomment below to get a free SSL certificate
  #LETSENCRYPT_ACCOUNT_EMAIL: me@example.com

  ## The CDN address for this Discourse instance (configured to pull)
  #DISCOURSE_CDN_URL: //discourse-cdn.example.com

## The Docker container is stateless; all data is stored in /shared
volumes:
  - volume:
      host: /var/discourse/shared/standalone
      guest: /shared
  - volume:
      host: /var/discourse/shared/standalone/log/var-log
      guest: /var/log

## Plugins go here
## see https://meta.discourse.org/t/19157 for details
hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/discourse/docker_manager.git

## Any custom commands to run after building
run:
  - exec: echo "Beginning of custom commands"
  ## If you want to set the 'From' email address for your first registration, uncomment and change:
  #- exec: rails r "SiteSetting.notification_email='info@unconfigured.discourse.org'"
  ## After getting the first signup email, re-comment the line. It only needs to run once.
  - exec: echo "End of custom commands"

자, 이제 사이트에 환경 변수를 추가하는 작업을 시작해 봅시다! :mage:

:information_source: 다음 설명은 표준 Discourse 설치를 기준으로 작성되었습니다.

서버에 로그인하기

PuTTY와 같은 도구나 Unix 기반 시스템의 터미널을 사용하여 서버에 SSH로 접속하세요.

ssh username@your-server-ip

Discourse 디렉터리로 이동하기

서버에 접근한 후, Discourse Docker 설정이 포함된 디렉터리로 이동하세요. 이는 일반적으로 /var/discourse 위치에 있습니다.

cd /var/discourse

app.yml 파일 열기

텍스트 편집기로 app.yml 파일을 열어야 합니다. 이 예시에서는 nano를 사용합니다.

nano containers/app.yml

환경 변수 추가하기

app.yml 파일에서 env 섹션을 찾을 수 있습니다. 여기에 환경 변수를 추가할 수 있습니다.

env:
  DISCOURSE_HOSTNAME: 'discourse.example.com'
  DISCOURSE_SMTP_ADDRESS: smtp.example.com
  DISCOURSE_SMTP_PORT: 587
  DISCOURSE_SMTP_USER_NAME: user@example.com
  DISCOURSE_SMTP_PASSWORD: a_s3cr3t_p@ssword
```\n
예를 들어, [크로스 오리진 리소스 공유(CORS)](https://meta.discourse.org/t/setup-cross-origin-resource-sharing-cors/270819)를 활성화하기 위해 `DISCOURSE_ENABLE_CORS` 환경 변수를 `true`로 설정하려면, `env` 섹션에 다음 줄을 추가합니다:

env:
DISCOURSE_ENABLE_CORS: “true”
…


> :person_tipping_hand: 여기서는 공백과 포맷이 중요하므로, 새로운 줄에 대해 올바른 들여쓰기(공백 2개)를 유지하는지 확인하세요.

변수를 수정한 후 파일을 저장하고 닫으세요.

## Discourse 컨테이너 다시 빌드하기

마지막으로, 변경 사항이 적용되도록 Discourse Docker 컨테이너를 다시 빌드해야 합니다. 다음 명령을 사용하여 수행할 수 있습니다:

./launcher rebuild app


대안으로, 재빌드 없이 실행 중인 컨테이너의 환경 변수를 업데이트하려면 다음을 사용할 수도 있습니다:

./launcher destroy app
./launcher start app


재빌드 과정이 완료되면, 업데이트된 환경 변수가 Discourse 애플리케이션에서 사용할 수 있게 됩니다! :tada:
4개의 좋아요

환경 변수를 사용하여 시스템 설정이나 기본 전역 변수 파일의 전역 설정을 오버라이드하는 방법(그리고 사람들이 난해한 redis 설정 같은 설정들을 볼 수 있도록 해당 파일에 링크를 걸어두는 것)을 설명해 주었다면 훨씬 더 유용했을 것입니다.

이 예시는 discourse와 전혀 관련이 없어 혼란스럽습니다.

docker에서 유사한 명령을 사용하는 것과 같다고 언급할 수 있을 것입니다.

Setup Cross-Origin Resource Sharing (CORS) 를 만들었기 때문에 이 문서도 작성하신 것 같으므로, 해당 항목을 예시로 사용해보시는 건 어떨까요?

7개의 좋아요

Discourse에서 사용되는 모든 환경 변수를 한 곳에서 찾을 수 있는 곳이 있을까요?

그것이 app.yml의 env: 섹션에 환경 변수가 들어간다는 주제를 말하는 것보다 훨씬 더 유용했을 것입니다 :laughing:

또한, 애플리케이션이 변경된 환경 변수를 "로드"하려면 rebuild할 필요 없이 단순히 restart하면 된다고 생각합니다. 제가 틀렸다면 정정해 주십시오.

컨테이너를 삭제하고 다시 시작할 수 있습니다. 이것이 OP에 추가된 것으로 생각합니다. 유일한 문제는 UX에서 업그레이드를 수행한 경우 해당 설정이 사라진다는 점입니다.

DISCOURSE_SETTING_NAME을 사용하여 사이트 설정을 임의로 설정할 수 있습니다. config의 기본 설정도 참조하세요. discourse/config/discourse_defaults.conf at main · discourse/discourse · GitHub

4개의 좋아요

안녕하세요 @SaraDev, Discourse의 동작 방식을 어떻게 변경하는지 이 환경 변수들이 어떻게 작용하는지 알려 주실 수 있을까요? 예를 들어, 이 게시물(Available settings for global rate limits and throttling)에 언급된 모든 변수를 Discourse 소스 코드에서 찾을 수 없는데, 그렇다면 이 변수들이 Discourse에 어떻게 연결되어 작동하는 것일까요? 감사합니다!

여기서 볼 수 있다고 생각합니다:

3개의 좋아요

@Arkshine 님, 정말 감사합니다.

1개의 좋아요

Docker가 아닌 개발 환경에서 환경 변수를 설정하는 방법이 있을까요? 최종적으로는 Docker로 호스팅할 계획이지만, 현재는 다음과 같은 설정으로 로컬에서 개발 중입니다: Install Discourse on macOS for development
이 경우 app.yml 파일이 없습니다.

레일스를 시작하기 전에 명령줄에서 설정할 수 있습니다. 그런데 해당 ENV 변수로 무엇을 하려는 건가요?

SSO를 위해 DISCOURSE_ENABLE_CORS를 true로 설정하려고 합니다. 샘플 명령어를 보내주실 수 있을까요? 저는 Discourse/Rails 개발에 처음 접하는 입장이거든요. 또한 이 설정이 궁극적으로 어떤 일을 수행하는지도 궁금합니다. site_settings 테이블에 레코드를 생성하는 건가요?

Kubernetes 내에서 Discourse를 자동으로 설정하려고 합니다. 이를 위해 커스텀 Docker 이미지(DinD)를 빌드할 계획입니다.
하지만 Dockerfile에서 ./discourse-setup.sh를 실행하면 설정 옵션에 대한 입력을 요구하게 되며, Docker는 이 질문에 답할 수 없습니다(이 과정은 자동으로 이루어져야 하므로).

app.yml 파일에 해당 환경 변수를 넣을 수 있다는 점은 이해합니다. 하지만 이 시점에서는 ./discourse-setup 스크립트가 아직 실행되지 않았기 때문에 app.yaml 파일 자체가 존재하지 않습니다.

따라서 제 질문은 다음과 같습니다. ./discourse-setup이 사용자 입력을 요구하지 않도록 Discourse를 미리 설정하는 방법은 무엇일까요?

discourse/docs/INSTALL-cloud.md at main · discourse/discourse (github.com) 설치 가이드에는 사전 구성이나 설정 파일에 대한 언급이 전혀 없습니다.

미리 감사드립니다!

2개의 좋아요

다음 명령어를 시도해 보세요.

./launcher start-cmd app

이 명령어를 실행하면 컨테이너를 시작하는 데 사용된 docker 시작 명령어를 확인할 수 있습니다. 이를 참고하여 k8s에서 서비스를 어떻게 시작할지 파악할 수 있을 것입니다.

5개의 좋아요

app.yml 파일이 존재할 수 있는 다른 일반적인 위치가 있나요, 아니면 이 파일을 처음부터 새로 만들어야 하는 상황일 수도 있나요? 저는 Docker 컨테이너에 진입(docker exec -it discourse_dev /bin/bash)했지만, app.yml이라는 이름의 파일을 찾을 수 없었습니다.

app.yml 파일은 컨테이너 내부가 아니라 외부에 있어야 합니다.

2개의 좋아요