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部署成功

更多文章


我是山月,一個喜歡跑步與登山的程序員,我會按期分享全棧文章在我的公衆號中,歡迎交流

歡迎關注公衆號山月行,我會按期分享一些先後端以及運維的文章
相關文章
相關標籤/搜索