Skip to content

Commit 82d79aa

Browse files
add registry docs
1 parent ed4d31d commit 82d79aa

File tree

5 files changed

+346
-18
lines changed

5 files changed

+346
-18
lines changed

codefresh/resource_registry.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func resourceRegistry() *schema.Resource {
132132
ConflictsWith: getConflictingProviders(providers, providerGar),
133133
Elem: &schema.Resource{
134134
Schema: map[string]*schema.Schema{
135-
"domain": {
135+
"location": {
136136
Type: schema.TypeString,
137137
Required: true,
138138
},
@@ -378,7 +378,7 @@ func mapResourceToRegistry(d *schema.ResourceData) *cfClient.Registry {
378378
providerKey = "spec.0." + providerGar
379379
if _, ok := d.GetOk(providerKey); ok {
380380
registry.Provider = providerGar
381-
registry.Domain = d.Get(providerKey + ".0.domain").(string)
381+
registry.Domain = d.Get(providerKey + ".0.location").(string)
382382
registry.Keyfile = d.Get(providerKey + ".0.keyfile").(string)
383383
registry.RepositoryPrefix = d.Get(providerKey + ".0.repository_prefix").(string)
384384
return registry
@@ -452,7 +452,7 @@ func mapRegistryToResource(registry cfClient.Registry, d *schema.ResourceData) e
452452

453453
if registry.Provider == providerGar {
454454
d.Set(fmt.Sprintf("spec.0.%v.0", providerGcr), map[string]interface{}{
455-
"domain": registry.Domain,
455+
"location": registry.Domain,
456456
"keyfile": registry.Keyfile,
457457
"repository_prefix": registry.RepositoryPrefix,
458458
})

docs/README.md

+25
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,28 @@ The following arguments are supported:
2828
* Create teams using [teams module](modules/teams.md)
2929
* Create permissions - [see example](../examples/permissions)
3030

31+
32+
## Resources
33+
* [account](resources/account.md)
34+
* [account-admins](resources/account-admins.md)
35+
* [api-key](resources/api-key.md)
36+
* [context](resources/context.md)
37+
* [idp-accounts](resources/idp-accounts.md)
38+
* [permissions](resources/permissions.md)
39+
* [pipeline](resources/pipeline.md)
40+
* [project](resources/project.md)
41+
* [registry](resources/registry.md)
42+
* [step-types](resources/step-types.md)
43+
* [team](resources/team.md)
44+
* [user](resources/user.md)
45+
46+
47+
## Data sources
48+
* [account](data/account.md)
49+
* [context](data/context.md)
50+
* [idps](data/idps.md)
51+
* [registry](data/registry.md)
52+
* [step-types](data/step-types.md)
53+
* [team](data/team.md)
54+
* [user](data/user.md)
55+

docs/data/registry.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Data Source: codefresh_registry
2+
This data source allows retrieving information on any existing registry
3+
4+
## Example Usage
5+
6+
```hcl
7+
# some pre-existing registry
8+
data "codefresh_registry" "dockerhub" {
9+
name = "dockerhub"
10+
}
11+
12+
# example with using data reference to existing registry, not managed by terraform
13+
# "dockerhub" registry will be used as fallback for "dockerhub1"
14+
resource "codefresh_registry" "dockerhub1" {
15+
name = "dockerhub1"
16+
primary = !data.codefresh_registry.dockerhub.primary
17+
18+
spec {
19+
dockerhub {
20+
username = "test"
21+
password = "test"
22+
}
23+
}
24+
fallback_registry = data.codefresh_registry.dockerhub.id
25+
}
26+
```
27+
28+
## Argument Reference
29+
30+
* `name` - (Required) Name of the registry to be retrieved
31+
32+
## Attributes Reference
33+
34+
* `domain` - String.
35+
* `registry_provider` - String identifying the type of registry. E.g. `dockerhub, ecr, acr` and others
36+
* `default` - Bool.
37+
* `primary` - Bool.
38+
* `fallback_registry` - String representing the id of the fallback registry.
39+
* `repository prefix` - String representing the optional prefix for registry.

docs/resources/registry.md

+264
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
# Registry Resource
2+
3+
Registry is the configuration that Codefresh uses to push/pull docker images.
4+
For more details see the [Codefresh Docker Registries](https://codefresh.io/docs/docs/integrations/docker-registries/)
5+
6+
7+
## Concurrency Limitation
8+
9+
Codefresh Registry API was not designed initially to handle concurrent modifications on `registry` entity.
10+
Thus, you need to take one of the following approaches to avoid **errors** and **non-expected behavior**:
11+
12+
1) run terraform write operations with `-parallelism=1` option
13+
```shell
14+
terraform apply -parallelism=1
15+
terraform destroy -parallelism=1
16+
```
17+
18+
2) make each registry resource `depend_on` each other - so the CRUD operations will be performed for each registry **sequentially**
19+
```hcl
20+
resource "codefresh_registry" "dockerhub" {
21+
name = "dockerhub"
22+
23+
spec {
24+
dockerhub {
25+
# some specific fields here
26+
}
27+
}
28+
}
29+
30+
# this registry will depend on the "dockerhub" registry
31+
resource "codefresh_registry" "gcr" {
32+
name = "gcr"
33+
34+
depends_on = [codefresh_registry.dockerhub]
35+
spec {
36+
gcr {
37+
# some specific fields here
38+
}
39+
}
40+
}
41+
```
42+
43+
## Supported Registry Providers
44+
45+
Currently, Codefresh supports the following registry providers:
46+
* dockerhub - [Docker Hub](https://codefresh.io/docs/docs/integrations/docker-registries/docker-hub/)
47+
* acr - [Azure Container Registry](https://codefresh.io/docs/docs/integrations/docker-registries/azure-docker-registry)
48+
* gcr - [Google Container Registry](https://codefresh.io/docs/docs/integrations/docker-registries/google-container-registry)
49+
* gar - [Google Artifact Registry](https://codefresh.io/docs/docs/integrations/docker-registries/google-artifact-registry)
50+
* ecr - [Amazon EC2 Container Registry](https://codefresh.io/docs/docs/integrations/docker-registries/amazon-ec2-container-registry)
51+
* bintray - [Bintray / Artifactory](https://codefresh.io/docs/docs/integrations/docker-registries/bintray-io)
52+
* other - any other provider including [Quay](https://codefresh.io/docs/docs/integrations/docker-registries/quay-io) and [Github Container Registry](https://codefresh.io/docs/docs/integrations/docker-registries/github-container-registry). See the [docs](https://codefresh.io/docs/docs/integrations/docker-registries/other-registries).
53+
54+
### Resource Spec
55+
56+
Each registry resource have some common fields and specific ones stored under the `spec`. Here is the template:
57+
58+
```hcl
59+
resource "codefresh_registry" "some_registry" {
60+
name = "some_name"
61+
default = false
62+
primary = true
63+
fallback_registry = codefresh_registry.some_other_registry.id
64+
65+
spec {
66+
<provider_name> {
67+
# some specific fields here
68+
}
69+
}
70+
}
71+
```
72+
73+
74+
### Common fields
75+
76+
* `name` - `(Required)` some unique name for registry
77+
* `default` - `(Optional, Default = false)` see the [Default Registry](https://codefresh.io/docs/docs/integrations/docker-registries/#the-default-registry)
78+
* `primary` - `(Optional, Default = true)` see the [Multiple Registries](https://codefresh.io/docs/docs/ci-cd-guides/working-with-docker-registries/#working-with-multiple-registries-with-the-same-domain)
79+
* `fallback_registry` - `(Optional)` see the [Fallback Registry](https://codefresh.io/docs/docs/integrations/docker-registries/#fallback-registry)
80+
81+
82+
### Default registry usage
83+
84+
If you want to manage default registry by Codefresh terraform provider correctly,
85+
you need to mark only one registry as `default = true`
86+
87+
```hcl
88+
resource "codefresh_registry" "dockerhub" {
89+
name = "dockerhub"
90+
91+
spec {
92+
dockerhub {
93+
# some specific fields here
94+
}
95+
}
96+
}
97+
98+
# this registry will be default
99+
resource "codefresh_registry" "gcr" {
100+
name = "gcr"
101+
default = true
102+
fallback_registry = codefresh_registry.some_other_registry.id
103+
104+
spec {
105+
gcr {
106+
# some specific fields here
107+
}
108+
}
109+
}
110+
```
111+
112+
### Primary registry usage
113+
114+
If you are using [Multiple Registries](https://codefresh.io/docs/docs/ci-cd-guides/working-with-docker-registries/#working-with-multiple-registries-with-the-same-domain) feature
115+
you need to manually mark each registry of the same domain as non-primary and only one as primary
116+
117+
```hcl
118+
# this registry will be primary
119+
resource "codefresh_registry" "dockerhub" {
120+
name = "dockerhub"
121+
primary = true
122+
123+
spec {
124+
dockerhub {
125+
# some specific fields here
126+
}
127+
}
128+
}
129+
130+
resource "codefresh_registry" "dockerhub1" {
131+
name = "dockerhub1"
132+
primary = false
133+
134+
spec {
135+
dockerhub {
136+
# some specific fields here
137+
}
138+
}
139+
}
140+
141+
resource "codefresh_registry" "dockerhub2" {
142+
name = "dockerhub2"
143+
primary = false
144+
145+
spec {
146+
dockerhub {
147+
# some specific fields here
148+
}
149+
}
150+
}
151+
```
152+
153+
### Fallback registry usage
154+
155+
If you want to use one of your registries as fallback you need to specify its id
156+
for `fallback_registry` field of another registry
157+
158+
```hcl
159+
resource "codefresh_registry" "dockerhub" {
160+
name = "dockerhub"
161+
162+
spec {
163+
dockerhub {
164+
# some specific fields here
165+
}
166+
}
167+
}
168+
169+
resource "codefresh_registry" "gcr" {
170+
name = "gcr"
171+
172+
# here we take the id of "dockerhub" registry
173+
fallback_registry = codefresh_registry.dockerhub.id
174+
175+
spec {
176+
gcr {
177+
# some specific fields here
178+
}
179+
}
180+
}
181+
```
182+
183+
## Argument Reference
184+
185+
- `name` - _(Required)_ some unique name for registry
186+
- `default` - _(Optional, Default = false)_ default registry
187+
- `primary` - _(Optional, Default = true)_ primary registry
188+
- `fallback_registry` - _(Optional)_ fallback registry
189+
- `spec` - _(Required)_ A `spec` block as documented below.
190+
191+
---
192+
193+
`spec` supports the following (Note: only 1 of the below can be specified at any time):
194+
195+
- dockerhub - _(Optional)_ A `dockerhub` block as documented below ([Docker Hub Registry](https://codefresh.io/docs/docs/integrations/docker-registries/docker-hub/))
196+
- acr - _(Optional)_ An `acr` block as documented below ([Azure Container Registry](https://codefresh.io/docs/docs/integrations/docker-registries/azure-docker-registry))
197+
- gcr - _(Optional)_ A `gcr` block as documented below ([Google Container Registry](https://codefresh.io/docs/docs/integrations/docker-registries/google-container-registry))
198+
- gar - _(Optional)_ A `gar` block as documented below ([Google Artifact Registry](https://codefresh.io/docs/docs/integrations/docker-registries/google-artifact-registry))
199+
- ecr - _(Optional)_ An `ecr` block as documented below ([Amazon EC2 Container Registry](https://codefresh.io/docs/docs/integrations/docker-registries/amazon-ec2-container-registry))
200+
- bintray - _(Optional)_ A `bintray` block as documented below ([Bintray / Artifactory](https://codefresh.io/docs/docs/integrations/docker-registries/bintray-io))
201+
- other - _(Optional)_ `other` provider block described below ([Other Providers](https://codefresh.io/docs/docs/integrations/docker-registries/other-registries)).
202+
203+
204+
---
205+
206+
`dockerhub` supports the following:
207+
208+
- `username` - _(Required)_ String.
209+
- `password` - _(Required, Sensitive)_ String.
210+
211+
---
212+
213+
`acr` supports the following:
214+
215+
- `domain` - _(Required)_ String representing your acr registry domain.
216+
- `client_id` - _(Required)_ String representing client id.
217+
- `client_secret` - _(Required)_ String representing client secret.
218+
- `repository_prefix` - _(Optional)_ String. See the [docs](https://codefresh.io/docs/docs/integrations/docker-registries/#using-an-optional-repository-prefix).
219+
220+
---
221+
222+
`gcr` supports the following:
223+
224+
- `domain` - _(Required)_ String representing one of the Google's gcr domains
225+
- `keyfile` - _(Required)_ String representing service account json file contents
226+
- `repository_prefix` - _(Optional)_ String. See the [docs](https://codefresh.io/docs/docs/integrations/docker-registries/#using-an-optional-repository-prefix).
227+
228+
---
229+
230+
`gar` supports the following:
231+
232+
- `location` - _(Required)_ String representing one of the Google's gar locations
233+
- `keyfile` - _(Required)_ String representing service account json file contents
234+
- `repository_prefix` - _(Optional)_ String. See the [docs](https://codefresh.io/docs/docs/integrations/docker-registries/#using-an-optional-repository-prefix).
235+
236+
---
237+
238+
`ecr` supports the following:
239+
240+
- `region` - _(Required)_ String representing one of the Amazon regions
241+
- `access_key_id` - _(Required)_ String representing access key id
242+
- `secret_access_key` - _(Required)_ String representing secret access key
243+
- `repository_prefix` - _(Optional)_ String. See the [docs](https://codefresh.io/docs/docs/integrations/docker-registries/#using-an-optional-repository-prefix).
244+
245+
---
246+
247+
`bintray` supports the following:
248+
249+
- `domain` - _(Required)_ String representing the bintray domain
250+
- `username` - _(Required)_ String representing the username
251+
- `token` - _(Required)_ String representing token
252+
- `repository_prefix` - _(Optional)_ String. See the [docs](https://codefresh.io/docs/docs/integrations/docker-registries/#using-an-optional-repository-prefix).
253+
254+
---
255+
256+
`other` supports the following:
257+
258+
- `domain` - _(Required)_ String representing the bintray domain
259+
- `username` - _(Required)_ String representing the username
260+
- `password` - _(Required)_ String representing token
261+
- `repository_prefix` - _(Optional)_ String. See the [docs](https://codefresh.io/docs/docs/integrations/docker-registries/#using-an-optional-repository-prefix).
262+
- `behind_firewall` - _(Optional, Default = false)_ Bool. See the [docs](https://codefresh.io/docs/docs/administration/behind-the-firewall/#accessing-an-internal-docker-registry).
263+
264+
---

0 commit comments

Comments
 (0)