跳至主要內容

"使用GitHub+VPS做图床"

post杂记大约 2 分钟

"使用GitHub+VPS做图床"

早期我是使用七牛做图床的,使用其实还是比较ok的,但是随着chrome的升级发现之前的图片加载不出来了。原因是出现ERR_SSL_VERSION_OR_CIPHER_MISMATCH。但是七牛的图床默认是http的,如果使用https是需要收费的。

我分析了一下我的现状:

  • 大量使用GitHub
  • 有自己的vps
  • 博客图片公开,不需要私密
  • 图片不能丢,最好数据可以自己维护

基于这几个原因,我采样了使用GitHub做图床。突然通过Picgo上传到GitHub的特定仓库上,并且给Picgo安装了rename插件: https://github.com/liuwave/picgo-plugin-super-prefix#readmeopen in new window 这个插件还是功能比较足够的,我的配置为:img/{y}/{m}/{timestamp}-{hash}-{origin}

这样我就可以通过picgo来自动的将剪贴板中的图片上传到GitHub上。然后我又自己为GitHub的这个图床仓库设置了workflow。这样当有图片文件 被push到这个仓库的时候,workflow流程会自动的将图片文件夹通过rsync命令同步到vps的指定目录下。

下面贴一下我的workflow的文件:

# This is a basic workflow to help you get started with Actions

name: sync to vps workflow

# Controls when the action will run. Triggers the workflow on push events
# but only for the master branch
on:
  push:
    branches:
      - main

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2
        with:
          submodules: 'recursive'

      # Use ssh-agent to cache ssh keys
      - uses: webfactory/ssh-agent@v0.2.0
        with:
          ssh-private-key: |
            ${{ secrets.BLOG_DEPLOY_KEY }}
      - name: Scan public keys
        run: |
          ssh-keyscan 域名 >> ~/.ssh/known_hosts
      - name: sync imgs
        run: |
          rsync -av --delete img 用户名@域名:VPS路径

版权申明

本站点所有内容,版权均归https://wenchao.renopen in new window所有,除非明确授权,否则禁止一切形式的转载协议

打赏

微信 支付宝

上次编辑于:
打赏
给作者赏一杯咖啡吧
您的支持将是我继续更新下去的动力
微信微信
支付宝支付宝