Concourse Lab Creation

支持 HackTricks

测试环境

运行 Concourse

使用 Docker-Compose

此 docker-compose 文件简化了与 concourse 进行一些测试的安装:

wget https://raw.githubusercontent.com/starkandwayne/concourse-tutorial/master/docker-compose.yml
docker-compose up -d

您可以从网络上下载适用于您的操作系统的命令行 fly,地址为 127.0.0.1:8080

使用 Kubernetes(推荐)

您可以使用 helm-chart 轻松在 Kubernetes(例如在 minikube 中)部署 concourse: concourse-chart.

brew install helm
helm repo add concourse https://concourse-charts.storage.googleapis.com/
helm install concourse-release concourse/concourse
# concourse-release will be the prefix name for the concourse elements in k8s
# After the installation you will find the indications to connect to it in the console

# If you need to delete it
helm delete concourse-release

在生成 concourse 环境后,您可以生成一个秘密并授予在 concourse web 中运行的 SA 访问 K8s 秘密的权限:

echo 'apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: read-secrets
rules:
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get"]

---

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: read-secrets-concourse
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: read-secrets
subjects:
- kind: ServiceAccount
name: concourse-release-web
namespace: default

---

apiVersion: v1
kind: Secret
metadata:
name: super
namespace: concourse-release-main
type: Opaque
data:
secret: MWYyZDFlMmU2N2Rm

' | kubectl apply -f -

创建管道

管道由一个包含有序列表的 Jobs 组成,这个列表包含 Steps

步骤

可以使用几种不同类型的步骤:

每个 stepjob plan 中在其 自己的容器 中运行。您可以在容器内运行任何您想要的内容 (即运行我的测试,运行这个 bash 脚本,构建这个镜像等)。因此,如果您有一个包含五个步骤的作业,Concourse 将为每个步骤创建五个容器。

因此,可以指示每个步骤需要运行的容器类型。

简单管道示例

jobs:
- name: simple
plan:
- task: simple-task
privileged: true
config:
# Tells Concourse which type of worker this task should run on
platform: linux
image_resource:
type: registry-image
source:
repository: busybox # images are pulled from docker hub by default
run:
path: sh
args:
- -cx
- |
sleep 1000
echo "$SUPER_SECRET"
params:
SUPER_SECRET: ((super.secret))
fly -t tutorial set-pipeline -p pipe-name -c hello-world.yml
# pipelines are paused when first created
fly -t tutorial unpause-pipeline -p pipe-name
# trigger the job and watch it run to completion
fly -t tutorial trigger-job --job pipe-name/simple --watch
# From another console
fly -t tutorial intercept --job pipe-name/simple

检查 127.0.0.1:8080 以查看管道流。

带有输出/输入管道的 Bash 脚本

可以 将一个任务的结果保存到文件中 并指示它是一个输出,然后将下一个任务的输入指示为上一个任务的输出。Concourse 所做的是 在新任务中挂载上一个任务的目录,以便您可以访问上一个任务创建的文件

触发器

您不需要每次手动触发作业,您还可以编程使其每次运行:

查看一个在主分支新提交时触发的 YAML 管道示例:https://concourse-ci.org/tutorial-resources.html

支持 HackTricks

Last updated