Mirror site is read only www.netnr.com
netnr 2020-08-18 10:34:31 2021-11-11 17:44:25 👁543 💬1

安装

yarn global add heroku  # yarn 方式
npm install -g heroku   # npm 方式

更多:https://devcenter.heroku.com/articles/heroku-cli

登录

heroku login        # 生成链接 WEB 登录
heroku login -i     # 命令行输入账号密码登录

创建

创建应用 {AppName} , 克隆代码仓库 git clone https://git.heroku.com/{AppName}.git

部署(一)

附加包到应用:heroku buildpacks:set jincod/dotnetcore -a {AppName}
或界面添加链接:https://github.com/jincod/dotnetcore-buildpack

注意安装的版本与发布的版本相同或兼容

如果有多个站点,配置环境变量指定发布哪个项目

PROJECT_FILE    Netnr.Blog.Web
PROJECT_NAME    Netnr.Blog.Web

部署(二)

根目录创建 Procfile 文件写入以下命令,文档:https://devcenter.heroku.com/articles/procfile
发布带运行时的包(推荐)

web: cd $HOME/dist && chmod +x {AppName} && ./{AppName} --urls http://+:$PORT

发布依赖环境的包(不推荐:因为休眠后每次唤醒都会执行这些命令)
先利用 curl 在线安装 dotnet (建议参数指定固定版本)

web: curl -s -L https://dot.net/v1/dotnet-install.sh | bash /dev/stdin -c Current && cd $HOME/dist && ~/.dotnet/dotnet {AppName}.dll --urls http://+:$PORT

$HOME/dist 目录可以自己改,heroku 默认 60s 端口(环境变量 $PORT)无服务就会超时

目前 heroku 只监听端口 http 协议,如果支持 https ,那么可以这样

web: export ASPNETCORE_URLS="https://+:$PORT" && curl -s -L https://dot.net/v1/dotnet-install.sh | bash /dev/stdin -c Current && ~/.dotnet/dotnet dev-certs https --clean && ~/.dotnet/dotnet dev-certs https --trust && cd $HOME/dist && chmod +x {AppName} && ./{AppName}

依赖

安装 GDI ,图形验证码需要
添加包链接:https://github.com/heroku/heroku-buildpack-apt
然后根目录添加 Aptfile 文件,写入 libgdiplus

echo 'libgdiplus' > Aptfile

第二种部署,由于 heroku 默认不支持 dotnet 环境,所以需要添加自定义构建包,推荐安装此包

推送

git add . && git commit -m 'm' && git push origin master

更多命令

heroku --help # 命令帮助
heroku logs --tail # 查看日志
heroku run bash # 进入容器终端

免费额度

  • 550 小时 / 月
  • 信用卡验证后,额外赠送 450 小时 / 月,即 共 1000 小时 / 月
  • 查看使用额度:heroku ps -a {AppName}
  • 用完当月额度后所有免费应用强制进入睡眠
第 1 页1 个回复
头像
2020-09-27 11:29:45 #1
Block


链接