Skip to content

Instantly share code, notes, and snippets.

@FlatMapIO
Last active March 25, 2018 10:31
Show Gist options
  • Save FlatMapIO/d22f338c623b6c0dfc6f33f82b5d22f7 to your computer and use it in GitHub Desktop.
Save FlatMapIO/d22f338c623b6c0dfc6f33f82b5d22f7 to your computer and use it in GitHub Desktop.
discourse up and running

Startup discourse

部署 Docker 镜像

按下面的指示完成基本设定

https://github.com/discourse/discourse/blob/master/docs/INSTALL-cloud.md#access-your-cloud-server

使用 daocloude 拉取最新的镜像版本. ( 官方仓库别指望能用了 )

dao pull discourse/discourse:1.3.0

编辑生成的 container/app.yml

使用 postgres.9.5 的模板代替默认 9.3 的模板

templates:
  - "templates/postgres.9.5.template.yml"
  - "templates/redis.template.yml"              
  - "templates/web.template.yml"
  - "templates/web.ratelimited.template.yml"

修改 templates/web.template.yml, 操 GFW 和方校长菊花一亿次

 - exec:
     cd: $home
     hook: web
     cmd:
       # ensure we are on latest bundler
       # 增加
       - gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/
       - gem update bundler
       - chown -R discourse $home
 - exec:
     cd: $home
     hook: bundle_exec
     cmd:
       # 增加
       - su discourse -c 'bundle config mirror.https://rubygems.org https://ruby.taobao.org'             
       - su discourse -c 'bundle install --deployment --verbose --without test --without development'
       - su discourse -c 'bundle exec rake db:migrate'
       - su discourse -c 'bundle exec rake assets:precompile'

开始构建镜像

./launcher rebuild app

构建完后会自动启动, 记录最后日志行启动参数, 大概是这样


docker run -d --restart=always \
--name app -t \
-p 32768:80 \
-p 32443:443 \
-p 2222:22 \
-v /var/discourse/shared/standalone:/shared \
-v /var/discourse/shared/standalone/log/var-log:/var/log \
-e LANG=en_US.UTF-8  \
-e RAILS_ENV=production  \
-e UNICORN_WORKERS=2  \
-e UNICORN_SIDEKIQS=1  \
-e RUBY_GC_MALLOC_LIMIT=40000000  \
-e RUBY_GC_HEAP_INIT_SLOTS=800000  \
-e DISCOURSE_DB_SOCKET=/var/run/postgresql  \
-e DISCOURSE_DB_HOST=  \
-e DISCOURSE_DB_PORT=  \
-e DISCOURSE_HOSTNAME=discourse.xx.com  \
-e DISCOURSE_DEVELOPER_EMAILS=xx@xx.com  \
-e DISCOURSE_SMTP_ADDRESS=stmp.qq.com  \
-e DISCOURSE_SMTP_PORT=587  \
-e DISCOURSE_SMTP_USER_NAME=xx@xx.com  \
-e DISCOURSE_SMTP_PASSWORD=password \
-h 10-13-63-112-app  \
-e DOCKER_HOST_IP=172.17.42.1 \
--mac-address 02:1e:52:91:8d:0e \
local_discourse/app /sbin/boot 

如果需要修改参数, 可以删掉刚才启动的容器, 修改参数新启一个. 注意配置好管理员邮箱和 stmp 信息

创建管理员账号

docker ps # 记录容器 ID
docker exec  -it <id> /bin/bash # 进入容器
rake admin:creat # 创建管理员, 与启动容器时邮件配置一样的账号密码
rake apikey:get # 生成 API KEY 用于 RSTFul API 形式与 discourse 交互, 在 WEB 端管理界面也可以直接生成 APIKEY

在 Vagrant VM 中测试开发版

  1. vagrant up
  2. 生成管理员账号 rake admin:create
  3. 登陆前端, 查看用户名, 创建 api_key, 之后的靠这两个信息调用 REST APIs.
  4. 参考 API 进行交互, https://meta.discourse.org/t/discourse-api-documentation/22706
  5. 配置语言 http://blog.discourse.org/2013/03/localizing-discourse/
  6. 本地化. 进入 /admin, 搜索 default_locations,
  7. 注意 /admin 右侧的警告. 解决这些问题.
  8. 部署 docker 容器

引用

@FlatMapIO
Copy link
Author

FlatMapIO commented May 18, 2016

使用 API_KEY 访问信息

curl 'http://discourse.domain.com/users/master.json?api_key=d40e77c710c95cfd1f7e5e53658a8e6ce937e05dfad654f5e88c1aaa34ba6a3d&api_username=master'  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment