首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >免费静态托管 | 笔记

免费静态托管 | 笔记

作者头像
yiyun
发布2022-04-01 13:06:39
发布2022-04-01 13:06:39
5.9K00
代码可运行
举报
文章被收录于专栏:yiyun 的专栏yiyun 的专栏
运行总次数:0
代码可运行

引言

1. GitHub Pages

https://pages.github.com/

2. Vercel

https://vercel.com

这里 只能输入 公开的仓库地址

下面在 GitHub 私有仓库,利用 GitHub App 来安装 Vercel, 更新: 错误,GitHub Marketplace 没有 Vercel App, 通过下方来导入私有仓库

目测只能创建完后,修改分支

更新: 可以通过修改下方链接来创建 Project, 这样创建时就能自定义分支

代码语言:javascript
代码运行次数:0
运行
复制
https://vercel.com/new/clone?repository-url=https://github.com/yiyungent/yiyungent.github.io/tree/gh-pages

修改 branch 为 gh-pages

由于直接使用 gh-pages 构建好的结果,因此下方直接置空

image-20220215155438117

现在流程,本地改完后,push 到 GitHub主分支 ( master ),然后触发 GitHub Actions 构建完成到 gh-pages, 然后这会触发两次 Vercel 的 Deployment , 第一次 来自 master, 第二次来自 GitHub Actions 推送到的 gh-pages, 第一次是不正确的,会导致 404, 第二次即可正常访问

image-20220215160910827

完成

image-20220215161636563

https://yiyungent.vercel.app/ https://yiyungent-yiyungent.vercel.app/ https://yiyungent-git-gh-pages-yiyungent.vercel.app/

3. Cloudflare Pages

https://pages.cloudflare.com/

image-20220215145113403

image-20220215145200413

image-20220215145221104

image-20220215145321101

image-20220215145333395

image-20220215145455877

image-20220215145622001

image-20220215145633939

image-20220215145650275

完成

image-20220215150838791

image-20220215150923479

https://yiyungent.pages.dev/

4. Netlify

https://www.netlify.com/

image-20220215151811507

image-20220215151830720

image-20220215152034895

image-20220215152114236

image-20220215152126782

image-20220215152148349

image-20220215152257325

image-20220215152323745

image-20220215152336079

完成

image-20220215152431277

https://yiyungent.netlify.app

Q&A

补充

类似免费

参考:

railway

  • 支持 Docker
自制 Railway Button

https://railway.app/button

heroku

  • 支持 Docker
自制 Heroku 模板

参考:

代码语言:javascript
代码运行次数:0
运行
复制
build:
  docker:
    web: docker/Dockerfile
代码语言:javascript
代码运行次数:0
运行
复制
{
  "name": "PanIndex",
  "description": "简易的网盘目录列表",
  "keywords": [
    "PanIndex", "cloud.189.cn", "teambition"
  ],
  "env": {
    "TZ": {
      "description": "时区",
      "value": "Asia/Shanghai"
    },
    "LANG": {
      "description": "编码格式",
      "value": "en_US.UTF-8"
    },
    "PAN_INDEX_VERSION": {
      "description": "PanIndex版本,默认为最新版,查看:https://github.com/libsgh/PanIndex/releases",
      "required": false,
      "value": ""
    },
    "PAN_INDEX_CONFIG": {
      "description": "程序配置,json格式,从后台获取复制到这里",
      "required": false,
      "value": ""
    },
    "PAN_INDEX_DEBUG": {
      "description": "调试模式,设置为true将输出更多日志",
      "value": "false"
    }
  },
  "website": "http://github.com/libsgh/PanIndex",
  "repository": "http://github.com/libsgh/PanIndex",
  "stack": "container",
  "features": [
    "runtime-dyno-metadata"
  ]
}

最后生成效果:

代码语言:javascript
代码运行次数:0
运行
复制
https://heroku.com/deploy?template=https://github.com/libsgh/PanIndex

koyeb

https://www.koyeb.com/

fly.io

https://fly.io/

  • 支持 Docker

Render

https://render.com/

  • 支持 Docker

部署 ASP.NET Core 到 Railway

参考:

Railway Docker 配置

若以仓库根目录为模板, 则 Dockerfile 必须位于仓库根目录

仓库根目录/Dockerfile

代码语言:javascript
代码运行次数:0
运行
复制
# Railway  Dockerfile

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
# ...
# for Railway
WORKDIR /app
ADD railway-entrypoint.sh ./railway-entrypoint.sh
RUN chmod +x ./railway-entrypoint.sh

# ...

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
#ENTRYPOINT ["dotnet", "WebScreenshot.dll"]
ENTRYPOINT ["/bin/sh", "./railway-entrypoint.sh"]

仓库根目录/railway-entrypoint.sh

代码语言:javascript
代码运行次数:0
运行
复制
#!/bin/sh

# 注意: $PORT 非常重要, Railway 必须监听此端口
export ASPNETCORE_URLS="http://+:$PORT"
export ASPNETCORE_ENVIRONMENT="Production"
export TZ="Asia/Shanghai"

dotnet WebScreenshot.dll

部署 ASP.NET Core 到 Heroku

参考:

Heroku 基础配置

仓库根目录/app.json

代码语言:javascript
代码运行次数:0
运行
复制
{
  "name": "Squidex",
  "description": "Headless CMS and Content Managment Hub",
  "website": "https://squidex.io/",
  "repository": "https://github.com/Squidex/squidex",
  "logo": "https://avatars.githubusercontent.com/u/25371797?s=200&v=4",
  "success_url": "/",
  "env": {
    "DOMAIN": {
      "description": "The domain name under which your instance is available",
      "value": "https://[YOUR-HEROKU-APPNAME].herokuapp.com"
    },
    "MONGO_USERNAME": {
      "description": "Mongo Username, follow https://devcenter.heroku.com/articles/ormongo#open-the-dashboard to create a database named Squidex and then edit the deployment to reflect the credentials you used",
      "value": "Squidex"
    },
    "MONGO_PASSWORD": {
      "description": "Mongo Password (see MONGO_USERNAME)",
      "value": "Squidex123"
    }
  },
  "formation": {
    "web": {
      "quantity": 1,
      "size": "standard-1x"
    }
  },
  "addons": [
    {
      "plan": "ormongo:2-mmap",
      "as": "MONGO"
    }
  ],
  "stack": "container"
}

仓库根目录/heroku.yml

代码语言:javascript
代码运行次数:0
运行
复制
build:
  docker:
    web: packer/heroku/squidex/Dockerfile

PS: heroku.yml: If you don’t include a run section, Heroku uses the CMD specified in the Dockerfile.

Heroku Docker 配置

需要注意 2 点: - Heroku Docker 容器内部应用需要监听 $PORT 端口 - Heroku 对 ENTRYPOINT [ "dotnet", "HerokuApp.dll" ] 支持不好, 建议 CMD [ "dotnet", "HerokuApp.dll" ], 或则在 ENTRYPOINT 运行 bash

方式1
代码语言:javascript
代码运行次数:0
运行
复制
# Heroku Dockerfile

# ENTRYPOINT [ "dotnet", "HerokuApp.dll" ]
# Use the following instead for Heroku
CMD ASPNETCORE_URLS=http://*:$PORT dotnet HerokuApp.dll
方式2

在程序中写死监听端口

代码语言:javascript
代码运行次数:0
运行
复制
public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();

                // For running in Railway
                var portVar = Environment.GetEnvironmentVariable("PORT");
                if (portVar is {Length: >0} && int.TryParse(portVar, out int port))
                {
                    webBuilder.ConfigureKestrel(options =>
                    {
                        options.ListenAnyIP(port);
                    });
                }
            });
代码语言:javascript
代码运行次数:0
运行
复制
# Heroku Dockerfile

CMD [ "dotnet", "HerokuApp.dll" ]
方式3

heroku.yml

代码语言:javascript
代码运行次数:0
运行
复制
build:
  docker:
    web: deploy/heroku/Dockerfile

deploy/heroku/Dockerfile

代码语言:javascript
代码运行次数:0
运行
复制
# Heroku Dockerfile

FROM yiyungent/webscreenshot:latest

ADD heroku-entrypoint.sh /heroku-entrypoint.sh

RUN chmod +x /heroku-entrypoint.sh

ENTRYPOINT ["/bin/sh", "/heroku-entrypoint.sh"]

deploy/heroku/heroku-entrypoint.sh

代码语言:javascript
代码运行次数:0
运行
复制
#!/bin/sh

export ASPNETCORE_URLS="http://+:$PORT"

dotnet WebScreenshot.dll
方式4

heroku.yml

注意: 此种方法, Docker build context 位于 src/WebApi/, 而不是 仓库根目录

代码语言:javascript
代码运行次数:0
运行
复制
build:
  docker:
    web: src/WebApi/Dockerfile
run:
  web: cd /app && dotnet WebApi.dll --urls="http://*:$PORT"

部署 ASP.NET Core 到 Render

参考:

部署 ASP.NET Core 到 fly.io

参考:

fly.io 与其它不一样,没有 Web 可视化面板,只能用 CLI 来创建 App

1. 安装 fly.io

Windows: PowerShell

代码语言:javascript
代码运行次数:0
运行
复制
iwr https://fly.io/install.ps1 -useb | iex

2. 登录 到 fly.io

代码语言:javascript
代码运行次数:0
运行
复制
flyctl auth login

3. 开始

参考:

代码语言:javascript
代码运行次数:0
运行
复制
flyctl info
代码语言:javascript
代码运行次数:0
运行
复制
flyctl status
flyctl logs

4. Deploy Your Application via Dockerfile

参考:

Dockerfile 目录执行

代码语言:javascript
代码运行次数:0
运行
复制
fly launch

部署 ASP.NET Core 实例

Railway

注意: 这里 Railway 的 Dockerfile 没有放在仓库根目录,因此 template 需指定为子目录 https://github.com/yiyungent/Dragonfly/tree/main/deploy/railway

Dockerfile

代码语言:javascript
代码运行次数:0
运行
复制
# Railway Dockerfile

# 注意: yiyungent/dragonfly:latest railway 会一直使用缓存,不会更新镜像
FROM yiyungent/dragonfly:v0.1.1

ADD railway-entrypoint.sh ./railway-entrypoint.sh
RUN chmod +x ./railway-entrypoint.sh
ADD railway-PluginCore.Config.json ./railway-PluginCore.Config.json

ENTRYPOINT ["/bin/sh", "./railway-entrypoint.sh"]

railway-entrypoint.sh

代码语言:javascript
代码运行次数:0
运行
复制
#!/bin/sh

# region env
export ASPNETCORE_URLS="http://+:$PORT"
export ASPNETCORE_ENVIRONMENT="Production"
export TZ="Asia/Shanghai"
# endregion env

# region PluginCore
echo ${PLUGINCORE_ADMIN_USERNAME}
echo ${PLUGINCORE_ADMIN_PASSWORD}

mkdir App_Data

touch /app/App_Data/PluginCore.Config.json

cat '/app/railway-PluginCore.Config.json' | sed "s/PLUGINCORE_ADMIN_USERNAME/${PLUGINCORE_ADMIN_USERNAME}/g" | tee '/app/App_Data/PluginCore.Config.json'
cat '/app/App_Data/PluginCore.Config.json' | sed "s/PLUGINCORE_ADMIN_PASSWORD/${PLUGINCORE_ADMIN_PASSWORD}/g" | tee '/app/App_Data/PluginCore.Config.json'
# endregion PluginCore

dotnet WebApi.dll

railway-PluginCore.Config.json

代码语言:javascript
代码运行次数:0
运行
复制
{"Admin":{"UserName":"PLUGINCORE_ADMIN_USERNAME","Password":"PLUGINCORE_ADMIN_PASSWORD"},"FrontendMode":"LocalEmbedded","RemoteFrontend":"https://cdn.jsdelivr.net/gh/yiyungent/plugincore-admin-frontend@0.3.0/dist-cdn","PluginWidgetDebug":false}

Heroku

Dockerfile

代码语言:javascript
代码运行次数:0
运行
复制
# Heroku Dockerfile

FROM yiyungent/dragonfly:v0.1.1

ADD heroku-entrypoint.sh ./heroku-entrypoint.sh
RUN chmod +x ./heroku-entrypoint.sh
ADD heroku-PluginCore.Config.json ./heroku-PluginCore.Config.json

ENTRYPOINT ["/bin/sh", "./heroku-entrypoint.sh"]

heroku-entrypoint.sh

代码语言:javascript
代码运行次数:0
运行
复制
#!/bin/sh

# region env
export ASPNETCORE_URLS="http://+:$PORT"
export ASPNETCORE_ENVIRONMENT="Production"
export TZ="Asia/Shanghai"
# endregion env

# region PluginCore
echo ${PLUGINCORE_ADMIN_USERNAME}
echo ${PLUGINCORE_ADMIN_PASSWORD}

mkdir App_Data

touch /app/App_Data/PluginCore.Config.json

cat '/app/heroku-PluginCore.Config.json' | sed "s/PLUGINCORE_ADMIN_USERNAME/${PLUGINCORE_ADMIN_USERNAME}/g" | tee '/app/App_Data/PluginCore.Config.json'
cat '/app/App_Data/PluginCore.Config.json' | sed "s/PLUGINCORE_ADMIN_PASSWORD/${PLUGINCORE_ADMIN_PASSWORD}/g" | tee '/app/App_Data/PluginCore.Config.json'
# endregion PluginCore

dotnet WebApi.dll

heroku-PluginCore.Config.json

代码语言:javascript
代码运行次数:0
运行
复制
{"Admin":{"UserName":"PLUGINCORE_ADMIN_USERNAME","Password":"PLUGINCORE_ADMIN_PASSWORD"},"FrontendMode":"LocalEmbedded","RemoteFrontend":"https://cdn.jsdelivr.net/gh/yiyungent/plugincore-admin-frontend@0.3.0/dist-cdn","PluginWidgetDebug":false}

app.json

代码语言:javascript
代码运行次数:0
运行
复制
{
  "name": "Dragonfly",
  "description": "Web 自动化平台 - Heroku Deploy",
  "keywords": ["yiyungent", "Dragonfly"],
  "website": "https://github.com/yiyungent/Dragonfly",
  "repository": "https://github.com/yiyungent/Dragonfly",
  "success_url": "/",
  "env": {
    "PLUGINCORE_ADMIN_USERNAME": {
      "description": "PluginCore Admin 用户名",
      "value": "admin",
      "required": true
    },
    "PLUGINCORE_ADMIN_PASSWORD": {
      "description": "PluginCore Admin 密码",
      "value": "Dragonfly",
      "required": true
    }
  },

  "stack": "container"
}

heroku.yml

代码语言:javascript
代码运行次数:0
运行
复制
build:
  docker:
    web: deploy/heroku/Dockerfile
  • 本文作者: yiyun
  • 本文链接: https://moeci.com/posts/分类-Web/免费静态托管-notebook/
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-02-15,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 引言
  • 1. GitHub Pages
  • 2. Vercel
  • 3. Cloudflare Pages
  • 4. Netlify
  • Q&A
  • 补充
    • 类似免费
      • railway
      • heroku
      • koyeb
      • fly.io
      • Render
    • 部署 ASP.NET Core 到 Railway
      • Railway Docker 配置
    • 部署 ASP.NET Core 到 Heroku
      • Heroku 基础配置
      • Heroku Docker 配置
    • 部署 ASP.NET Core 到 Render
    • 部署 ASP.NET Core 到 fly.io
      • 1. 安装 fly.io
      • 2. 登录 到 fly.io
      • 3. 开始
      • 4. Deploy Your Application via Dockerfile
    • 部署 ASP.NET Core 实例
      • Railway
      • Heroku
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档