Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README-ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ services:
type: kustomize
```

サービスは `roots` の下にあるファイルを持ち、`{service}` の位置のディレクトリ名がサービス名になります。stack はサービスの中のデプロイ元ディレクトリです。この設定では、`apps/api/src/main.rb` を変更すると Pull Request に `deploy:api` が付き、`apps/api/kubernetes/overlays/develop` ディレクトリがあれば次のターゲットが作られます。
サービスは `roots` の下にあるファイルを持ち、`{service}` の位置のディレクトリ名がサービス名になります。[サービス名](action-scripts/config-manager/README-ja.md#service-names)に使えるのは ASCII の英字、数字、`_`、`-` だけで、`a.b` や `.github` のようにそれ以外の文字を含むディレクトリはサービスではありません。stack はサービスの中のデプロイ元ディレクトリです。この設定では、`apps/api/src/main.rb` を変更すると Pull Request に `deploy:api` が付き、`apps/api/kubernetes/overlays/develop` ディレクトリがあれば次のターゲットが作られます。

```json
{
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ services:
type: kustomize
```

A service owns the files under its `roots`, and the directory name at `{service}` becomes the service name. A stack is a directory inside the service to deploy from. With this configuration, changing `apps/api/src/main.rb` labels the pull request `deploy:api`, and an existing `apps/api/kubernetes/overlays/develop` directory produces this target:
A service owns the files under its `roots`, and the directory name at `{service}` becomes the service name. A [service name](action-scripts/config-manager/README.md#service-names) contains only ASCII letters, digits, `_`, and `-`, and a directory with any other name, such as `a.b` or `.github`, is not a service. A stack is a directory inside the service to deploy from. With this configuration, changing `apps/api/src/main.rb` labels the pull request `deploy:api`, and an existing `apps/api/kubernetes/overlays/develop` directory produces this target:

```json
{
Expand Down
12 changes: 9 additions & 3 deletions action-scripts/config-manager/README-ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ bundle exec ruby config-manager/bin/config-manager test demo
bundle exec ruby config-manager/bin/config-manager test demo production
```

環境を省略すると、定義された環境と探索された環境のすべてに、環境をまたいで共有されるターゲットを加えて調べます。環境を指定すると、その環境と共有ターゲットを調べます。サービスの事前登録は不要で、どのディレクトリにも一致しない名前を渡すと結果は空になります。各ターゲットは stack の `id`、展開後の属性値、取得したプレースホルダーとともに表示されます。除外されたターゲットも `excluded: true` を付けて表示されるので、デプロイから外れるものを確認できます。未知の環境、不正な設定、ディレクトリを列挙できない場合、同じターゲットで取得値が食い違う場合はエラーになり、終了コード 1 で終わります。
環境を省略すると、定義された環境と探索された環境のすべてに、環境をまたいで共有されるターゲットを加えて調べます。環境を指定すると、その環境と共有ターゲットを調べます。サービスの事前登録は不要で、正しい名前がどのディレクトリにも一致しないときは結果が空になります。各ターゲットは stack の `id`、展開後の属性値、取得したプレースホルダーとともに表示されます。除外されたターゲットも `excluded: true` を付けて表示されるので、デプロイから外れるものを確認できます。[正しいサービス名](#service-names)でない名前、未知の環境、不正な設定、ディレクトリを列挙できない場合、同じターゲットで取得値が食い違う場合はエラーになり、終了コード 1 で終わります。

元の設定を編集せずに変更を試すときは、`WORKFLOW_CONFIG_PATH` でコピーを指定します。

Expand Down Expand Up @@ -118,6 +118,12 @@ services:

root には `{project}` のような任意のプレースホルダーを使えます。`envs/{environment}/{service}` のように root に `{environment}` を書くと拒否されます。環境は stack の `path` で表すものだからです。環境ディレクトリがサービスの下にあるなら、`{environment}` は `path` に書き、root はサービスのディレクトリのままにします。こうすると、環境の隣にある共有ディレクトリも root の下に収まります。

### Service Names

サービス名は `[a-zA-Z0-9_-]+` に一致する名前で、使えるのは ASCII の英字、数字、`_`、`-` です。`all` も他と同じ普通の名前です。

`{service}` の位置のディレクトリのうち、`a.b` や `.github` のようにそれ以外の名前を持つものはサービスではありません。その下を変更してもラベルは付かず、ターゲットも作られず、その下の環境も探索されません。ツールは中を見ないので、読み取れないディレクトリでも構いません。`{team}` など他のプレースホルダーにこの制約はありません。

### Stacks

stack は各 root に `path` を続けた場所で動きます。root が `aws/{service}`、path が `{environment}` なら、ディレクトリのパターンは `aws/{service}/{environment}` です。複数の stack が同じディレクトリを指しても構いません。
Expand Down Expand Up @@ -154,7 +160,7 @@ profile の属性には環境の属性と同じルールが適用されます。

### Path Patterns

root と path は相対パターンです。絶対パスと `..` セグメントは拒否されます。先頭の `./`、余分な `/`、`.` セグメントは正規化されます。名前がドットで始まるサービスは対象から外れます。
root と path は相対パターンです。絶対パスと `..` セグメントは拒否されます。先頭の `./`、余分な `/`、`.` セグメントは正規化されます。

任意のプレースホルダーの名前は `[a-z_][a-z0-9_]*` に一致する必要があり、値は 1 つのパスセグメントに収まります。同じプレースホルダーを複数回書くと、すべて同じ値に一致しなければなりません。glob の文字は文字どおりに扱われます。

Expand All @@ -166,7 +172,7 @@ root と path は相対パターンです。絶対パスと `..` セグメント

条件は完全一致で判定します。マップ内のキーは AND、配列のエントリは OR で組み合わされ、書かなかったキーは制約になりません。一致した root が取得しない値を要求する条件は、その root では一致しません。たとえば `project: sandbox` が除外するのは、`gcp/{project}/{service}` のような root の下のターゲットだけです。

条件の値は 1 つのパスセグメントを表す空でない文字列で、`/`、`.`、`..` は使えません。サービス名をドットで始めることはできません。値は文字どおりに扱われ、プレースホルダーは展開されません。
条件の値は 1 つのパスセグメントを表す空でない文字列で、`/`、`.`、`..` は使えません。`service` の条件は[正しいサービス名](#service-names)でなければならず、`service: a.b` は設定エラーになります。値は文字どおりに扱われ、プレースホルダーは展開されません。

`environment` 条件の扱いは、stack が環境をどう得るかで変わります。`environments` があれば、その stack で定義した環境だけを指定できます。環境を探索する stack では、まだ存在しないディレクトリの値も指定できます。`environments` も `path` の `{environment}` も持たない stack では、`environment` を省略するか `null` にします。それ以外の条件の値に `null` は使えません。

Expand Down
12 changes: 9 additions & 3 deletions action-scripts/config-manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ bundle exec ruby config-manager/bin/config-manager test demo
bundle exec ruby config-manager/bin/config-manager test demo production
```

Without an environment it covers all declared and discovered environments plus the targets shared across environments. With an environment it covers that environment plus the shared targets. Services do not need registering, and a name that matches no directory prints an empty result. Each target is printed with its stack `id`, expanded attribute values, and captured placeholders. Excluded targets are printed too, with `excluded: true`, so you can see what is left out of deployment. An unknown environment, an invalid configuration, a directory that cannot be listed, and conflicting captured values for the same target are errors and exit with status 1.
Without an environment it covers all declared and discovered environments plus the targets shared across environments. With an environment it covers that environment plus the shared targets. Services do not need registering, and a valid name that matches no directory prints an empty result. Each target is printed with its stack `id`, expanded attribute values, and captured placeholders. Excluded targets are printed too, with `excluded: true`, so you can see what is left out of deployment. A name that is not a [valid service name](#service-names), an unknown environment, an invalid configuration, a directory that cannot be listed, and conflicting captured values for the same target are errors and exit with status 1.

To try a configuration change without editing the original, point `WORKFLOW_CONFIG_PATH` at a copy:

Expand Down Expand Up @@ -118,6 +118,12 @@ The value captured by `{service}` is the service name in labels and the matrix.

Roots can contain arbitrary placeholders such as `{project}`. `{environment}` is rejected in roots, as in `envs/{environment}/{service}`, because the environment belongs to a stack's `path`. When environment directories sit below the service, put `{environment}` in `path` and keep the root at the service directory, so that shared directories next to the environments stay under the root.

### Service Names

A service name matches `[a-zA-Z0-9_-]+`: ASCII letters, digits, `_`, and `-`. `all` is a name like any other.

A directory at the `{service}` position with any other name, such as `a.b` or `.github`, is not a service. A change below it labels nothing, it produces no targets, and environments below it are not discovered. The tools do not look inside it, so it may be unreadable. Other placeholders, such as `{team}`, have no such rule.

### Stacks

A stack runs in each root followed by its `path`: root `aws/{service}` with path `{environment}` is the directory pattern `aws/{service}/{environment}`. Different stacks can point at the same directory.
Expand Down Expand Up @@ -154,7 +160,7 @@ Every placeholder referenced by an attribute must be available for every root of

### Path Patterns

Roots and paths are relative patterns. Absolute paths and `..` segments are rejected. A leading `./`, extra `/` separators, and `.` segments are normalized. Service names starting with a dot are excluded.
Roots and paths are relative patterns. Absolute paths and `..` segments are rejected. A leading `./`, extra `/` separators, and `.` segments are normalized.

Names of arbitrary placeholders must match `[a-z_][a-z0-9_]*`, and each value occupies one path segment. Repeated occurrences of a placeholder must match the same value. Glob characters are treated literally.

Expand All @@ -166,7 +172,7 @@ Each entry in `exclude` is a nonempty condition map. Conditions can use `service

Conditions use exact matching: keys within a map are combined with AND, and entries in the array are combined with OR. Omitted keys impose no restriction. A condition requiring a captured value that the matched root does not capture does not match there. For example, `project: sandbox` excludes only the targets under a root such as `gcp/{project}/{service}`.

Condition values must be nonempty strings representing one path segment, so `/`, `.`, and `..` are not allowed. Service names cannot start with a dot. Values are literal and do not expand placeholders.
Condition values must be nonempty strings representing one path segment, so `/`, `.`, and `..` are not allowed. A `service` condition must be a [valid service name](#service-names), so `service: a.b` is a configuration error. Values are literal and do not expand placeholders.

The `environment` condition depends on how the stack gets its environments. With `environments`, it can name only the stack's declared environments. A stack that discovers environments can name a directory value that does not exist yet. A stack with neither `environments` nor `{environment}` in `path` can omit `environment` or set it to `null`. Other condition values cannot be `null`.

Expand Down
2 changes: 2 additions & 0 deletions action-scripts/config-manager/use_cases/test_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ def initialize(list_candidates:)
end

def execute(service_name:, environment:)
return Entities::Result.failure(Entities::Service.invalid_name_message(service_name)) unless Entities::Service.valid_name?(service_name)

candidates = @list_candidates.execute(services: [service_name], environments: environment && [environment])
return candidates if candidates.failure?

Expand Down
8 changes: 4 additions & 4 deletions action-scripts/label-dispatcher/README-ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ action は `repository` を全履歴つきで自分で checkout するので、j

変更ファイルがいずれかの root の下にあれば、そのサービスにラベルが付きます。dispatcher は Pull Request の base と head を three-dot diff で比較し、すべての変更ファイルをすべての root に対して次の順で評価します。

1. ファイルが root の下にない場合、または `{service}` の取得値がドットで始まる場合はスキップします。
1. ファイルが root の下にない場合、または `{service}` の取得値が[正しいサービス名](../config-manager/README-ja.md#service-names)でない場合はスキップします。
2. root からの相対パスが `ignore` のパターンに一致する場合はスキップします。
3. ファイルが stack のディレクトリ(root に `path` を続けた場所)の下にある場合は、[Label Resolver と同じ方法](../label-resolver/README-ja.md#how-targets-are-built)で候補ターゲットを作ります。`exclude` が候補をすべて除外しない限り、サービスにラベルを付けます。
4. `modules/` や `Makefile` のようにどの stack のディレクトリの下にもない場合は、サービスにラベルを付けます。こうした共有ファイルに `exclude` は効かないので、スキップするには `ignore` を使います。
Expand All @@ -55,7 +55,7 @@ action は `repository` を全履歴つきで自分で checkout するので、j
- 別の stack のディレクトリの下にあり、その候補がすべて除外されるファイルには、やはりラベルが付きません。
- `environments` を持つ stack では、`{environment}` の位置にある定義外のディレクトリは stack のディレクトリの外として扱います。

関係のないトップレベルのディレクトリがサービスとみなされないよう、root は十分に絞ります。たとえば `{service}` だけの root では、トップレベルのディレクトリすべてがサービスになります。
関係のないトップレベルのディレクトリがサービスとみなされないよう、root は十分に絞ります。たとえば `{service}` だけの root では、名前が正しいサービス名であるトップレベルのディレクトリすべてがサービスになります。

共有ファイルの変更で、解決できるターゲットのないサービスにラベルが付くこともあります。唯一の環境が除外されている場合などです。ラベルは付きますが、Label Resolver が返すターゲットは空です。

Expand Down Expand Up @@ -128,9 +128,9 @@ labels:

prefix は区切り文字を含めてそのまま使われるので、`:` で終わる prefix は YAML で引用符を付けます。prefix は空でない文字列でなければなりません。ある prefix が別の prefix で始まることは許されません。Label Dispatcher が重なった prefix のラベルまで外してしまうためです。

`<prefix>all` は Label Resolver で全サービスを対象にします。dispatcher がこれを作るのは `{service}` の位置に `all` というディレクトリがある場合だけなので、普通は手で付けます。ただし `prefix` のラベルを手で付けても次の push で外れます。`extra_prefixes` で始まるラベルには一切触らないので、`manual/all` や `manual/api` は以後の push でも残ります。
`prefix` のラベルを手で付けても次の push で外れます。`extra_prefixes` で始まるラベルには一切触らないので、`manual/api` は以後の push でも残ります。

`{service}` の位置のディレクトリには名前を問わずラベルが付きますが、Label Resolver は `[a-zA-Z0-9_-]+` に一致する名前[だけを読みます](../label-resolver/README-ja.md#from-labels-to-targets)。そのため `a.b` のようなディレクトリには、何にも解決されないラベルが付きます。
ラベルが付くのは[正しいサービス名](../config-manager/README-ja.md#service-names)だけです。`a.b` のようなディレクトリはサービスではないので、その下を変更してもラベルは付きません。`all` というディレクトリは普通のサービスで `<prefix>all` が付き、[Label Resolver はそれを](../label-resolver/README-ja.md#from-labels-to-targets)その 1 つのサービスとして読みます。

## Commands

Expand Down
Loading
Loading