Skip to content

Commit

Permalink
Create Cortex Image (#2443)
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Singh Anantha <[email protected]>
  • Loading branch information
sanghanan authored Apr 5, 2024
1 parent dab54df commit cd30082
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 0 deletions.
52 changes: 52 additions & 0 deletions images/cortex/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!--monopod:start-->
# cortex
| | |
| - | - |
| **OCI Reference** | `cgr.dev/chainguard/cortex` |


* [View Image in Chainguard Academy](https://edu.chainguard.dev/chainguard/chainguard-images/reference/cortex/overview/)
* [View Image Catalog](https://console.enforce.dev/images/catalog) for a full list of available tags.
* [Contact Chainguard](https://www.chainguard.dev/chainguard-images) for enterprise support, SLAs, and access to older tags.*

---
<!--monopod:end-->

<!--overview:start-->
Cortex provides horizontally scalable, highly available, multi-tenant, long term storage for Prometheus.
<!--overview:end-->

<!--getting:start-->
## Download this Image
The image is available on `cgr.dev`:

```
docker pull cgr.dev/chainguard/cortex:latest
```
<!--getting:end-->

<!--body:start-->

## Usage
For full instructions on using cortex, refer to the
[official documentation](https://cortexmetrics.io/docs/).
The GitHub repository can also be [found here](https://github.com/cortexproject/cortex).

### Helm
To deploy cortex via helm, please refer to the
[official helm charts documentation](https://cortexproject.github.io/cortex-helm-chart/) and the [helm charts repository](https://github.com/cortexproject/cortex-helm-chart)
for comprehensive instructions, which includes
[supported parameters](https://github.com/cortexproject/cortex-helm-chart/blob/master/values.yaml)

Below is an example of how to use the helm chart, overriding the image with the
chainguard image:

```bash
helm repo add cortex-helm https://cortexproject.github.io/cortex-helm-chart
helm repo update

helm install cortex --namespace cortex cortex-helm/cortex \
--set image.repository=cgr.dev/chainguard/cortex \
--set image.tag=latest
```
<!--body:end-->
21 changes: 21 additions & 0 deletions images/cortex/config/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
terraform {
required_providers {
apko = { source = "chainguard-dev/apko" }
}
}

variable "extra_packages" {
description = "The additional packages to install"
default = [
"cortex",
]
}

data "apko_config" "this" {
config_contents = file("${path.module}/template.apko.yaml")
extra_packages = var.extra_packages
}

output "config" {
value = jsonencode(data.apko_config.this.config)
}
15 changes: 15 additions & 0 deletions images/cortex/config/template.apko.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
contents:
packages: []

accounts:
groups:
- groupname: nonroot
gid: 65532
users:
- username: nonroot
uid: 65532
gid: 65532
run-as: 65532

entrypoint:
command: cortex
38 changes: 38 additions & 0 deletions images/cortex/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
terraform {
required_providers {
oci = { source = "chainguard-dev/oci" }
}
}

variable "target_repository" {
description = "The docker repo into which the image and attestations should be published."
}

module "config" { source = "./config" }

module "cortex" {
source = "../../tflib/publisher"
name = basename(path.module)
target_repository = var.target_repository
config = module.config.config
build-dev = true

}

module "test" {
source = "./tests"
digest = module.cortex.image_ref
}

resource "oci_tag" "latest" {
depends_on = [module.test]
digest_ref = module.cortex.image_ref
tag = "latest"
}

resource "oci_tag" "latest-dev" {
depends_on = [module.test]
digest_ref = module.cortex.dev_ref
tag = "latest-dev"
}

12 changes: 12 additions & 0 deletions images/cortex/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: cortex
image: cgr.dev/chainguard/cortex
logo: https://storage.googleapis.com/chainguard-academy/logos/cortex.svg
endoflife: ""
console_summary: ""
short_description: "Cortex provides horizontally scalable, highly available, multi-tenant, long term storage for Prometheus."
compatibility_notes: ""
readme_file: README.md
upstream_url: https://cortexmetrics.io/
keywords:
- analytics
- application
75 changes: 75 additions & 0 deletions images/cortex/tests/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
terraform {
required_providers {
oci = { source = "chainguard-dev/oci" }
imagetest = { source = "chainguard-dev/imagetest" }
}
}

variable "digest" {
description = "The image digest to run tests over."
}

data "oci_string" "ref" { input = var.digest }

data "imagetest_inventory" "this" {}

resource "imagetest_harness_k3s" "this" {
name = "cortex"
inventory = data.imagetest_inventory.this
sandbox = {
mounts = [
{
source = path.module
destination = "/tests"
}
]
}
}

module "helm" {
source = "../../../tflib/imagetest/helm"

name = "cortex"
namespace = "cortex"
repo = "https://cortexproject.github.io/cortex-helm-chart"
chart = "cortex"

values = {
image = {
tag = data.oci_string.ref.pseudo_tag
repository = data.oci_string.ref.registry_repo
},
config = {
blocks_storage = {
backend = "filesystem"
filesystem = {
dir = "/data/tsdb"
}
}
},
alertmanager = {
enabled = false
},
ruler = {
enabled = false
}
}
}

resource "imagetest_feature" "basic" {
name = "Basic"
description = "Test a basic installation of Cortex Metrics"
harness = imagetest_harness_k3s.this

steps = [
{
name = "Helm install"
cmd = module.helm.install_cmd
}
]

labels = {
type = "k8s",
}
}

5 changes: 5 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@ module "coredns" {
target_repository = "${var.target_repository}/coredns"
}

module "cortex" {
source = "./images/cortex"
target_repository = "${var.target_repository}/cortex"
}

module "cosign" {
source = "./images/cosign"
target_repository = "${var.target_repository}/cosign"
Expand Down

0 comments on commit cd30082

Please sign in to comment.