使用docker搭建hexo博客cicd环境实现自动部署, 自动更新到线上
docker 部署
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| FROM node:15.7.0-alpine3.10
WORKDIR /usr/blog
RUN chmod 777 /usr/blog
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
RUN apk add bash git openssh curl openrc
RUN curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64 RUN chmod +x /usr/local/bin/gitlab-runner RUN adduser -D -h /home/gitlab-runner -s /bin/sh gitlab RUN gitlab-runner install --user=gitlab --working-directory=/home/gitlab-runner RUN echo "#!/bin/sh" >> /start.sh RUN echo "gitlab-runner start" >> /start.sh
RUN apk add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ && echo "Asia/Shanghai" > /etc/timezone \ && apk del tzdata
RUN npm install -g npm@8.12.1
|
启动gitlab-runner
REGISTRATION_TOKEN 根据 gitlab后台的来填写
1 2 3 4 5 6 7 8 9 10 11
| #!/bin/bash docker stop hexo-gitlab-runner docker rm hexo-gitlab-runner
docker run -dit \ --name hexo-gitlab-runner \ -e REGISTRATION_TOKEN='******' \ -v /docker/hexo-build/data/www:/usr/blog \ -v /docker/hexo-build/data/config:/etc/gitlab-runner \ --privileged=true \ hexo-runner:latest
|
注册runner
1 2 3 4 5 6
| gitlab-runner register --url https://www.example.com/ --registration-token $REGISTRATION_TOKEN
Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell: shell
|
运行runner
常见问题
如果出现信息提示runner
但是网页提示没连接大概率是出现假死了
如果服务出现假死请删除/var/run
下的gitlab-runner.pid
文件