Skip to content

Commit

Permalink
feat: [TKC-2684] docker image version (#5918)
Browse files Browse the repository at this point in the history
* feat: docker image version

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: format json

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: pass docker_image_version arg

Signed-off-by: Vladislav Sukhin <[email protected]>

---------

Signed-off-by: Vladislav Sukhin <[email protected]>
  • Loading branch information
vsukhin authored Oct 11, 2024
1 parent 2847b2f commit f303b6e
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 47 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ jobs:
segmentio_key=${{secrets.TESTKUBE_SEGMENTIO_KEY}}
ga_id=${{secrets.TESTKUBE_CLI_GA_MEASUREMENT_ID}}
ga_secret=${{secrets.TESTKUBE_CLI_GA_MEASUREMENT_SECRET}}
docker_image_version=${{steps.tag.outputs.tag}}
context: build/kind
file: build/kind/kind.Dockerfile
platforms: linux/amd64,linux/arm64/v8
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ jobs:
segmentio_key=${{secrets.TESTKUBE_SEGMENTIO_KEY}}
ga_id=${{secrets.TESTKUBE_CLI_GA_MEASUREMENT_ID}}
ga_secret=${{secrets.TESTKUBE_CLI_GA_MEASUREMENT_SECRET}}
docker_image_version=${{steps.tag.outputs.tag}}
context: build/kind
file: build/kind/kind.Dockerfile
platforms: linux/amd64,linux/arm64
Expand Down
4 changes: 4 additions & 0 deletions api/v1/testkube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6217,6 +6217,10 @@ components:
items:
type: string
example: my-namespace
dockerImageVersion:
type: string
description: docker image version
example: "2.1.2"

Repository:
description: repository representation for tests in git repositories
Expand Down
62 changes: 31 additions & 31 deletions build/kind/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,21 @@ send_event_to_segment() {
# Prepare the JSON payload
local payload=$(cat <<EOF
{
"userId": "$machine_id",
"event": "$event",
"userId": "$machine_id",
"event": "$event",
"properties": {
"name": "testkube-api-server",
"version": "$version",
"arch": "$arch",
"os": "$os",
"eventCategory": "api",
"containerEnv": "docker",
"contextType": "agent",
"machineId": "$machine_id",
"clusterType": "kind",
"errorType": "$error_type",
"errorCode": "$error_code",
"agentKey": "$AGENT_KEY"
"name": "testkube-api-server",
"version": "$version",
"arch": "$arch",
"os": "$os",
"eventCategory": "api",
"contextType": "agent",
"machineId": "$machine_id",
"clusterType": "kind",
"errorType": "$error_type",
"errorCode": "$error_code",
"agentKey": "$AGENT_KEY",
"dockerImageVersion": "$DOCKER_IMAGE_VERSION"
},
"context": {
"app": {
Expand Down Expand Up @@ -117,26 +117,26 @@ send_event_to_ga() {
# Prepare the JSON payload
local payload=$(cat <<EOF
{
"client_id": "$machine_id",
"user_id": "$machine_id",
"client_id": "$machine_id",
"user_id": "$machine_id",
"events": [{
"name": "$event",
"name": "$event",
"params": {
"event_count": 1,
"event_category": "api",
"app_version": "$version",
"app_name": "testkube-api-server",
"machine_id": "$machine_id",
"operating_system": "$os",
"architecture": "$arch",
"event_count": 1,
"event_category": "api",
"app_version": "$version",
"app_name": "testkube-api-server",
"machine_id": "$machine_id",
"operating_system": "$os",
"architecture": "$arch",
"context": {
"container_env": "docker",
"type": "agent"
"docker_image_version": "$DOCKER_IMAGE_VERSION",
"type": "agent"
},
"cluster_type": "kind",
"error_type": "$error_type",
"error_code": "$error_code",
"agent_key": "$AGENT_KEY"
"cluster_type": "kind",
"error_type": "$error_type",
"error_code": "$error_code",
"agent_key": "$AGENT_KEY"
}
}]
}
Expand Down Expand Up @@ -226,7 +226,7 @@ else

# Step 7: Install Testkube using Helm
log "Installing Testkube via Helm..."
helm install testkube testkube/testkube --namespace testkube --create-namespace --set testkube-api.cloud.key=$AGENT_KEY --set testkube-api.minio.enabled=false --set mongodb.enabled=false --set testkube-dashboard.enabled=false --set testkube-api.cloud.url=$CLOUD_URL --set testkube-api.containerEnv=docker
helm install testkube testkube/testkube --namespace testkube --create-namespace --set testkube-api.cloud.key=$AGENT_KEY --set testkube-api.minio.enabled=false --set mongodb.enabled=false --set testkube-dashboard.enabled=false --set testkube-api.cloud.url=$CLOUD_URL --set testkube-api.dockerImageVersion=$DOCKER_IMAGE_VERSION
if [ $? -ne 0 ]; then
log "Testkube installation failed."
send_telenetry "docker_installation_failed" "helm_error" "Testkube installation failed"
Expand Down
2 changes: 2 additions & 0 deletions build/kind/kind.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ ARG ga_id
ENV GA_ID=$ga_id
ARG ga_secret

Check warning on line 35 in build/kind/kind.Dockerfile

View workflow job for this annotation

GitHub Actions / Build a Docker image for Testkube Agent

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ARG "ga_secret") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/
ENV GA_SECRET=$ga_secret

Check warning on line 36 in build/kind/kind.Dockerfile

View workflow job for this annotation

GitHub Actions / Build a Docker image for Testkube Agent

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ENV "GA_SECRET") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/
ARG docker_image_version
ENV DOCKER_IMAGE_VERSION=$docker_image_version

# Step 8: Set Docker entry point for DIND (Docker-in-Docker)
ENTRYPOINT ["tini", "--", "/usr/local/bin/entrypoint.sh"]
1 change: 1 addition & 0 deletions cmd/api-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ func main() {
subscriptionChecker,
serviceAccountNames,
envs,
cfg.TestkubeDockerImageVersion,
)

if mode == common.ModeAgent {
Expand Down
1 change: 1 addition & 0 deletions internal/app/api/v1/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func (s *TestkubeAPI) InfoHandler() fiber.Handler {
LogsV2: s.featureFlags.LogsV2,
},
ExecutionNamespaces: executionNamespaces,
DockerImageVersion: s.dockerImageVersion,
})
}
}
Expand Down
3 changes: 3 additions & 0 deletions internal/app/api/v1/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func NewTestkubeAPI(
subscriptionChecker checktcl.SubscriptionChecker,
serviceAccountNames map[string]string,
envs map[string]string,
dockerImageVersion string,
) TestkubeAPI {

var httpConfig server.Config
Expand Down Expand Up @@ -165,6 +166,7 @@ func NewTestkubeAPI(
LabelSources: common.Ptr(make([]LabelSource, 0)),
ServiceAccountNames: serviceAccountNames,
Envs: envs,
dockerImageVersion: dockerImageVersion,
}
}

Expand Down Expand Up @@ -214,6 +216,7 @@ type TestkubeAPI struct {
LabelSources *[]LabelSource
ServiceAccountNames map[string]string
Envs map[string]string
dockerImageVersion string
}

type storageParams struct {
Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ type Config struct {
TestkubeDefaultStorageClassName string `envconfig:"TESTKUBE_DEFAULT_STORAGE_CLASS_NAME" default:""`
GlobalWorkflowTemplateName string `envconfig:"TESTKUBE_GLOBAL_WORKFLOW_TEMPLATE_NAME" default:""`
EnableK8sEvents bool `envconfig:"ENABLE_K8S_EVENTS" default:"true"`
TestkubeDockerImageVersion string `envconfig:"TESTKUBE_DOCKER_IMAGE_VERSION" default:""`

// DEPRECATED: Use TestkubeProAPIKey instead
TestkubeCloudAPIKey string `envconfig:"TESTKUBE_CLOUD_API_KEY" default:""`
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/v1/testkube/model_server_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ type ServerInfo struct {
Features *Features `json:"features,omitempty"`
// execution namespaces
ExecutionNamespaces []string `json:"executionNamespaces,omitempty"`
// docker image version
DockerImageVersion string `json:"dockerImageVersion,omitempty"`
}
25 changes: 10 additions & 15 deletions pkg/telemetry/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (
)

const (
runContextAgent = "agent"
containerEnvKubernetes = "kubernetes"
runContextAgent = "agent"
)

type Params struct {
Expand Down Expand Up @@ -89,10 +88,10 @@ type RunParams struct {
}

type RunContext struct {
Type string
OrganizationId string
EnvironmentId string
ContainerEnv string
Type string
OrganizationId string
EnvironmentId string
DockerImageVersion string
}

type WorkflowParams struct {
Expand Down Expand Up @@ -345,18 +344,14 @@ func AnonymizeHost(host string) string {
func getAgentContext() RunContext {
orgID := utils.GetEnvVarWithDeprecation("TESTKUBE_PRO_ORG_ID", "TESTKUBE_CLOUD_ORG_ID", "")
envID := utils.GetEnvVarWithDeprecation("TESTKUBE_PRO_ENV_ID", "TESTKUBE_CLOUD_ENV_ID", "")
containerEnv := os.Getenv("TESTKUBE_CONTAINER_ENV")
if containerEnv == "" {
containerEnv = containerEnvKubernetes
}

dockerImageVersion := os.Getenv("TESTKUBE_DOCKER_IMAGE_VERSION")
if orgID == "" || envID == "" {
return RunContext{}
}
return RunContext{
Type: runContextAgent,
EnvironmentId: envID,
OrganizationId: orgID,
ContainerEnv: containerEnv,
Type: runContextAgent,
EnvironmentId: envID,
OrganizationId: orgID,
DockerImageVersion: dockerImageVersion,
}
}
2 changes: 1 addition & 1 deletion pkg/telemetry/sender_sio.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func mapProperties(name string, params Params) analytics.Properties {
Set("clusterId", params.ClusterID).
Set("eventCategory", params.EventCategory).
Set("host", params.Host).
Set("containerEnv", params.Context.ContainerEnv).
Set("dockerImageVersion", params.Context.DockerImageVersion).
Set("contextType", params.Context.Type).
Set("cloudOrganizationId", params.Context.OrganizationId).
Set("cloudEnvironmentId", params.Context.EnvironmentId).
Expand Down

0 comments on commit f303b6e

Please sign in to comment.