Skip to content

Commit

Permalink
Adding test workflow (#52)
Browse files Browse the repository at this point in the history
* adding tests for recipes

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* testing to run test.yaml

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* fix syntax

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* fixing test.yaml

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* fixing test.yaml

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* setting output variables

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* add install radius script

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* fix test.yaml

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* rename file

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* test

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* test

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* test

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* test

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* test

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* install edge version

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* test

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* adding checkout step

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* adding execute permissions

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* path fix

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* fixing k3d create command

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* adding mongo test

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* fix syntax error

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* fix syntax error

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* remove provider

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* testing

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* adding all tests

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* adding matrix

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* testing

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* test

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* testing

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* testing

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* testing

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* testing

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* testing

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* testing

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* testing

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* testing

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* test sql

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* test-statestore

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* testing

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* adding magpie

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* fix errors

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* enable all tests

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* testSecretStores

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* fix sescret store test

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* adding pod logs

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* test uploading logs

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* fix upload logs error

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* fix test error

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* updating magpie to ghcr

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* testing

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* testing

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* remove build magpie

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* have single app to deploy all recipes

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* fix syntax error

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* remove RUN_TEST

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* addressing comments

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* addressing review comments

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* remove sql test

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* fixing sql test

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* updating wait for pods

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* upgrading dapr version

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

* adressing comments

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>

---------

Signed-off-by: Vishwanath Hiremath <vhiremath@microsoft.com>
  • Loading branch information
vishwahiremat committed Dec 7, 2023
1 parent 70fc625 commit 5cd81f3
Show file tree
Hide file tree
Showing 4 changed files with 348 additions and 1 deletion.
38 changes: 38 additions & 0 deletions .github/scripts/install-radius.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# ------------------------------------------------------------
# Copyright 2023 The Radius Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------

set -xe

VERSION=$1
RAD_CLI_URL=https://raw.githubusercontent.com/radius-project/radius/main/deploy/install.sh
RAD_CLI_EDGE_URL=ghcr.io/radius-project/rad/linux-amd64:latest

if [[ $VERSION == "edge" ]]; then
echo Downloading rad CLI edge version
oras pull $RAD_CLI_EDGE_URL
chmod +x ./rad
mv ./rad /usr/local/bin/rad
elif [[ -n $VERSION && $VERSION != *"rc"* ]]; then
INPUT_CHANNEL=$(echo $VERSION | cut -d '.' -f 1,2)
echo "Downloading rad CLI version $INPUT_CHANNEL"
wget -q $RAD_CLI_URL -O - | /bin/bash -s $INPUT_CHANNEL
elif [[ -n $VERSION ]]; then
echo Downloading rad CLI version $VERSION
wget -q $RAD_CLI_URL -O - | /bin/bash -s $VERSION
else
echo Downloading latest rad CLI
wget -q $RAD_CLI_URL -O - | /bin/bash
fi
102 changes: 102 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Test Recipes

on:
workflow_dispatch:
inputs:
version:
description: 'Radius version number to use (e.g. 0.1.0, 0.1.0-rc1, edge). Defaults to edge.'
required: false
default: 'edge'
type: string
push:
branches:
- v*.*
- edge
paths:
- "local-dev/**"
- ".github/workflows/**"
pull_request:
types: [opened, synchronize, reopened]
env:
RUN_IDENTIFIER: recipestest-${{ github.run_id }}-${{ github.run_attempt }}
APP_NAME: local-dev-recipe-app
APP_NAMESPACE: local-dev-recipe-app
jobs:
test:
name: "Recipe tests"
runs-on: [ubuntu-latest]
steps:
- name: Generate output variables
id: gen-id
run: |
# Set output variables to be used in the other jobs
echo "RUN_IDENTIFIER=${RUN_IDENTIFIER}" >> $GITHUB_OUTPUT
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16
- name: Download k3d
run: wget -q -O - https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
- name: Create k3d cluster
run: k3d cluster create --agents 2 -p "80:80@loadbalancer" --k3s-arg "--disable=traefik@server:0" --registry-create reciperegistry:51351
- name: Install Dapr
run: |
helm repo add dapr https://dapr.github.io/helm-charts/
helm install dapr dapr/dapr --version=1.12 --namespace dapr-system --create-namespace --wait
- name: Download rad CLI
run: |
RADIUS_VERSION="${{ inputs.version }}"
if [[ -z "${{ inputs.version }}" ]]; then
RADIUS_VERSION=edge
fi
chmod +x ./.github/scripts/install-radius.sh
./.github/scripts/install-radius.sh $RADIUS_VERSION
- name: Publish Recipes
run: |
files_list=$(ls "local-dev")
for file in $files_list; do
echo "Publishing recipe: local-dev/$file"
recipeName="${file%.*}"
rad bicep publish --file local-dev/$file --target br:localhost:51351/recipes/local-dev/$recipeName:latest --plain-http
done
- name: Initialize default environment
run: |
rad install kubernetes --set rp.publicEndpointOverride=localhost
rad group create default
rad workspace create kubernetes default --group default
rad group switch default
rad env create default
rad env switch default
- name: Deploy app
id: deploy-app
run: rad deploy ./tests/test-local-dev-recipes.bicep --parameters magpieimage="ghcr.io/radius-project/magpiego:latest" --parameters registry="reciperegistry:5000" --parameters version="latest"
- name: Wait for all pods to be ready
id: wait-for-pods
run: |
label="radapp.io/application=${APP_NAME}"
kubectl rollout status deployment -l $label -n ${APP_NAMESPACE} --timeout=90s
- name: Get Pod logs for failed tests
id: get-pod-logs
if: failure() && (steps.deploy-app.outcome == 'failure' || steps.wait-for-pods.outcome == 'failure')
run: |
# Create pod-logs directory
mkdir -p recipe-tests/pod-logs/local_dev_recipe_test_container_logs
# Get pod logs and save to file
label="radapp.io/application=${APP_NAME}"
pod_names=($(kubectl get pods -l $label -n ${APP_NAMESPACE} -o jsonpath='{.items[*].metadata.name}'))
for pod_name in "${pod_names[@]}"; do
kubectl logs $pod_name -n ${APP_NAMESPACE} > recipe-tests/pod-logs/local_dev_recipe_test_container_logs/${pod_name}.txt
done
echo "Pod logs saved to recipe-tests/pod-logs/local_dev_recipe_test_container_logs/"
# Get kubernetes events and save to file
kubectl get events -n ${APP_NAMESPACE} > recipe-tests/pod-logs/local_dev_recipe_test_container_logs/events.txt
- name: Upload Pod logs for failed tests
uses: actions/upload-artifact@v3
if: failure() && steps.get-pod-logs.outcome == 'success'
with:
name: local_dev_recipe_test_container_logs-pod-logs
path: recipe-tests/pod-logs/local_dev_recipe_test_container_logs
retention-days: 30
if-no-files-found: error
2 changes: 1 addition & 1 deletion local-dev/pubsubbrokers.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ resource daprComponent 'dapr.io/Component@v1alpha1' = {
metadata: [
{
name: 'redisHost'
value: '${svc.metadata.name}.${svc.metadata.namespace}.svc.cluster.local'
value: '${svc.metadata.name}.${svc.metadata.namespace}.svc.cluster.local:${port}'
}
{
name: 'redisPassword'
Expand Down
207 changes: 207 additions & 0 deletions tests/test-local-dev-recipes.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
import radius as radius

@description('Specifies the image for the container resource.')
param magpieimage string

@description('The OCI registry for test Bicep recipes.')
param registry string

@description('The OCI tag for test Bicep recipes.')
param version string

import kubernetes as kubernetes {
namespace: 'daprrp-rs-secretstore-recipe'
kubeConfig: ''
}

resource env 'Applications.Core/environments@2023-10-01-preview' = {
name: 'local-dev-recipe-env'
location: 'global'
properties: {
compute: {
kind: 'kubernetes'
resourceId: 'self'
namespace: 'local-dev-recipe-env'
}
recipes: {
'Applications.Datastores/mongoDatabases':{
mongoazure: {
templateKind: 'bicep'
plainHTTP: true
templatePath: '${registry}/recipes/local-dev/mongodatabases:${version}'
}
}
'Applications.Dapr/pubSubBrokers': {
default: {
templateKind: 'bicep'
plainHTTP: true
templatePath: '${registry}/recipes/local-dev/pubsubbrokers:${version}'
}
}
'Applications.Messaging/rabbitMQQueues': {
default: {
templateKind: 'bicep'
plainHTTP: true
templatePath: '${registry}/recipes/local-dev/rabbitmqqueues:${version}'
}
}
'Applications.Datastores/redisCaches':{
default: {
templateKind: 'bicep'
plainHTTP: true
templatePath: '${registry}/recipes/local-dev/rediscaches:${version}'
}
}
'Applications.Dapr/secretStores': {
default: {
templateKind: 'bicep'
plainHTTP: true
templatePath: '${registry}/recipes/local-dev/secretstores:${version}'
}
}
'Applications.Datastores/sqlDatabases': {
default: {
templateKind: 'bicep'
plainHTTP: true
templatePath: '${registry}/recipes/local-dev/sqldatabases:${version}'
}
}
'Applications.Dapr/stateStores': {
default: {
templateKind: 'bicep'
plainHTTP: true
templatePath: '${registry}/recipes/local-dev/statestores:${version}'
}
}
}
}
}

resource app 'Applications.Core/applications@2023-10-01-preview' = {
name: 'local-dev-recipe-app'
location: 'global'
properties: {
environment: env.id
extensions: [
{
kind: 'kubernetesNamespace'
namespace: 'local-dev-recipe-app'
}
]
}
}

resource webapp 'Applications.Core/containers@2023-10-01-preview' = {
name: 'mongodb-app-ctnr'
location: 'global'
properties: {
application: app.id
connections: {
mongodb: {
source: recipedb.id
}
daprpubsub: {
source: pubsubBroker.id
}
rabbitmq: {
source: rabbitmq.id
}
redis: {
source: redis.id
}
daprsecretstore: {
source: secretstore.id
}
sql: {
source: db.id
disableDefaultEnvVars: true
}
daprstatestore: {
source: statestore.id
}
}
container: {
image: magpieimage
readinessProbe:{
kind:'httpGet'
containerPort:3000
path: '/healthz'
}
}
extensions: [
{
kind: 'daprSidecar'
appId: 'dpsb-recipe-app-ctnr'
appPort: 3000
}
]
}
}

resource recipedb 'Applications.Datastores/mongoDatabases@2023-10-01-preview' = {
name: 'mongodb-db'
properties: {
application: app.id
environment: env.id
recipe: {
name: 'mongoazure'
}
}
}

resource pubsubBroker 'Applications.Dapr/pubSubBrokers@2023-10-01-preview' = {
name: 'dpsb-recipe'
properties: {
application: app.id
environment: env.id
}
}

resource rabbitmq 'Applications.Messaging/rabbitMQQueues@2023-10-01-preview' = {
name: 'rmq-recipe-resource'
properties: {
application: app.id
environment: env.id
}
}

resource redis 'Applications.Datastores/redisCaches@2023-10-01-preview' = {
name: 'rds-recipe'
properties: {
environment: env.id
application: app.id
}
}

resource secretstore 'Applications.Dapr/secretStores@2023-10-01-preview' = {
name: 'gnrc-scs-recipe'
properties: {
environment: env.id
application: app.id
}
}

resource mysecret 'core/Secret@v1' = {
metadata: {
name: 'mysecret'
namespace: 'local-dev-recipe-app'
}
type: 'opaque'
data: {}
}

resource db 'Applications.Datastores/sqlDatabases@2023-10-01-preview' = {
name: 'sql-db-recipe'
properties: {
application: app.id
environment: env.id
}
}

resource statestore 'Applications.Dapr/stateStores@2023-10-01-preview' = {
name: 'dapr-sts-recipe'
properties: {
application: app.id
environment: env.id
}
}

0 comments on commit 5cd81f3

Please sign in to comment.