简介
主要用github action做了两个自动化部署
- github pages的自动部署
- 利用github仓库进行docker的自动build,并且定时跟新
- 利用docker镜像恢复dockerfile
github pages的自动部署
修改hexo的_config.yml
deploy:
type: git
#repo: https://github.com/chnxyzz/chnxyzz.github.io.git
repo: https://GITHUB_TOKEN@github.com/chnxyzz/chnxyzz.github.io.git
branch: master
name: chnxyzz
email: 28676240+chnxyzz@users.noreply.github.com
添加github_action
name: build and deploy
on:
push:
branches: master
jobs:
build:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{secrets.POST_TOKEN}}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
registry-url: https://registry.npmjs.org/
- name: build and deploy
run: |
npm install -g hexo-cli
npm install
sed -i "s/GITHUB_TOKEN/${{secrets.POST_TOKEN}}/g" ./_config.yml
hexo clean && hexo g && hexo d
docker自动部署
给定dockerfile,就可以自动build并且push到dockerhub上
docker官方用的
name: docker build CI
on:
push:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: build and push
uses: docker/build-push-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: xyzzpwn/hexo_dev
tags: latest
自己写的,可以用于打上时间的tag,然后不断的叠加push
name: Docker Image CI
on:
push:
branches: [ master ]
schedule:
- cron: '50 23 * * 6'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build the Docker image
run: |
sudo ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime;
sudo echo 'Asia/Shanghai' >/etc/timezone;
echo ${{ secrets.DOCKER_PASSWORD }} | docker login --username ${{ secrets.DOCKER_USERNAME }} --password-stdin
export con_name=xyzzpwn/hexo
export con_time_name=$con_name:$(date +%Y%m%d%H%M%S)
export con_relese_name=$con_name:latest
docker build . --file ./Dockerfile --tag $con_time_name
docker push $con_time_name
docker tag $con_time_name $con_relese_name
docker push $con_relese_name
有时间希望能做成一个和build-push-action一样的即插即用的github action项目
并且可以把deploy github pages 拓展到push到各个仓库
利用docker镜像恢复dockerfile
利用脚本
docker history 然后反转
#!/bin/bash
if [ $# -eq 1 ];then
docker history --format {{.CreatedBy}} --no-trunc=true $1 |sed "s/\/bin\/sh\ -c\ \#(nop)\ //g"|sed "s/\/bin\/sh\ -c/RUN/g" | tac
else
echo "sh $0 Docker_image_name"
fi
通过hash找docker镜像
docker pull ubuntu@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2
所以有需要的时候把docker中所有常用的docker image名字收集起来,通过不断的docker pull来进行尝试
还有一种方法
docker pull ubuntu --all-tags
把所有镜像下载本地,做成一个数据库,不过太耗费流量了。而且实时性不强。