Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,6 @@ testing/docker/certs/

# Claude Code
.claude/

# Visual Studio Code
.vscode/
49 changes: 49 additions & 0 deletions MISE_POC.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# MISE POC - Local Agent

POC para validar el uso de [mise](https://mise.jdx.dev/) en entornos de agente para instalar herramientas definidas en `mise.toml`.

## Requisitos

- Docker
- `NP_API_KEY` exportada en tu shell
- Contexto de Kubernetes `test` configurado en `~/.kube/config`

## Levantar el agente local

Desde la raíz del repo:

```bash
./agent/start_dev.sh
```

Esto construye la imagen Docker y levanta el agente local conectado a nullplatform.

## Canal de notificaciones

El canal configurado para esta POC es:

https://kwik-e-mart.app.nullplatform.io/settings/notifications/channels/593601403

## Disparar una prueba

1. Ir a la notificación:
https://kwik-e-mart.app.nullplatform.io/settings/notifications/272a3f48-bcc3-4794-8873-55d0d701b78f

2. Hacer **Resend** para que el agente local la procese.

## Output esperado

En los logs del agente deberías ver:

```
[DEBUG] Trusting mise config...
[DEBUG] Starting mise install...
[DEBUG] mise install done (exit code: 0)
[DEBUG] mise ls output:
github:kwik-e-mart/scim-logs-fetcher 0.1.0
[DEBUG] Running scim-logs-fetcher --version...
Hello from scim-logs-fetcher! (OS: linux, Arch: arm64)
[DEBUG] scim-logs-fetcher done (exit code: 0)
```

Esto confirma que mise instaló correctamente `scim-logs-fetcher 0.1.0` desde GitHub y lo ejecutó con éxito.
6 changes: 3 additions & 3 deletions agent/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM alpine

# Install essential tools and Go
RUN apk add --no-cache curl ca-certificates bash openssl aws-cli gettext gomplate jq yq go
RUN apk add --no-cache curl ca-certificates bash openssl aws-cli gettext gomplate jq yq go mise

# Install Nullplatform tools
RUN curl https://cli.nullplatform.com/install.sh | sh
Expand All @@ -18,9 +18,9 @@ ENV GOPATH=/go
ENV PATH=$PATH:/go/bin

# Copy files
ADD start.sh /app/start.sh
ADD /agent/start.sh /app/start.sh
RUN chmod +x /app/start.sh
ADD .. /root/.np/services
ADD .. /root/.np/scopes

# Set PATH
ENV PATH=$PATH:/root/.local/bin
Expand Down
6 changes: 3 additions & 3 deletions agent/start_dev.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ if [[ "$NP_API_KEY" == "" ]]; then
echo "NP_API_KEY should be defined"
exit 1
fi
docker build . -t agent-local
docker build -f agent/Dockerfile . -t agent-local
docker run --rm --name agent-local -it \
-e NP_LOG_LEVEL=DEBUG \
-e NP_API_KEY=$NP_API_KEY \
-e K8S_CONTEXT=test \
-e TAGS="local:true" \
-e TAGS="local:true,user:javisolis" \
-v ~/.kube/:/root/.kube \
-v .:/root/.np/services \
-v $(pwd):/root/.np/nullplatform/scopes \
agent-local
95 changes: 15 additions & 80 deletions entrypoint
Original file line number Diff line number Diff line change
@@ -1,82 +1,17 @@
#!/bin/bash

# Check if NP_ACTION_CONTEXT is set
if [ -z "$NP_ACTION_CONTEXT" ]; then
echo "NP_ACTION_CONTEXT is not set. Exiting."
exit 1
fi

CLEAN_CONTEXT=$(echo "$NP_ACTION_CONTEXT" | sed "s/^'//;s/'$//")

export NP_ACTION_CONTEXT="$CLEAN_CONTEXT"

# Parse the JSON properly - remove the extra quotes
export CONTEXT=$(echo "$CLEAN_CONTEXT" | jq '.notification')

export SCOPE_ID=$(echo "$CONTEXT" | jq -r '.parameters.scope_id // .tags.scope_id // .arguments.scope_id')

# If the action has no scope_id update the original context so we can use the np service workflow build-context command
export CONTEXT=$(echo "$CONTEXT" | jq --arg scope_id "$SCOPE_ID" '.parameters.scope_id = $scope_id')
export NP_ACTION_CONTEXT=$(echo "$NP_ACTION_CONTEXT" | jq --arg scope_id "$SCOPE_ID" '.notification.parameters.scope_id = $scope_id')

export DEPLOYMENT_ID=$(echo $CONTEXT | jq -r '.parameters.deployment_id // "null"')
export SERVICE_ACTION=$(echo $CONTEXT | jq -r '.slug')
export SERVICE_ACTION_TYPE=$(echo $CONTEXT | jq -r '.type')
export NOTIFICATION_ACTION=$(echo $CONTEXT | jq -r '.action')

export WORKING_DIRECTORY="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

SERVICE_PATH=""
OVERRIDES_PATH=""
DEPLOYMENT_TEMPLATE_PATH=""
BLUE_GREEN_INGRESS_TEMPLATE_PATH=""
INITIAL_INGRESS_TEMPLATE_PATH=""

for arg in "$@"; do
case $arg in
--service-path=*)
SERVICE_PATH="${arg#*=}"
;;
--overrides-path=*)
OVERRIDE_VALUE="${arg#*=}"
IFS=',' read -ra SPLIT_PATHS <<< "$OVERRIDE_VALUE"
for path in "${SPLIT_PATHS[@]}"; do
path=$(echo "$path" | xargs)
OVERRIDES_PATHS+=("$path")
done
;;
*)
echo "Unknown argument: $arg"
exit 1
;;
esac
done

if [[ ${#OVERRIDES_PATHS[@]} -gt 0 ]]; then
OVERRIDES_PATH=$(IFS=','; echo "${OVERRIDES_PATHS[*]}")
fi


export SERVICE_PATH
export OVERRIDES_PATH

# export util functions
source "$WORKING_DIRECTORY/utils"

if [[ "$NOTIFICATION_ACTION" == "log:read" ]]; then
source "$WORKING_DIRECTORY/service/log/entrypoint"
elif [[ "$NOTIFICATION_ACTION" =~ ^parameter: ]]; then
source "$WORKING_DIRECTORY/service/parameter/entrypoint"
elif [[ "$NOTIFICATION_ACTION" =~ ^metric: ]]; then
source "$WORKING_DIRECTORY/service/metric/entrypoint"
elif [[ "$NOTIFICATION_ACTION" == "instance:data" ]]; then
source "$WORKING_DIRECTORY/service/instance/entrypoint"
elif [[ "$DEPLOYMENT_ID" != "null" && -n "$DEPLOYMENT_ID" ]]; then
echo "Notification action: $NOTIFICATION_ACTION"

np service-action exec --live-output --live-report --script="$WORKING_DIRECTORY/service/deployment/entrypoint"
else
echo "Notification action: $NOTIFICATION_ACTION"

np service-action exec --live-output --live-report --script="$WORKING_DIRECTORY/service/scope/entrypoint"
fi
SCOPE_DIR="${SERVICE_PATH:-$(dirname "${BASH_SOURCE[0]}")}"

echo "[DEBUG] working directory: $SCOPE_DIR"
echo "[DEBUG] mise.toml path: $(ls -la "$SCOPE_DIR/mise.toml" 2>&1)"
echo "[DEBUG] Trusting mise config..."
MISE_YES=1 mise trust "$SCOPE_DIR/mise.toml"
echo "[DEBUG] Starting mise install..."
MISE_YES=1 MISE_CONFIG_FILE="$SCOPE_DIR/mise.toml" mise install
echo "[DEBUG] mise install done (exit code: $?)"
echo "[DEBUG] mise ls output:"
mise ls

echo "[DEBUG] Running scim-logs-fetcher --version..."
MISE_CONFIG_FILE="$SCOPE_DIR/mise.toml" mise exec -- scim-logs-fetcher --version
echo "[DEBUG] scim-logs-fetcher done (exit code: $?)"
5 changes: 5 additions & 0 deletions mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[settings]
experimental = true

[tools]
"github:kwik-e-mart/scim-logs-fetcher" = "0.1.0"
Loading