在阿裡雲容器服務上,輕鬆搭建Concourse CI

來源:互聯網
上載者:User

摘要 Concourse CI是一款CI/CD工具,它的魅力在於極簡設計,被廣泛套用於Cloud Foundry各個模組的CI/CD。本文介紹在阿裡雲容器服務上快速搭建Concourse。

Concourse CI是一款CI/CD工具,它的魅力在於極簡設計,被廣泛套用於CloudFoundry各個模組的CI/CD。阿裡雲也推出了CI工具CodePipeline,開箱即用,推薦試用。

image

Concourse CI官方提供了標準的Docker鏡像,在阿裡雲容器服務部署一套Concourse CI套用是很輕鬆的一件事。

準備Docker集群

·首先,在阿裡雲容器服務主控台建立一個集群。簡單起見,這裡節點數為1,網路類型為經典網路。

集群建立程序大約幾分鐘,成功後的狀態如下圖:

image

·然後需要開啟8080埠的入網權限:

image

·接下來,SSH到節點上,建立容器目錄,腳本如下:

·mkdir -p keys/web keys/worker
·ssh-keygen -t rsa -f ./keys/web/tsa_host_key -N ''
·ssh-keygen -t rsa -f ./keys/web/session_signing_key -N ''
·ssh-keygen -t rsa -f ./keys/worker/worker_key -N ''
·cp ./keys/worker/worker_key.pub ./keys/web/authorized_worker_keys
·cp ./keys/web/tsa_host_key.pub ./keys/worker

部署Concourse CI

·在容器服務主控台建立套用,填寫基本資料如下圖:

image

·用compose範本來建立套用,範本如下:

·version: '2'
·services:
·concourse-db:
·image: postgres:9.5
·privileged: true
·environment:
·POSTGRES_DB: concourse
·POSTGRES_USER: concourse
·POSTGRES_PASSWORD: changeme
·PGDATA: /database
·concourse-web:
·image: concourse/concourse
·links: [concourse-db]
·command: web
·privileged: true
·depends_on: [concourse-db]
·ports: ["8080:8080"]
·volumes: ["/keys/web:/concourse-keys"]
·restart: unless-stopped # required so that it retries until conocurse-db comes up
·environment:
·CONCOURSE_BASIC_AUTH_USERNAME: concourse
·CONCOURSE_BASIC_AUTH_PASSWORD: changeme
·CONCOURSE_EXTERNAL_URL: "${CONCOURSE_EXTERNAL_URL}"
·CONCOURSE_POSTGRES_HOST: concourse-db
·CONCOURSE_POSTGRES_USER: concourse
·CONCOURSE_POSTGRES_PASSWORD: changeme
·CONCOURSE_POSTGRES_DATABASE: concourse
·concourse-worker:
·image: concourse/concourse
·privileged: true
·links: [concourse-web]
·depends_on: [concourse-web]
·command: worker
·volumes: ["/keys/worker:/concourse-keys"]
·environment:
·CONCOURSE_TSA_HOST: concourse-web
·dns: 8.8.8.8

·在建立套用之前需要填寫範本參數,CONCOURSE_EXTERNAL_URL,值為http://your-ecs-public-ip:8080,如下圖所示:

image

·建立之後會啟動3個服務,DB、Web和Worker,如下圖:

image

·至此,Concourse CI部署完成,在瀏覽器輸入http://your-ecs-public-ip:8080即可存取。使用者名稱密碼是concourse/changeme
image

第一個CI任務(Hello world)

·安裝CLI用戶端,在上一步瀏覽器中下載對應您作業系統的CLI.本例以ECS(ubuntu16.04),安裝之後可以查看一下組建

·fly -v
·3.4.0

·串連Target,使用者名稱密碼是concourse/changeme

·fly -t lite login -c http://your-ecs-public-ip:8080
·logging in to team 'main'
·username: concourse
·password:
·target saved

·一個簡單的設定範本,儲存為hello.yml

·jobs:
·- name: hello-world
·plan:
·- task: say-hello
·config:
·platform: linux
·image_resource:
·type: docker-image
·source: {repository: ubuntu}
·run:
·path: echo
·args: ["Hello, world!"]

·註冊任務

·fly -t lite set-pipeline -p hello-world -c hello.yml

·啟動任務

·fly -t lite unpause-pipeline -p hello-world

·成功執行的介面如下

image

最後

本文僅僅是安裝引導,歡迎探索ConcourseCI其他屬性。

參考

https://concourse.ci/docker-repository.html
https://concourse.ci/hello-world.html

相關產品:

  1. 容器服務(Docker)
  2. 憑證服務
  3. 阿裡雲辦公
  4. 雲端服務器ECS
相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.