Skip to content

Commit

Permalink
Add deploy of demo + agent to staging
Browse files Browse the repository at this point in the history
  • Loading branch information
mackjmr committed Aug 16, 2023
1 parent e8318c8 commit 113bcbd
Show file tree
Hide file tree
Showing 10 changed files with 366 additions and 16 deletions.
68 changes: 60 additions & 8 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ variables:
RESTORE_CACHE_ATTEMPTS: 2
BUILD_DD_REGISTRY: registry.ddbuild.io/ci/opentelemetry-demo
BUILD_DEMO_REGISTRY: 172597598159.dkr.ecr.us-east-1.amazonaws.com/otel-demo
BUILD_SANDBOX_REGISTRY: 601427279990.dkr.ecr.us-east-1.amazonaws.com/otel-demo
stages:
- build
- prod-deploy
- staging-deploy
# =======================================================================
# Build and deploy the images used for CI
# =======================================================================
Expand All @@ -17,9 +19,13 @@ stages:
image: $CI_IMAGE
script:
- TAG="v$CI_COMMIT_SHORT_SHA-$IMAGE_TAG_SUFFIX"
- docker build --file $DOCKERFILE --tag $BUILD_DD_REGISTRY:$TAG --tag $BUILD_DEMO_REGISTRY:$TAG --label target=staging $CONTEXT
- docker push $BUILD_DD_REGISTRY:$TAG
- docker push $BUILD_DEMO_REGISTRY:$TAG
- docker build --file $DOCKERFILE --tag $BUILD_SANDBOX_REGISTRY:$TAG --tag $BUILD_DEMO_REGISTRY:$TAG --label target=staging $CONTEXT
- if [[ $CI_COMMIT_REF_NAME =~ -staging$ ]]; then
docker push $BUILD_SANDBOX_REGISTRY:$TAG;
fi
- if [[ $CI_COMMIT_REF_NAME == "prod" ]]; then
docker push $BUILD_DEMO_REGISTRY:$TAG;
fi
build-ci-image-accountingservice:
!!merge <<: *build-ci-image
variables:
Expand Down Expand Up @@ -116,9 +122,10 @@ build-ci-image-shippingservice:
image: $CI_IMAGE
script:
- TAG="v$CI_COMMIT_SHORT_SHA-$IMAGE_TAG_SUFFIX"
- docker buildx build --file $DOCKERFILE --tag $BUILD_DD_REGISTRY:$TAG --tag $BUILD_DEMO_REGISTRY:$TAG --label target=staging $CONTEXT
- docker buildx build --file $DOCKERFILE --tag $BUILD_DD_REGISTRY:$TAG --tag $BUILD_DEMO_REGISTRY:$TAG --tag $BUILD_SANDBOX_REGISTRY:$TAG --label target=staging $CONTEXT
- docker push $BUILD_DD_REGISTRY:$TAG
- docker push $BUILD_DEMO_REGISTRY:$TAG
- docker push $BUILD_SANDBOX_REGISTRY:$TAG
variables:
DOCKERFILE: src/shippingservice/Dockerfile
IMAGE_TAG_SUFFIX: shippingservice
Expand All @@ -141,19 +148,15 @@ build-ci-image-orderproducer:
image: $CI_IMAGE
rules:
- if: '$CI_COMMIT_REF_NAME == "prod"'
- if: '$CI_COMMIT_REF_NAME =~ /-staging$/'
script:
# # For debugging
#- aws sts get-caller-identity
- >-
TEMP_AWS_ACCESS_KEY_ID=$(aws ssm get-parameter --region us-east-1 --name ci.opentelemetry-demo.eks_access_key --with-decryption --query Parameter.Value --out text)
- >-
TEMP_AWS_SECRET_ACCESS_KEY=$(aws ssm get-parameter --region us-east-1 --name ci.opentelemetry-demo.eks_secret_access_key --with-decryption --query Parameter.Value --out text)
- >-
TEMP_DD_API_KEY=$(aws ssm get-parameter --region us-east-1 --name ci.opentelemetry-demo.dd-demo-api --with-decryption --query Parameter.Value --out text)
- export AWS_ACCESS_KEY_ID=$TEMP_AWS_ACCESS_KEY_ID
- export AWS_SECRET_ACCESS_KEY=$TEMP_AWS_SECRET_ACCESS_KEY
- export DD_API_KEY=$TEMP_DD_API_KEY
# # For debugging
# - aws sts get-caller-identity
- bash $SCRIPT $CLUSTER_NAME $CLUSTER_ARN $REGION $NAMESPACE
Expand Down Expand Up @@ -181,3 +184,52 @@ prod-deploy-otel-ingest-agent-eks:
CLUSTER_ARN: arn:aws:eks:us-east-2:172597598159:cluster/otel-ingest-demo
REGION: us-east-2
NAMESPACE: otel-ingest
VALUES: ./ci/datadog-agent-values-prod.yaml
.staging-deploy: &staging-deploy
stage: staging-deploy
tags: ["runner:docker", "size:large"]
image: $CI_IMAGE
rules:
- if: '$CI_COMMIT_REF_NAME =~ /-staging$/'
script:
# # For debugging
#- aws sts get-caller-identity
- >-
TEMP_AWS_ACCESS_KEY_ID=$(aws ssm get-parameter --region us-east-1 --name ci.opentelemetry-demo.sand-eks-deploy-api-key --with-decryption --query Parameter.Value --out text)
- >-
TEMP_AWS_SECRET_ACCESS_KEY=$(aws ssm get-parameter --region us-east-1 --name ci.opentelemetry-demo.sand-eks-deploy-access-key --with-decryption --query Parameter.Value --out text)
- export AWS_ACCESS_KEY_ID=$TEMP_AWS_ACCESS_KEY_ID
- export AWS_SECRET_ACCESS_KEY=$TEMP_AWS_SECRET_ACCESS_KEY
# # For debugging
# - aws sts get-caller-identity
- bash $SCRIPT

staging-deploy-otel-demo-eks:
!!merge <<: *staging-deploy
variables:
NAMESPACE: otel-staging
VALUES: ./ci/values-staging.yaml
NODE_GROUP: ng-3
SCRIPT: ./ci/scripts/ci-deploy-demo-staging.sh
CLUSTER_NAME: dd-otel
CLUSTER_ARN: "arn:aws:eks:us-east-1:601427279990:cluster/dd-otel"
REGION: us-east-1
staging-deploy-otel-ingest-demo-eks:
!!merge <<: *staging-deploy
variables:
NAMESPACE: otel-ingest-staging
VALUES: ./ci/values-ingest-staging.yaml
NODE_GROUP: ng-4
SCRIPT: ./ci/scripts/ci-deploy-demo-staging.sh
CLUSTER_NAME: dd-otel
CLUSTER_ARN: "arn:aws:eks:us-east-1:601427279990:cluster/dd-otel"
REGION: us-east-1
staging-deploy-otel-ingest-agent-eks:
!!merge <<: *staging-deploy
variables:
NAMESPACE: otel-ingest-staging
SCRIPT: ./ci/scripts/ci-deploy-agent.sh
CLUSTER_NAME: dd-otel
CLUSTER_ARN: "arn:aws:eks:us-east-1:601427279990:cluster/dd-otel"
REGION: us-east-1
VALUES: ./ci/datadog-agent-values-staging.yaml
3 changes: 3 additions & 0 deletions ci/datadog-agent-values-prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
datadog:
tags:
- "env:otel-ingest"
6 changes: 6 additions & 0 deletions ci/datadog-agent-values-staging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
agents:
nodeSelector:
alpha.eksctl.io/nodegroup-name: ng-4
datadog:
tags:
- "env:otel-ingest-staging"
10 changes: 8 additions & 2 deletions ci/datadog-agent-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ agents:
image:
tagSuffix: jmx
datadog:
apiKey: $DD_API_KEY
logs:
enabled: true
tags:
- "env:otel-ingest"
otlp:
receiver:
protocols:
grpc:
enabled: true
http:
enabled: true
env:
- name: DD_API_KEY
valueFrom:
secretKeyRef:
name: datadog-secrets
key: api-key
optional: false
14 changes: 8 additions & 6 deletions ci/scripts/ci-deploy-agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
set -euo pipefail
IFS=$'\n\t'

clusterName=$1
clusterArn=$2
region=$3
namespace=$4
clusterName=$CLUSTER_NAME
clusterArn=$CLUSTER_ARN
region=$REGION
namespace=$NAMESPACE
values=$VALUES

install_agent() {
# Set the namespace and release name
release_name="datadog-agent"
Expand All @@ -21,8 +23,8 @@ install_agent() {

# --install will run `helm install` if not already present.
helm upgrade "${release_name}" -n "${namespace}" datadog/datadog --install \
-f ./ci/datadog-agent-values.yaml --set datadog.apiKey=$DD_API_KEY

-f ./ci/datadog-agent-values.yaml \
-f "${values}"
}

###########################################################################################################
Expand Down
48 changes: 48 additions & 0 deletions ci/scripts/ci-deploy-demo-staging.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash

# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

# This script is used to deploy collector on demo account cluster

set -euo pipefail
IFS=$'\n\t'
set -x

clusterName=$CLUSTER_NAME
clusterArn=$CLUSTER_ARN
region=$REGION
namespace=$NAMESPACE
nodeGroup=$NODE_GROUP
values=$VALUES

install_demo() {
# Set the namespace and release name
release_name="opentelemetry-demo"

# Deploy zookeeper which is not a default component.
sed -i "s/PLACEHOLDER_NODE_GROUP/v$nodeGroup/g" ./src/zookeeperservice/deployment-staging.yaml
kubectl apply -f ./src/zookeeperservice/deployment-staging.yaml -n "${namespace}"

# if repo already exists, helm 3+ will skip
helm --debug repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts

# --install will run `helm install` if not already present.
helm --debug upgrade "${release_name}" -n "${namespace}" open-telemetry/opentelemetry-demo --install \
-f ./ci/values.yaml \
-f $values \
--set-string default.image.tag="v$CI_COMMIT_SHORT_SHA" \
--set-string default.image.repository="601427279990.dkr.ecr.us-east-1.amazonaws.com/otel-demo"

# Deploy java order producer which is not a default component.
sed -i "s/PLACEHOLDER_COMMIT_SHA/v$CI_COMMIT_SHORT_SHA/g" ./src/orderproducerservice/deployment-staging.yaml
sed -i "s/PLACEHOLDER_NODE_GROUP/v$nodeGroup/g" ./src/orderproducerservice/deployment-staging.yaml
kubectl apply -f ./src/orderproducerservice/deployment-staging.yaml -n "${namespace}"
}

###########################################################################################################

aws eks --region "${region}" update-kubeconfig --name "${clusterName}"
kubectl config use-context "${clusterArn}"

install_demo
4 changes: 4 additions & 0 deletions ci/values-ingest-staging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
default:
schedulingRules:
nodeSelector:
alpha.eksctl.io/nodegroup-name: ng-4
4 changes: 4 additions & 0 deletions ci/values-staging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
default:
schedulingRules:
nodeSelector:
alpha.eksctl.io/nodegroup-name: ng-3
142 changes: 142 additions & 0 deletions src/orderproducerservice/deployment-staging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: opentelemetry-demo-orderproducer
labels:
app.kubernetes.io/component: orderproducer
app.kubernetes.io/instance: opentelemetry-demo
app.kubernetes.io/name: opentelemetry-demo-orderproducer
app.kubernetes.io/part-of: opentelemetry-demo
app.kubernetes.io/version: "1.4.0"
spec:
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app.kubernetes.io/name: opentelemetry-demo-orderproducer
template:
metadata:
annotations:
ad.datadoghq.com/orderproducer.logs: '[{"source":"kafka","service":"orderproducer"}]'
ad.datadoghq.com/orderproducer.checks: |
{
"kafka": {
"init_config": {
"is_jmx": true,
"collect_default_metrics": true
},
"instances": [
{
"host": "opentelemetry-demo-orderproducer",
"port": "1097",
"tags": [
"kafka_source:agent"
]
}
]
}
}
labels:
app.kubernetes.io/component: orderproducer
app.kubernetes.io/instance: opentelemetry-demo
app.kubernetes.io/name: opentelemetry-demo-orderproducer
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: alpha.eksctl.io/nodegroup-name
operator: In
values:
- ng-4
initContainers:
- command:
- sh
- -c
- until nc -z -v -w30 opentelemetry-demo-kafka 9092; do echo waiting
for kafka; sleep 2; done;
image: busybox:latest
name: wait-for-kafka
containers:
- name: orderproducer
image: 601427279990.dkr.ecr.us-east-1.amazonaws.com/otel-demo:PLACEHOLDER_COMMIT_SHA-orderproducer
imagePullPolicy: IfNotPresent
ports:
- containerPort: 1097
name: producerjmx
protocol: TCP
env:
- name: KAFKA_SERVICE_ADDR
value: "opentelemetry-demo-kafka:9092"
- name: HOST_IP
valueFrom:
fieldRef:
fieldPath: status.hostIP
- name: OTEL_SERVICE_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: "metadata.labels['app.kubernetes.io/component']"
- name: OTEL_K8S_NAMESPACE
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
- name: OTEL_K8S_NODE_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: spec.nodeName
- name: OTEL_K8S_POD_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
- name: OTEL_K8S_POD_UID
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.uid
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: HOST_IP
valueFrom:
fieldRef:
fieldPath: status.hostIP
- name: OTEL_COLLECTOR_NAME
value: $(HOST_IP)
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: http://$(OTEL_COLLECTOR_NAME):4317
- name: OTEL_RESOURCE_ATTRIBUTES
value: >-
service.name=$(OTEL_SERVICE_NAME),
service.instance.id=$(OTEL_K8S_POD_UID),
service.namespace=opentelemetry-demo,
k8s.namespace.name=$(OTEL_K8S_NAMESPACE),
k8s.node.name=$(OTEL_K8S_NODE_NAME),
k8s.pod.name=$(OTEL_K8S_POD_NAME),
deployment.environment=$(OTEL_K8S_NAMESPACE),
k8s.pod.ip=$(POD_IP)
resources:
limits:
memory: 1Gi
securityContext:
runAsGroup: 1000
runAsNonRoot: true
runAsUser: 1000
---
apiVersion: v1
kind: Service
metadata:
name: opentelemetry-demo-orderproducer
spec:
selector:
app.kubernetes.io/name: opentelemetry-demo-orderproducer
ports:
- name: orderproducer
port: 1097
protocol: TCP
targetPort: 1097
Loading

0 comments on commit 113bcbd

Please sign in to comment.