- 1.Drone的安装配置,Hugo的安装配置请参考我的系列博客。
- 2.首先需要在我们的Hugo项目下新建一个Dockerfile文件和一个conf/default.conf文件,Dockerfile文件用于生成Docker镜像。conf/default.conf文件用于覆盖nginx的配置文件。内容如下:
conf/default.conf
server {
listen 80;
listen [::]:80;
server_name _;
#access_log /var/log/nginx/host.access.log main;
location / {
root /var/www/my_blog; #hugo生成的静态文件存放路径
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/my_blog;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
Dockerfile
# 以官方的nginx镜像为基础进行构建
FROM nginx
COPY conf/default.conf /etc/nginx/conf.d/default.conf
# 将当前dockerfile所在目录下的dist目录的内容拷贝到容器的/usr/share/nginx/html/下
COPY public /var/www/my_blog/
- 3、修改.drone.yaml文件,用于打包和部署
type: docker
kind: pipeline
name: default
clone:
skip_verify: true
steps:
- name: hugo-build
image: plugins/hugo
settings:
#hugo_version: 0.76.4
validate: true
commands:
- hugo --config config.toml
#确认编译结果,之前版本没有把主题文件加入git,所以发布到nginx时没有index.html文件,
#站点启动后一直进入nginx的欢迎界面!!!!!
- ls -al ./public
- echo hugo build finished
- name: docker-build
image: plugins/docker
pull: if-not-exists
settings:
registry: reg.xxx.com/my_blog
username: username
password:
from_secret: registry_password
tags:
- latest
repo: reg.xxx.com/my_blog
#mirror: https://hub-mirror.c.163.com
mirror: https://3i0kfkai.mirror.aliyuncs.com
dockerfile: Dockerfile
- name: deploy
image: appleboy/drone-ssh
settings:
host: www.xxx.com
username: username
password:
from_secret: ssh_password
port: 22
script:
- echo deploy to server...
#这里为了方便说明,直接写用户和密码,应该放到secret里面
- docker login --username=xxx --password=xxx reg.xxx.com
- docker pull reg.xxx.com/my_blog:latest
- docker rm -f my_blog || true #先删除
- docker run --name=my_blog --restart=always -p 80:80 -d reg.xxx.com/my_blog:latest
评论区