github 上持续集成方案 drone 的简介及部署

通常小型公司的持续集成方案会选择: gitlab + gitlab CI,固然部分公司也会选择 jenkinsnginx

选择 gitlab CI 的缘由很简单,由于使用了 gitlab CE 做为代码托管平台。那为何选择了 gitlab 做为代码托管呢, gitlab CE 是免费版(社区版),对于昂贵的 toB 软件来讲,一家公司至少省了几十万的开销,并且支持自建平台,搭在自家的服务器中,安全性获得了保证。git

而对比 gitlab 的同一类产品,世界最大的同性社交网站 github 来讲,随着微软的收购,github 也愈来愈开放了,它不只免费开放了私有仓库,如今也能够经过 github action 来作简单的 CI。程序员

对于我的,自有开发者以及小型公司来讲,拥有免费仓库的 github 也是一个不错的选择。github

drone 是基于容器的构建服务,配置简单且免费,在 github 上也有 20K star。若是你的仓库主要都在 github,你会喜欢上它的后端

随着 github action 的发展,github + github-action 也是我的以及小型公司可选的持续集成方案,不过因为它属于公共构建服务的缘故,镜像构建以及镜像拉取速度会是一个问题,这要取舍浏览器

本篇文章单单介绍 drone.ci 的部署安全

环境

kubernetes 集群,并使用 helm 部署。若是不具有这两个条件能够参考我之前的文章bash

部署

为了更好地真实环境效果,在命令演示过程当中我会使用我真实的域名: drone.xiange.tech,你须要替换成你本身的域名服务器

部署时采用 helm 的官方 chart: stable/droneapp

当咱们选择结合 github 作CI,此时须要两个参数

  1. github oauth2 client-secret
  2. github oauth2 client-id
# 根据 github oauth2 的 client-secret 建立一个 secret
# generic: 指从文件或者字符串中建立
# --form-literal: 根据键值对字符串建立
$ kubectl create secret generic drone-server-secrets --from-literal=clientSecret="${github-oauth2-client-secret}"

# 使用 helm v3 部署 stable/drone
$ helm install drone stable/drone
复制代码

此时部署会提示部署失败,咱们还须要一些必要的参数: Ingress 以及 github oauth2

咱们使用 Ingress 配置域名 drone.xiange.tech,并开启 https,关于如何使用 Ingress 并自动开启 https,能够参考我之前的文章:

  1. 经过外部域名访问你的应用: Ingress
  2. 自动为你的域名添加 https

同时你也须要配置好默认 pv/pvc,能够参考我之前的文章

  1. k8s 中的永久存储: PersistentVolume

配置相关的参数,存储为 drone-values.yaml,其中 drone.xiange.tech 是在 github 上为 drone 设置的回调域名

ingress:
  ## If true, Drone Ingress will be created.
  ##
 enabled: true

  ## Drone Ingress annotations
  ##
 annotations:
    kubernetes.io/ingress.class: nginx
    kubernetes.io/tls-acme: 'true'

  ## Drone hostnames must be provided if Ingress is enabled
  ##
 hosts:
 - drone.xiange.tech

  ## Drone Ingress TLS configuration secrets
  ## Must be manually created in the namespace
  ##
 tls:
 - secretName: drone-tls
 hosts:
 - drone.xiange.tech

server:
  ## If not set, it will be autofilled with the cluster host.
  ## Host shoud be just the hostname.
  ##
 host: drone.xiange.tech

sourceControl:
  ## your source control provider: github,gitlab,gitea,gogs,bitbucketCloud,bitbucketServer
 provider: github
  ## secret containing your source control provider secrets, keys provided below.
  ## if left blank will assume a secret based on the release name of the chart.
 secret: drone-server-secrets
  ## Fill in the correct values for your chosen source control provider
  ## Any key in this list with the suffix will be fetched from the
  ## secret named above, if not provided the secret it will be created as
  ## using for the key "ClientSecretKey" and
  # "clientSecretValue" for the value. Be awere to not leak shis file with your password
 github:
 clientSecretKey: clientSecret
 server: https://github.com
复制代码

准备好 values 以后,helm upgrade 更新 chart 再次部署

$ helm upgrade drone --reuse-values --values drone-values.yaml \ 
  --set 'sourceControl.github.clientID={github-oauth2-client-id}' stable/drone
Release "drone" has been upgraded. Happy Helming!
NAME: drone
LAST DEPLOYED: 2019-10-31 15:27:53.284739572 +0800 CST
NAMESPACE: default
STATUS: deployed
NOTES:
*********************************************************************************
***        PLEASE BE PATIENT: drone may take a few minutes to install         ***
*********************************************************************************
From outside the cluster, the server URL(s) are:
     http://drone.xiange.tech
复制代码

查看 deployment 状态,部署成功

$ kubectl get deploy drone-drone-server
NAME                 READY   UP-TO-DATE   AVAILABLE   AGE
drone-drone-server   1/1     1            1           6h44
复制代码

打开浏览器,查看域名 drone.xiange.tech,通过 github 受权后能够看到 drone.ci 的管理页面

drone部署成功

更多文章


我是山月,一个喜欢跑步与登山的程序员,我会按期分享全栈文章在我的公众号中,欢迎交流

欢迎关注公众号山月行,我会按期分享一些先后端以及运维的文章
相关文章
相关标签/搜索