Commit 6f1b8952 authored by Jorge Moratinos's avatar Jorge Moratinos
Browse files

removed not used values

parent f42fb410
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -186,7 +186,7 @@
      same "printed page" as the copyright notice for easier
      identification within third-party archives.

   Copyright 2022 Telefónica Innovación Digital and ETSI.
   Copyright 2026 Telefónica Innovación Digital and ETSI.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
+87 −33
Original line number Diff line number Diff line
# CAPIF Backoffice Frontend
# OpenCAPIF Backoffice Frontend

# Repository structure
This repository contains the frontend UI for the OpenCAPIF Backoffice.

The frontend provides dashboards and management pages to view and operate OpenCAPIF resources through the backend API, including:
- Invokers
- Providers
- APIs
- Users
- Configuration

The frontend does not query OpenCAPIF directly. It consumes data from the backoffice backend API, which in turn retrieves data from OpenCAPIF.

## Prerequisites

- Docker with integrated Compose V2 support (docker compose command), Docker Engine 20.10+ recommended.
- The backoffice backend must be deployed and running.
- The frontend and backend must run in the same Docker network (default: capif-network).
- A running OpenCAPIF deployment is required and must be reachable from the backend.

Important:
- If OpenCAPIF is not deployed/running, or the backend cannot access it, the frontend will not have data to display.
- The default frontend API URL is configured in capif_frontend/.env as:
	- NEXT_PUBLIC_API_BASE_URL="http://backoffice-backend:8085/api"

## Run with Scripts

Run from the repository root:

```bash
./run.sh
```
CAPIF_BACKOFFICE_Frontend
└───./vscode
└───public
│    └───images
│    └───locales
└───src
│    └───@core
│    └───@fake-db
│    └───configs
│    └───context
│    └───hooks
│    └───iconify-bundle
│    └───layouts
│    └───navigation
│    └───pages
│    └───store
│    └───views
└───styles
```
* **vscode**: ...
* **public**: ...
* **src**: ...
* **styles**: ...

What run.sh does:
- Moves into capif_frontend.
- Runs yarn install.
- Runs yarn build.
- Runs yarn export.
- Returns to repository root.
- Runs docker compose up --build --detach with DOCKER_DEFAULT_PLATFORM=linux/amd64.

After startup, the frontend is exposed on:

```text
http://localhost:4000
```

## How to run Backoffice Frontend in this Repository
## Clean Deployment

### Run CAPIF Frontend
To run using yarn you must ensure you have that tools installed at your machine.
To stop and clean local deployment:

Compile 
```bash
./clean.sh
```

What clean.sh does:
- Runs docker compose down --rmi all with DOCKER_DEFAULT_PLATFORM=linux/amd64.

## Default Login Credentials

For local/default backend authentication setup, the configured credentials are:

- Username: superadmin
- Password: admin

Note:
- These credentials are validated by the backend login endpoint configuration.
- Change them in production environments as part of security hardening.

## Optional Manual Frontend Commands

If you need to run the UI manually (without the wrapper script), use these commands inside capif_frontend:

```bash
yarn install
yarn build
yarn export
```

You can run it in two differents ways. The first one is a way for a deployment environment.
```
For development mode:

```bash
yarn dev
```

The second one is a way to run in production environment.
```
For production mode (after build):

```bash
yarn start
```

## Repository Structure

```text
capif_frontend/
	public/
	src/
	styles/
helm/
docker-compose.yml
run.sh
clean.sh
```

build_and_push.sh

deleted100755 → 0
+0 −105
Original line number Diff line number Diff line
#!/bin/bash

set -e  # Detener la ejecución si ocurre un error

# Función para manejar errores
handle_error() {
    echo "Error en el script. Línea: $1"
    exit 1
}

# Capturar errores y llamar a la función handle_error
trap 'handle_error $LINENO' ERR

# Pedir al usuario la URL del backend
read -p "Introduce la URL del backend (ej. http://localhost:8085): " BACKEND_URL

# Concatenar "/api" al final de la URL
API_URL="${BACKEND_URL}/api"

echo "La URL completa de la API será: $API_URL"

# Cambiar el valor de NEXT_PUBLIC_API_BASE_URL en el archivo capif_frontend/.env
ENV_FILE="capif_frontend/.env"

if [ -f "$ENV_FILE" ]; then
    # Reemplazar la línea correcta sin tocar las comentadas o con espacios alrededor del igual
    sed -i '' -E 's|^NEXT_PUBLIC_API_BASE_URL\s*=\s*.*$|NEXT_PUBLIC_API_BASE_URL="'"$API_URL"'"|g' "$ENV_FILE"
    echo "Variable NEXT_PUBLIC_API_BASE_URL actualizada en $ENV_FILE"
else
    echo "Error: No se encontró el archivo $ENV_FILE"
    exit 1
fi

# Obtener la última versión desde ECR usando AWS CLI
LAST_VERSION=$(aws ecr-public describe-image-tags --repository-name opencapif/backoffice-frontend --region us-east-1 --query 'imageTagDetails[*].imageTag' --output text | grep -Eo 'v3.1.[0-9]+' | sed 's/v3.1.//' | sort -n | tail -1)

if [ -z "$LAST_VERSION" ]; then
    echo "No se pudo obtener la última versión desde ECR. Verifica si el repositorio o las imágenes existen."
    exit 1
fi

# Incrementar la versión
NEW_VERSION=$((LAST_VERSION + 1))
echo "Nueva versión: v3.1.$NEW_VERSION"

# Cambiar directorio a capif_frontend
echo "Cambiando a directorio capif_frontend..."
cd capif_frontend || { echo "Error: no se pudo cambiar al directorio capif_frontend."; exit 1; }

# Ejecutar comandos de yarn
echo "Instalando dependencias con yarn..."
yarn install || { echo "Error en 'yarn install'."; exit 1; }

echo "Construyendo la aplicación con yarn..."
yarn build || { echo "Error en 'yarn build'."; exit 1; }

echo "Exportando la aplicación con yarn..."
yarn export || { echo "Error en 'yarn export'."; exit 1; }

# Volver al directorio principal
cd .. || { echo "Error: no se pudo volver al directorio principal."; exit 1; }

# Establecer la plataforma y construir la imagen Docker
echo "Construyendo la imagen Docker..."
DOCKER_DEFAULT_PLATFORM=linux/amd64 docker-compose build || { echo "Error en la construcción de la imagen Docker."; exit 1; }

# Pedir al usuario el ARN de MFA
read -p "Introduce el ID de cuenta de AWS (ej. 230672794366): " AWS_ACCOUNT_ID
read -p "Introduce el nombre del dispositivo MFA (ej. google_authenticator_phone): " MFA_DEVICE

MFA_ARN="arn:aws:iam::$AWS_ACCOUNT_ID:mfa/$MFA_DEVICE"

# Autenticación MFA con AWS para obtener un token temporal
read -p "Introduce el código MFA de 6 dígitos: " MFA_CODE

# Obtener un token temporal usando MFA
echo "Autenticando con AWS usando MFA..."
TEMP_CREDS=$(aws sts get-session-token --serial-number "$MFA_ARN" --token-code "$MFA_CODE" --output json)

if [ -z "$TEMP_CREDS" ]; then
    echo "Error: No se pudo obtener el token temporal de AWS. Verifica el código MFA."
    exit 1
fi

# Exportar credenciales temporales
export AWS_ACCESS_KEY_ID=$(echo "$TEMP_CREDS" | jq -r '.Credentials.AccessKeyId')
export AWS_SECRET_ACCESS_KEY=$(echo "$TEMP_CREDS" | jq -r '.Credentials.SecretAccessKey')
export AWS_SESSION_TOKEN=$(echo "$TEMP_CREDS" | jq -r '.Credentials.SessionToken')

# Autenticar Docker con Amazon ECR Public
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/o2v4a8t6 || { echo "Error en la autenticación con Docker."; exit 1; }

# Taggear la imagen con la nueva versión
echo "Etiquetando la imagen Docker..."
docker tag pesp_capif_backoffice_frontend_v2-frontend_microservice public.ecr.aws/o2v4a8t6/opencapif/backoffice-frontend:v3.1.$NEW_VERSION || { echo "Error al etiquetar la imagen Docker."; exit 1; }

# Push de la imagen con la nueva versión
echo "Pushing la nueva imagen a ECR..."
docker push public.ecr.aws/o2v4a8t6/opencapif/backoffice-frontend:v3.1.$NEW_VERSION || { echo "Error al hacer push de la imagen Docker."; exit 1; }

# Mostrar la nueva versión
echo "Nueva imagen subida correctamente: public.ecr.aws/o2v4a8t6/opencapif/backoffice-frontend:v3.1.$NEW_VERSION"

# Tag a desplegar
echo "Frontend tag a desplegar: v3.1.$NEW_VERSION"
 No newline at end of file

build_and_push_and_deploy.sh

deleted100755 → 0
+0 −130
Original line number Diff line number Diff line
#!/bin/bash

set -e  # Detener la ejecución si ocurre un error

# Función para manejar errores
handle_error() {
    echo "Error en el script. Línea: $1"
    exit 1
}

# Capturar errores y llamar a la función handle_error
trap 'handle_error $LINENO' ERR

# Pedir al usuario la URL del backend
read -p "Introduce la URL del backend (ej. http://localhost:8085): " BACKEND_URL

# Concatenar "/api" al final de la URL
API_URL="${BACKEND_URL}/api"

echo "La URL completa de la API será: $API_URL"

# Cambiar el valor de NEXT_PUBLIC_API_BASE_URL en el archivo capif_frontend/.env
ENV_FILE="capif_frontend/.env"

if [ -f "$ENV_FILE" ]; then
    # Reemplazar la línea correcta sin tocar las comentadas o con espacios alrededor del igual
    sed -i '' -E 's|^NEXT_PUBLIC_API_BASE_URL\s*=\s*.*$|NEXT_PUBLIC_API_BASE_URL="'"$API_URL"'"|g' "$ENV_FILE"
    echo "Variable NEXT_PUBLIC_API_BASE_URL actualizada en $ENV_FILE"
else
    echo "Error: No se encontró el archivo $ENV_FILE"
    exit 1
fi

# Obtener la última versión desde ECR usando AWS CLI
LAST_VERSION=$(aws ecr-public describe-image-tags --repository-name opencapif/backoffice-frontend --region us-east-1 --query 'imageTagDetails[*].imageTag' --output text | grep -Eo 'v3.1.[0-9]+' | sed 's/v3.1.//' | sort -n | tail -1)

if [ -z "$LAST_VERSION" ]; then
    echo "No se pudo obtener la última versión desde ECR. Verifica si el repositorio o las imágenes existen."
    exit 1
fi

# Incrementar la versión
NEW_VERSION=$((LAST_VERSION + 1))
echo "Nueva versión: v3.1.$NEW_VERSION"

# Cambiar directorio a capif_frontend
echo "Cambiando a directorio capif_frontend..."
cd capif_frontend || { echo "Error: no se pudo cambiar al directorio capif_frontend."; exit 1; }

# Ejecutar comandos de yarn
echo "Instalando dependencias con yarn..."
yarn install || { echo "Error en 'yarn install'."; exit 1; }

echo "Construyendo la aplicación con yarn..."
yarn build || { echo "Error en 'yarn build'."; exit 1; }

echo "Exportando la aplicación con yarn..."
yarn export || { echo "Error en 'yarn export'."; exit 1; }

# Volver al directorio principal
cd .. || { echo "Error: no se pudo volver al directorio principal."; exit 1; }

# Establecer la plataforma y construir la imagen Docker
echo "Construyendo la imagen Docker..."
DOCKER_DEFAULT_PLATFORM=linux/amd64 docker-compose build || { echo "Error en la construcción de la imagen Docker."; exit 1; }

# Pedir al usuario el ARN de MFA
read -p "Introduce el ID de cuenta de AWS (ej. 230672794366): " AWS_ACCOUNT_ID
read -p "Introduce el nombre del dispositivo MFA (ej. google_authenticator_phone): " MFA_DEVICE

MFA_ARN="arn:aws:iam::$AWS_ACCOUNT_ID:mfa/$MFA_DEVICE"

# Autenticación MFA con AWS para obtener un token temporal
read -p "Introduce el código MFA de 6 dígitos: " MFA_CODE

# Obtener un token temporal usando MFA
echo "Autenticando con AWS usando MFA..."
TEMP_CREDS=$(aws sts get-session-token --serial-number "$MFA_ARN" --token-code "$MFA_CODE" --output json)

if [ -z "$TEMP_CREDS" ]; then
    echo "Error: No se pudo obtener el token temporal de AWS. Verifica el código MFA."
    exit 1
fi

# Exportar credenciales temporales
export AWS_ACCESS_KEY_ID=$(echo "$TEMP_CREDS" | jq -r '.Credentials.AccessKeyId')
export AWS_SECRET_ACCESS_KEY=$(echo "$TEMP_CREDS" | jq -r '.Credentials.SecretAccessKey')
export AWS_SESSION_TOKEN=$(echo "$TEMP_CREDS" | jq -r '.Credentials.SessionToken')

# Autenticar Docker con Amazon ECR Public
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/o2v4a8t6 || { echo "Error en la autenticación con Docker."; exit 1; }

# Taggear la imagen con la nueva versión
echo "Etiquetando la imagen Docker..."
docker tag pesp_capif_backoffice_frontend_v2-frontend_microservice public.ecr.aws/o2v4a8t6/opencapif/backoffice-frontend:v3.1.$NEW_VERSION || { echo "Error al etiquetar la imagen Docker."; exit 1; }

# Push de la imagen con la nueva versión
echo "Pushing la nueva imagen a ECR..."
docker push public.ecr.aws/o2v4a8t6/opencapif/backoffice-frontend:v3.1.$NEW_VERSION || { echo "Error al hacer push de la imagen Docker."; exit 1; }

# Actualizar el archivo helm/backoffice/values.yaml con el nuevo tag solo en la sección frontend
VALUES_FILE="helm/backoffice/values.yaml"

if [ -f "$VALUES_FILE" ]; then
    echo "Actualizando el archivo $VALUES_FILE con el nuevo tag..."

    # Reemplazar el tag del frontend buscando el repository y el tag justo después
    awk -v new_version="v3.1.$NEW_VERSION" '
    $0 ~ /repository: public.ecr.aws\/o2v4a8t6\/opencapif\/backoffice-frontend/ {
        found=1
    }
    found && /tag:/ {
        sub(/"v3.1.[0-9]+"/, "\"" new_version "\"")
        found=0
    }
    { print }
    ' "$VALUES_FILE" > "$VALUES_FILE.tmp" && mv "$VALUES_FILE.tmp" "$VALUES_FILE"

    echo "Archivo $VALUES_FILE actualizado con el nuevo tag v3.1.$NEW_VERSION"
else
    echo "Error: No se encontró el archivo $VALUES_FILE"
    exit 1
fi

# Ejecutar el comando Helm para actualizar la instalación
echo "Ejecutando helm upgrade..."
helm upgrade --install -n backoffice backoffice helm/backoffice --create-namespace || { echo "Error en el comando Helm."; exit 1; }

# Mostrar la nueva versión
echo "Nueva imagen subida y helm upgrade ejecutado correctamente: public.ecr.aws/o2v4a8t6/opencapif/backoffice-frontend:v3.1.$NEW_VERSION"
+0 −66
Original line number Diff line number Diff line
#!/bin/bash

set -e  # Detener la ejecución si ocurre un error

# Función para manejar errores
handle_error() {
    echo "Error en el script. Línea: $1"
    exit 1
}

# Capturar errores y llamar a la función handle_error
trap 'handle_error $LINENO' ERR

# Verificar si AWS CLI está instalado
if ! command -v aws &> /dev/null
then
    echo "AWS CLI no está instalado. Por favor, instala AWS CLI y vuelve a ejecutar el script."
    exit 1
fi

# Pedir al usuario las credenciales base (sin MFA)
read -p "Introduce tu AWS Access Key ID: " AWS_ACCESS_KEY_ID_BASE
read -s -p "Introduce tu AWS Secret Access Key: " AWS_SECRET_ACCESS_KEY_BASE
echo ""

# Exportar las credenciales base para la sesión
export AWS_ACCESS_KEY_ID="$AWS_ACCESS_KEY_ID_BASE"
export AWS_SECRET_ACCESS_KEY="$AWS_SECRET_ACCESS_KEY_BASE"

# Comprobar si las credenciales base funcionan ejecutando un comando sencillo
aws sts get-caller-identity || { echo "Error: No se pueden utilizar las credenciales base"; exit 1; }

# Pedir al usuario el ARN de MFA
read -p "Introduce el ID de cuenta de AWS (ej. 230672794366): " AWS_ACCOUNT_ID
read -p "Introduce el nombre del dispositivo MFA (ej. google_authenticator_phone): " MFA_DEVICE

MFA_ARN="arn:aws:iam::$AWS_ACCOUNT_ID:mfa/$MFA_DEVICE"

# Autenticación MFA con AWS para obtener un token temporal
read -p "Introduce el código MFA de 6 dígitos: " MFA_CODE

# Obtener un token temporal usando MFA
echo "Autenticando con AWS usando MFA..."
TEMP_CREDS=$(aws sts get-session-token --serial-number "$MFA_ARN" --token-code "$MFA_CODE" --output json)

# Verificar si se obtuvieron las credenciales temporales
if [ -z "$TEMP_CREDS" ]; then
    echo "Error: No se pudo obtener el token temporal de AWS. Verifica el código MFA."
    exit 1
fi

# Exportar credenciales temporales
export AWS_ACCESS_KEY_ID=$(echo "$TEMP_CREDS" | jq -r '.Credentials.AccessKeyId')
export AWS_SECRET_ACCESS_KEY=$(echo "$TEMP_CREDS" | jq -r '.Credentials.SecretAccessKey')
export AWS_SESSION_TOKEN=$(echo "$TEMP_CREDS" | jq -r '.Credentials.SessionToken')

# Comprobar si las credenciales temporales han sido exportadas correctamente
if [ -z "$AWS_ACCESS_KEY_ID" ] || [ -z "$AWS_SECRET_ACCESS_KEY" ] || [ -z "$AWS_SESSION_TOKEN" ]; then
    echo "Error: No se exportaron correctamente las credenciales temporales."
    exit 1
else
    echo "Credenciales temporales obtenidas y exportadas correctamente."
fi

# Comprobar si las credenciales temporales funcionan ejecutando un comando sencillo
aws sts get-caller-identity ||
Loading