Skip to content

Commit

Permalink
apps: support specifying images by digest (#1295)
Browse files Browse the repository at this point in the history
* apps: support specifying images by digest

* Update digitalocean/app/app_spec.go

Co-authored-by: Anna Lushnikova <[email protected]>

---------

Co-authored-by: Anna Lushnikova <[email protected]>
  • Loading branch information
andrewsomething and loosla authored Jan 6, 2025
1 parent 6f15115 commit dcdeef2
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
9 changes: 8 additions & 1 deletion digitalocean/app/app_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,12 @@ func appSpecImageSourceSchema() map[string]*schema.Schema {
"tag": {
Type: schema.TypeString,
Optional: true,
Description: "The repository tag. Defaults to latest if not provided.",
Description: "The repository tag. Defaults to latest if not provided. Cannot be specified if digest is provided.",
},
"digest": {
Type: schema.TypeString,
Optional: true,
Description: "The image digest. Cannot be specified if tag is provided.",
},
"deploy_on_push": {
Type: schema.TypeList,
Expand Down Expand Up @@ -1603,6 +1608,7 @@ func expandAppImageSourceSpec(config []interface{}) *godo.ImageSourceSpec {
Registry: imageSourceConfig["registry"].(string),
Repository: imageSourceConfig["repository"].(string),
Tag: imageSourceConfig["tag"].(string),
Digest: imageSourceConfig["digest"].(string),
RegistryCredentials: imageSourceConfig["registry_credentials"].(string),
}

Expand All @@ -1626,6 +1632,7 @@ func flattenAppImageSourceSpec(i *godo.ImageSourceSpec) []interface{} {
r["registry"] = (*i).Registry
r["repository"] = (*i).Repository
r["tag"] = (*i).Tag
r["digest"] = (*i).Digest
r["registry_credentials"] = (*i).RegistryCredentials

if i.DeployOnPush != nil {
Expand Down
52 changes: 52 additions & 0 deletions digitalocean/app/resource_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,35 @@ func TestAccDigitalOceanApp_autoScale(t *testing.T) {
})
}

func TestAccDigitalOceanApp_ImageDigest(t *testing.T) {
var app godo.App
appName := acceptance.RandomTestName()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
Providers: acceptance.TestAccProviders,
CheckDestroy: testAccCheckDigitalOceanAppDestroy,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(testAccCheckDigitalOceanAppConfig_imageDigest, appName),
Check: resource.ComposeTestCheckFunc(
testAccCheckDigitalOceanAppExists("digitalocean_app.foobar", &app),
resource.TestCheckResourceAttrSet("digitalocean_app.foobar", "live_url"),
resource.TestCheckResourceAttrSet("digitalocean_app.foobar", "live_domain"),
resource.TestCheckResourceAttr(
"digitalocean_app.foobar", "spec.0.service.0.image.0.registry_type", "DOCKER_HUB"),
resource.TestCheckResourceAttr(
"digitalocean_app.foobar", "spec.0.service.0.image.0.registry", "ubuntu"),
resource.TestCheckResourceAttr(
"digitalocean_app.foobar", "spec.0.service.0.image.0.repository", "nginx"),
resource.TestCheckResourceAttr(
"digitalocean_app.foobar", "spec.0.service.0.image.0.digest", "sha256:909169d4de5b750071dc2cbe286e18763f8ed23dd0f267b5db59ea33bdbf8853"),
),
},
},
})
}

var testAccCheckDigitalOceanAppConfig_basic = `
resource "digitalocean_app" "foobar" {
spec {
Expand Down Expand Up @@ -1233,6 +1262,29 @@ resource "digitalocean_app" "foobar" {
}
}`

var testAccCheckDigitalOceanAppConfig_imageDigest = `
resource "digitalocean_app" "foobar" {
spec {
name = "%s"
region = "nyc"
service {
name = "image-service"
instance_count = 1
instance_size_slug = "apps-s-1vcpu-1gb"
image {
registry_type = "DOCKER_HUB"
registry = "ubuntu"
repository = "nginx"
digest = "sha256:909169d4de5b750071dc2cbe286e18763f8ed23dd0f267b5db59ea33bdbf8853"
}
http_port = 80
}
}
}`

var testAccCheckDigitalOceanAppConfig_addInternalPort = `
resource "digitalocean_app" "foobar" {
spec {
Expand Down
3 changes: 3 additions & 0 deletions docs/data-sources/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ A `service` can contain:
- `registry` - The registry name. Must be left empty for the `DOCR` registry type. Required for the `DOCKER_HUB` registry type.
- `repository` - The repository name.
- `tag` - The repository tag. Defaults to `latest` if not provided.
- `digest` - The image digest. Cannot be specified if `tag` is provided.
- `deploy_on_push` - Configures automatically deploying images pushed to DOCR.
- `enabled` - Whether to automatically deploy images pushed to DOCR.
* `env` - Describes an environment variable made available to an app competent.
Expand Down Expand Up @@ -170,6 +171,7 @@ A `worker` can contain:
- `registry` - The registry name. Must be left empty for the `DOCR` registry type. Required for the `DOCKER_HUB` registry type.
- `repository` - The repository name.
- `tag` - The repository tag. Defaults to `latest` if not provided.
- `digest` - The image digest. Cannot be specified if `tag` is provided.
- `deploy_on_push` - Configures automatically deploying images pushed to DOCR.
- `enabled` - Whether to automatically deploy images pushed to DOCR.
* `env` - Describes an environment variable made available to an app competent.
Expand Down Expand Up @@ -225,6 +227,7 @@ A `job` can contain:
- `registry` - The registry name. Must be left empty for the `DOCR` registry type. Required for the `DOCKER_HUB` registry type.
- `repository` - The repository name.
- `tag` - The repository tag. Defaults to `latest` if not provided.
- `digest` - The image digest. Cannot be specified if `tag` is provided.
- `deploy_on_push` - Configures automatically deploying images pushed to DOCR.
- `enabled` - Whether to automatically deploy images pushed to DOCR.
* `env` - Describes an environment variable made available to an app competent.
Expand Down
3 changes: 3 additions & 0 deletions docs/resources/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ A `service` can contain:
- `repository` - The repository name.
- `registry_credentials` - The credentials required to access a private Docker Hub or GitHub registry, in the following syntax `<username>:<token>`.
- `tag` - The repository tag. Defaults to `latest` if not provided.
- `digest` - The image digest. Cannot be specified if `tag` is provided.
- `deploy_on_push` - Configures automatically deploying images pushed to DOCR.
- `enabled` - Whether to automatically deploy images pushed to DOCR.
- `env` - Describes an environment variable made available to an app competent.
Expand Down Expand Up @@ -376,6 +377,7 @@ A `worker` can contain:
- `repository` - The repository name.
- `registry_credentials` - The credentials required to access a private Docker Hub or GitHub registry, in the following syntax `<username>:<token>`.
- `tag` - The repository tag. Defaults to `latest` if not provided.
- `digest` - The image digest. Cannot be specified if `tag` is provided.
- `deploy_on_push` - Configures automatically deploying images pushed to DOCR.
- `enabled` - Whether to automatically deploy images pushed to DOCR.
- `env` - Describes an environment variable made available to an app competent.
Expand Down Expand Up @@ -438,6 +440,7 @@ A `job` can contain:
- `repository` - The repository name.
- `registry_credentials` - The credentials required to access a private Docker Hub or GitHub registry, in the following syntax `<username>:<token>`.
- `tag` - The repository tag. Defaults to `latest` if not provided.
- `digest` - The image digest. Cannot be specified if `tag` is provided.
- `deploy_on_push` - Configures automatically deploying images pushed to DOCR.
- `enabled` - Whether to automatically deploy images pushed to DOCR.
- `env` - Describes an environment variable made available to an app competent.
Expand Down

0 comments on commit dcdeef2

Please sign in to comment.