mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-01-27 15:24:32 -08:00
144 lines
6.2 KiB
Markdown
144 lines
6.2 KiB
Markdown
# Concourse Lab Creation
|
||
|
||
{{#include ../../banners/hacktricks-training.md}}
|
||
|
||
## テスト環境
|
||
|
||
### Concourseの実行
|
||
|
||
#### Docker-Composeを使用して
|
||
|
||
このdocker-composeファイルは、concourseでいくつかのテストを行うためのインストールを簡素化します:
|
||
```bash
|
||
wget https://raw.githubusercontent.com/starkandwayne/concourse-tutorial/master/docker-compose.yml
|
||
docker-compose up -d
|
||
```
|
||
コマンドライン `fly` をあなたのOS用にウェブから `127.0.0.1:8080` でダウンロードできます。
|
||
|
||
#### Kubernetesを使用して(推奨)
|
||
|
||
**Kubernetes**(例えば**minikube**)でhelm-chartを使用してconcourseを簡単にデプロイできます: [**concourse-chart**](https://github.com/concourse/concourse-chart)。
|
||
```bash
|
||
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の秘密にアクセスする権限を与えることができます:
|
||
```yaml
|
||
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 -
|
||
```
|
||
### パイプラインの作成
|
||
|
||
パイプラインは、順序付きの[ジョブ](https://concourse-ci.org/jobs.html)のリストで構成されています。
|
||
|
||
### ステップ
|
||
|
||
いくつかの異なるタイプのステップを使用できます:
|
||
|
||
- **the** [**`task` step**](https://concourse-ci.org/task-step.html) **は** [**task**](https://concourse-ci.org/tasks.html) **を実行します**
|
||
- the [`get` step](https://concourse-ci.org/get-step.html) は [resource](https://concourse-ci.org/resources.html) を取得します
|
||
- the [`put` step](https://concourse-ci.org/put-step.html) は [resource](https://concourse-ci.org/resources.html) を更新します
|
||
- the [`set_pipeline` step](https://concourse-ci.org/set-pipeline-step.html) は [pipeline](https://concourse-ci.org/pipelines.html) を構成します
|
||
- the [`load_var` step](https://concourse-ci.org/load-var-step.html) は [local var](https://concourse-ci.org/vars.html#local-vars) に値をロードします
|
||
- the [`in_parallel` step](https://concourse-ci.org/in-parallel-step.html) はステップを並行して実行します
|
||
- the [`do` step](https://concourse-ci.org/do-step.html) はステップを順番に実行します
|
||
- the [`across` step modifier](https://concourse-ci.org/across-step.html#schema.across) はステップを複数回実行します;変数の値の組み合わせごとに1回
|
||
- the [`try` step](https://concourse-ci.org/try-step.html) はステップを実行しようとし、ステップが失敗しても成功します
|
||
|
||
各[ステップ](https://concourse-ci.org/steps.html)は、[ジョブプラン](https://concourse-ci.org/jobs.html#schema.job.plan)内で**独自のコンテナ**で実行されます。コンテナ内で何でも実行できます _(つまり、テストを実行する、bashスクリプトを実行する、このイメージをビルドするなど)。_ したがって、5つのステップを持つジョブがある場合、Concourseは各ステップのために5つのコンテナを作成します。
|
||
|
||
したがって、各ステップが実行される必要があるコンテナのタイプを指定することが可能です。
|
||
|
||
### シンプルなパイプラインの例
|
||
```yaml
|
||
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))
|
||
```
|
||
|
||
```bash
|
||
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スクリプト
|
||
|
||
**1つのタスクの結果をファイルに保存**し、それを出力として示し、次のタスクの入力を前のタスクの出力として示すことが可能です。Concourseが行うことは、**前のタスクのディレクトリを新しいタスクにマウントし、前のタスクによって作成されたファイルにアクセスできるようにすることです**。
|
||
|
||
### トリガー
|
||
|
||
ジョブを手動で毎回トリガーする必要はなく、毎回実行されるようにプログラムすることもできます:
|
||
|
||
- しばらく時間が経過したとき: [Time resource](https://github.com/concourse/time-resource/)
|
||
- メインブランチへの新しいコミット時: [Git resource](https://github.com/concourse/git-resource)
|
||
- 新しいPR: [Github-PR resource](https://github.com/telia-oss/github-pr-resource)
|
||
- アプリの最新イメージを取得またはプッシュ: [Registry-image resource](https://github.com/concourse/registry-image-resource/)
|
||
|
||
[https://concourse-ci.org/tutorial-resources.html](https://concourse-ci.org/tutorial-resources.html) で、マスターへの新しいコミットでトリガーされるYAMLパイプラインの例を確認してください。
|
||
|
||
{{#include ../../banners/hacktricks-training.md}}
|