Skip to content

Commit 2a57793

Browse files
authored
Add Documentation (#3)
* Added docs * Add original_yaml_string and runtime_environment to pipeline * Minor fix in docs * Add pipeline revision * Fix docs
1 parent b924e06 commit 2a57793

File tree

4 files changed

+306
-55
lines changed

4 files changed

+306
-55
lines changed

docs/index.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
layout: "codefresh"
3+
page_title: "Provider: Codefresh"
4+
sidebar_current: "docs-codefresh-index"
5+
description: |-
6+
The Codefresh provider is used to manage Codefresh resources.
7+
---
8+
9+
# Codefresh Provider
10+
11+
The Codefresh Provider can be used to configure [Codefresh](https://codefresh.io/) resources - pipelines, projects, accounts, etc using the [Codefresh API](https://codefresh.io/docs/docs/integrations/codefresh-api/).
12+
13+
## Authenticating to Codefresh
14+
15+
The Codefresh API requires the [authentication key](https://codefresh.io/docs/docs/integrations/codefresh-api/#authentication-instructions) to authenticate.
16+
The key can be passed either as provider's attribute or as environment variable - `CODEFRESH_API_KEY`.
17+
18+
## Example Usage
19+
20+
```hcl
21+
provider "codefresh" {
22+
token = "xxxxxxxxx.xxxxxxxxxx"
23+
}
24+
25+
resource "codefresh_project" "project" {
26+
name = "myproject"
27+
28+
tags = [
29+
"production",
30+
"docker",
31+
]
32+
33+
variables = {
34+
myProjectVar = "value"
35+
}
36+
}
37+
38+
resource "codefresh_pipeline" "pipeline" {
39+
lifecycle {
40+
ignore_changes = [
41+
revision
42+
]
43+
}
44+
45+
name = "${codefresh_project.project.name}/mypipeline"
46+
47+
spec {
48+
49+
spec_template {
50+
repo = "my-github-account/my-repository"
51+
path = "./codefresh.yml"
52+
revision = "master"
53+
context = "github"
54+
}
55+
56+
variables = {
57+
goVersion = "1.13"
58+
release = "true"
59+
}
60+
}
61+
}
62+
```
63+
64+
## Argument Reference
65+
66+
The following arguments are supported:
67+
68+
- `token` - (Optional) The client API token. This can also be sourced from the `CODEFRESH_API_KEY` environment variable.
69+
- `api_url` -(Optional) Default value - https://g.codefresh.io/api.

docs/resources/pipeline.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# Pipeline Resource
2+
3+
The central component of the Codefresh Platform. Pipelines are workflows that contain individual steps. Each step is responsible for a specific action in the process.
4+
See the [documentation](https://codefresh.io/docs/docs/configure-ci-cd-pipeline/introduction-to-codefresh-pipelines/) for the details.
5+
6+
## Example Usage
7+
8+
```hcl
9+
resource "codefresh_project" "test" {
10+
name = "myproject"
11+
}
12+
13+
resource "codefresh_pipeline" "test" {
14+
15+
lifecycle {
16+
ignore_changes = [
17+
revision
18+
]
19+
}
20+
21+
name = "${codefresh_project.test.name}/react-sample-app"
22+
23+
tags = [
24+
"production",
25+
"docker",
26+
]
27+
28+
spec {
29+
concurrency = 1
30+
priority = 5
31+
32+
spec_template {
33+
repo = "codefresh-contrib/react-sample-app"
34+
path = "./codefresh.yml"
35+
revision = "master"
36+
context = "git"
37+
}
38+
39+
trigger {
40+
branch_regex = "/.*/gi"
41+
context = "git"
42+
description = "Trigger for commits"
43+
disabled = false
44+
events = [
45+
"push.heads"
46+
]
47+
modified_files_glob = ""
48+
name = "commits"
49+
provider = "github"
50+
repo = "codefresh-contrib/react-sample-app"
51+
type = "git"
52+
}
53+
54+
trigger {
55+
branch_regex = "/.*/gi"
56+
context = "git"
57+
description = "Trigger for tags"
58+
disabled = false
59+
events = [
60+
"push.tags"
61+
]
62+
modified_files_glob = ""
63+
name = "tags"
64+
provider = "github"
65+
repo = "codefresh-contrib/react-sample-app"
66+
type = "git"
67+
}
68+
69+
variables = {
70+
MY_PIP_VAR = "value"
71+
ANOTHER_PIP_VAR = "another_value"
72+
}
73+
}
74+
}
75+
```
76+
77+
## Argument Reference
78+
79+
- `name` - (Required) The display name for the pipeline.
80+
- `revision` - (Optional) The pipeline's revision. Should be added to the **lifecycle/ignore_changes** or incremented mannually each update.
81+
- `tags` - (Optional) A list of tags to mark a project for easy management and access control.
82+
- `spec` - (Required) A collection of `spec` blocks as documented below.
83+
- `original_yaml_string` - (Optional) A string with original yaml pipeline.
84+
- `original_yaml_string = "version: \"1.0\"\nsteps:\n test:\n image: alpine:latest\n commands:\n - echo \"ACC tests\""`
85+
- or `original_yaml_string = file("/path/to/my/codefresh.yml")`
86+
87+
---
88+
89+
`spec` supports the following:
90+
91+
- `concurrency` - (Optional) The maximum amount of concurrent builds.
92+
- `priority` - (optional) Helps to organize the order of builds execution in case of reaching the concurrency limit.
93+
- `variables` - (Optional) Pipeline variables.
94+
- `trigger` - (Optional) A collection of `trigger` blocks as documented below. Triggers [documentation](https://codefresh.io/docs/docs/configure-ci-cd-pipeline/triggers/git-triggers/).
95+
- `spec_template` - (Optional) A collection of `spec_template` blocks as documented below.
96+
- `runtime_environment` - (Optional) A collection of `runtime_environment` blocks as documented below.
97+
98+
---
99+
100+
`spec_template` supports the following:
101+
102+
- `location` - (Optional) Default value - **git**.
103+
- `repo` - (Required) The GitHub `account/repo_name`.
104+
- `path` - (Required) The relative path to the Codefresh pipeline file.
105+
- `revison` - (Required) The git revision.
106+
- `context` - (Optional) The Codefresh Git [context](https://codefresh.io/docs/docs/integrations/git-providers/).
107+
108+
---
109+
110+
`trigger` supports the following:
111+
112+
- `name` - (Optional) The display name for the pipeline.
113+
- `description` - (Optional) The trigger description.
114+
- `type` - (Optional) The trigger type. Default value - **git**.
115+
- `repo` - (Optional) The GitHub `account/repo_name`.
116+
- `branch_regex` - (Optional) A regular expression and will only trigger for branches that match this naming pattern.
117+
- `modified_files_glob` - (Optional) Allows to constrain the build and trigger it only if the modified files from the commit match this glob expression.
118+
- `events` - (Optional) A list of GitHub events for which a Pipeline is triggered. Default value - **push.heads**.
119+
- `provider` - (Optional) Default value - **github**.
120+
- `context` - (Optional) Codefresh Git context.
121+
- `variables` - (Optional) Trigger variables.
122+
123+
---
124+
125+
`runtime_environment` supports the following:
126+
127+
- `name` - (Required) A name of runtime.
128+
- `cpu` - (Optional) A required amount of CPU.
129+
- `memory` - (Optional) A required amount of memory.
130+
- `dind_storage` - (Optional) A pipeline shared storage.
131+
132+
## Attributes Reference
133+
134+
- `id` - The Pipeline ID.
135+
136+
## Import
137+
138+
```sh
139+
terraform import codefresh_pipeline.test xxxxxxxxxxxxxxxxxxx
140+
```

docs/resources/project.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Project Resource
2+
3+
The top-level concept in Codefresh. You can create projects to group pipelines that are related. In most cases a single project will be a single application (that itself contains many micro-services). You are free to use projects as you see fit. For example, you could create a project for a specific Kubernetes cluster or a specific team/department.
4+
More about pipeline concepts see in the [official documentation](https://codefresh.io/docs/docs/configure-ci-cd-pipeline/pipelines/#pipeline-concepts).
5+
6+
## Example Usage
7+
8+
```hcl
9+
resource "codefresh_project" "test" {
10+
name = "myproject"
11+
12+
tags = [
13+
"production",
14+
"docker",
15+
]
16+
17+
variables = {
18+
go_version = "1.13"
19+
}
20+
}
21+
```
22+
23+
## Argument Reference
24+
25+
- `name` (Required) The display name for the project.
26+
- `tags` (Optional) A list of tags to mark a project for easy management and access control.
27+
- `variables` (Optional) project variables.
28+
29+
## Attributes Reference
30+
31+
- `id` - The Project ID
32+
33+
## Import
34+
35+
```sh
36+
terraform import codefresh_project.test xxxxxxxxxxxxxxxxxxx
37+
```

examples/README.md

Lines changed: 60 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,81 @@
11
# Example
22

3-
```yaml
4-
resource "codefresh_project" "test" {
5-
name = "test"
6-
}
7-
```
3+
In the example the Codefresh Provider is configured to authenticate with Codefresh API, and new project and pipeline are created.
4+
Pipeline includes link to the original __codefresh.yml__ spec and two git triggres.
85

96
Run `terraform plan` or `terraform apply` as usual. Note this will modify the actual Codefresh configuration.
107

11-
# Syntax Examples
12-
13-
## Project
14-
15-
```yaml
16-
resource "codefresh_project" "docker" {
17-
name = "docker"
8+
```hcl
9+
provider "codefresh" {
10+
api_url = "https://my.onpremcodefresh.com/api"
11+
token = "xxxxxxxxxxxxxxx.xxxxxxxxxxxxxx"
1812
}
19-
```
20-
21-
## Pipeline
2213
23-
```yaml
24-
resource "codefresh_pipeline" "docker_monorepo" {
25-
name = "docker/docker-monorepo"
26-
project = "docker"
27-
28-
spec = {
29-
repo = "abcinc/monorepo"
30-
path = "./codefresh/docker/docker-monorepo.yaml"
31-
revision = "master"
32-
concurrency = 1
33-
priority = 5
34-
}
14+
resource "codefresh_project" "test" {
15+
name = "myproject"
3516
3617
tags = [
3718
"docker",
3819
]
3920
4021
variables {
41-
TAG = "master"
22+
go_version = "1.13"
4223
}
4324
}
44-
```
45-
46-
## Cron Trigger
47-
48-
```yaml
49-
resource "codefresh_cron_event" "docker_monorepo_cron" {
50-
expression = "40 0 * * *"
51-
message = "build monorepo docker"
52-
}
5325
54-
resource "codefresh_cron_trigger" "docker_monorepo_cron" {
55-
pipeline = "${codefresh_pipeline.docker_monorepo.id}"
56-
event = "${codefresh_cron_event.docker_monorepo_cron.id}"
57-
}
58-
```
26+
resource "codefresh_pipeline" "test" {
27+
name = "${codefresh_project.test.name}/react-sample-app"
5928
60-
## Environment
29+
tags = [
30+
"production",
31+
"docker",
32+
]
6133
62-
```yaml
63-
resource "codefresh_environment" "staging" {
64-
account_id = "<redacted>"
65-
name = "staging"
66-
namespace = "staging"
67-
cluster = "abcinc-staging"
68-
}
69-
```
34+
spec {
35+
concurrency = 1
36+
priority = 5
7037
71-
## User
72-
```yaml
73-
resource "codefresh_user" "john_doe" {
74-
38+
spec_template {
39+
repo = "codefresh-contrib/react-sample-app"
40+
path = "./codefresh.yml"
41+
revision = "master"
42+
context = "git"
43+
}
44+
45+
trigger {
46+
branch_regex = "/.*/gi"
47+
context = "git"
48+
description = "Trigger for commits"
49+
disabled = false
50+
events = [
51+
"push.heads"
52+
]
53+
modified_files_glob = ""
54+
name = "commits"
55+
provider = "github"
56+
repo = "codefresh-contrib/react-sample-app"
57+
type = "git"
58+
}
59+
60+
trigger {
61+
branch_regex = "/.*/gi"
62+
context = "git"
63+
description = "Trigger for tags"
64+
disabled = false
65+
events = [
66+
"push.tags"
67+
]
68+
modified_files_glob = ""
69+
name = "tags"
70+
provider = "github"
71+
repo = "codefresh-contrib/react-sample-app"
72+
type = "git"
73+
}
74+
75+
variables = {
76+
MY_PIP_VAR = "value"
77+
ANOTHER_PIP_VAR = "another_value"
78+
}
79+
}
7580
}
7681
```

0 commit comments

Comments
 (0)