diff --git a/Enphase/app/extrae.sh b/Enphase/app/extrae.sh index 5cae9e85..35bddff3 100644 --- a/Enphase/app/extrae.sh +++ b/Enphase/app/extrae.sh @@ -1,7 +1,23 @@ #!/bin/bash +# Datos para la conexión + +export ENPHASE_REMOTE_API_USERNAME=creylopez@yahoo.es +export ENPHASE_REMOTE_API_PASSWORD=h769jzYDnqpPog +export ENPHASE_REMOTE_API_SERIALNO=122044072645 + +# obtener un id de sesión válido + +sesion=`curl https://enlighten.enphaseenergy.com/login/login.json -d "user[email]=${ENPHASE_REMOTE_API_USERNAME}&user[password]=${ENPHASE_REMOTE_API_PASSWORD}" | jq -r '.session_id'` + +# obtener un token usando el id de sesión +token=`curl "https://enlighten.enphaseenergy.com/entrez-auth-token?serial_num=${ENPHASE_REMOTE_API_SERIALNO}" -H "cookie: _enlighten_4_session=$sesion" | jq -r '.token'` + +#echo "La sesión es $sesion y el token es $token" + +datos=`curl -k -H "Authorization: Bearer $token" https://192.168.1.141/production.json` #datos=`curl http://envoy.local/production.json 2>/dev/null` -datos=`curl http://192.168.1.141/production.json 2>/dev/null` +#datos=`curl http://192.168.1.141/production.json 2>/dev/null` # # obtiene datos de producción de inverters diff --git a/Enphase/creaImagen.sh b/Enphase/creaImagen.sh index 6d0e40bb..8c8adde3 100644 --- a/Enphase/creaImagen.sh +++ b/Enphase/creaImagen.sh @@ -1,2 +1,11 @@ -docker build --no-cache -t docker-registry:32000/enphase:2.0 . -docker push docker-registry:32000/enphase:2.0 +#!/bin/bash + +if [ -z "$1" ] +then + echo "Falta versión" +else + + +docker build --no-cache -t docker-registry:32000/enphase:$1 . +docker push docker-registry:32000/enphase:$1 +fi diff --git a/Enphase/enlighten.py b/Enphase/enlighten.py new file mode 100644 index 00000000..0d4de07b --- /dev/null +++ b/Enphase/enlighten.py @@ -0,0 +1,16 @@ +import json +import requests + +# REPLACE ITEMS BELOW +user='creylopez@yahoo.es' +password='h769jzYDnqpPog' +envoy_serial='122044072645' +# DO NOT CHANGE ANYTHING BELOW + +data = {'user[email]': user, 'user[password]': password} +response = requests.post('https://enlighten.enphaseenergy.com/login/login.json?',data=data) +response_data = json.loads(response.text) +data = {'session_id': response_data['session_id'], 'serial_num': envoy_serial, 'username':user} +response = requests.post('https://entrez.enphaseenergy.com/tokens', json=data) +token_raw = response.text +print(token_raw) \ No newline at end of file diff --git a/Enphase/sesion.sh b/Enphase/sesion.sh new file mode 100644 index 00000000..22edb537 --- /dev/null +++ b/Enphase/sesion.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# Datos para la conexión + +export ENPHASE_REMOTE_API_USERNAME=creylopez@yahoo.es +export ENPHASE_REMOTE_API_PASSWORD=h769jzYDnqpPog +export ENPHASE_REMOTE_API_SERIALNO=122044072645 + +# obtener un id de sesión válido + +sesion=`curl https://enlighten.enphaseenergy.com/login/login.json -d "user[email]=${ENPHASE_REMOTE_API_USERNAME}&user[password]=${ENPHASE_REMOTE_API_PASSWORD}" | jq -r '.session_id'` + +token=`curl "https://enlighten.enphaseenergy.com/entrez-auth-token?serial_num=${ENPHASE_REMOTE_API_SERIALNO}" -H "cookie: _enlighten_4_session=$sesion" | jq -r '.token'` + +echo "La sesión es $sesion y el token es $token" + +curl -k -H "Authorization: Bearer $token" https://envoy.local/production.json diff --git a/HelmCharts/enphase-chart/templates/enphase-cronjob.yaml b/HelmCharts/enphase-chart/templates/enphase-cronjob.yaml index 7cc0e9d4..5d33bc78 100644 --- a/HelmCharts/enphase-chart/templates/enphase-cronjob.yaml +++ b/HelmCharts/enphase-chart/templates/enphase-cronjob.yaml @@ -12,7 +12,7 @@ spec: spec: containers: - name: hello - image: docker-registry:32000/enphase:2.0 + image: docker-registry:32000/enphase:4.0 imagePullPolicy: IfNotPresent env: - name: DB_HOST diff --git a/HelmCharts/homeassistant-chart/templates/homeassistant-deployment.yaml b/HelmCharts/homeassistant-chart/templates/homeassistant-deployment.yaml index 686cddaf..534c1b7d 100644 --- a/HelmCharts/homeassistant-chart/templates/homeassistant-deployment.yaml +++ b/HelmCharts/homeassistant-chart/templates/homeassistant-deployment.yaml @@ -58,7 +58,7 @@ spec: name: homeassistant volumeMounts: - name: homeassistant-persistent-storage - mountPath: /data + mountPath: /config imagePullSecrets: - name: reg-cred-secret volumes: diff --git a/HelmCharts/instala b/HelmCharts/instala index d94a9054..b8e80e2c 100755 --- a/HelmCharts/instala +++ b/HelmCharts/instala @@ -4,12 +4,15 @@ if [ -z "$1" ] then echo "Falta nombre del chart" else + +chart=`echo $1 | cut -f1 -d-` + if [ "$2" = "i" ] then - helm install $1 ./$1-chart --namespace=$1 --create-namespace + helm install $chart ./$1 --namespace=$chart --create-namespace elif [ "$2" = "u" ] then - helm uninstall $1 -n $1 + helm uninstall $chart -n $chart else echo "Falta comando: i=instalar, u=desinstalar" fi diff --git a/HelmCharts/repostajes-chart/.helmignore b/HelmCharts/repostajes-chart/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/HelmCharts/repostajes-chart/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/HelmCharts/repostajes-chart/Chart.yaml b/HelmCharts/repostajes-chart/Chart.yaml new file mode 100644 index 00000000..5df4efaa --- /dev/null +++ b/HelmCharts/repostajes-chart/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: repostajes-chart +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" diff --git a/HelmCharts/repostajes-chart/copyRepostajesDB b/HelmCharts/repostajes-chart/copyRepostajesDB new file mode 100755 index 00000000..4ed30277 --- /dev/null +++ b/HelmCharts/repostajes-chart/copyRepostajesDB @@ -0,0 +1,24 @@ +# Backup date + +today=$(date "+%Y_%m_%d-%H_%M_%S") + +echo "Current date: $today" + +# build up filename + +# destination folder (change to your own needs) + +BACKUP_FOLDER=/tmp + +file_name=$BACKUP_FOLDER/bkup_repostajes +new_name=$file_name-$today.sql +echo "Backup file name: " "$new_name" + +#sudo docker exec `sudo docker container ls | grep mysql_repostajes | cut -f1 -d' '` /usr/bin/mysqldump -u root --password=Dsa-0213 repostajes > $new_name +sudo kubectl --kubeconfig /home/creylopez/.kube/config exec `kubectl --kubeconfig /home/creylopez/.kube/config get pod -n repostajes|grep mysql|cut -f1 -d' '` -n repostajes -- /usr/bin/mariadb-dump -u root --password=Dsa-0213 automoviles > $new_name + +message="Backup stored "$today + +sudo -u creylopez cat $new_name | mail -s "Repostajes backup finished" "creylopez@yahoo.es" + +sudo rm $new_name diff --git a/HelmCharts/repostajes-chart/templates/mysql-deployment.yaml b/HelmCharts/repostajes-chart/templates/mysql-deployment.yaml new file mode 100644 index 00000000..42420555 --- /dev/null +++ b/HelmCharts/repostajes-chart/templates/mysql-deployment.yaml @@ -0,0 +1,76 @@ +apiVersion: v1 +kind: Service +metadata: + name: repostajes-mysql + namespace: repostajes + labels: + app: repostajes +spec: + type: NodePort + ports: + - name: mysql + port: 3306 + nodePort: 30385 + targetPort: mysql + selector: + app: repostajes + tier: mysql +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: mysql-pv-claim + namespace: repostajes + labels: + app: repostajes +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 25Gi + selector: + matchLabels: + app: mysql +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: repostajes-mysql + namespace: repostajes + labels: + app: repostajes +spec: + selector: + matchLabels: + app: repostajes + tier: mysql + strategy: + type: Recreate + template: + metadata: + labels: + app: repostajes + tier: mysql + spec: + containers: + - image: mariadb:latest + name: mysql + env: + - name: MYSQL_ROOT_PASSWORD + valueFrom: + secretKeyRef: + name: mysql-pass + key: password + ports: + - containerPort: 3306 + name: mysql + volumeMounts: + - name: mysql-persistent-storage + mountPath: /var/lib/mysql + imagePullSecrets: + - name: reg-cred-secret + volumes: + - name: mysql-persistent-storage + persistentVolumeClaim: + claimName: mysql-pv-claim diff --git a/HelmCharts/repostajes-chart/templates/php-myadmin-deployment.yaml b/HelmCharts/repostajes-chart/templates/php-myadmin-deployment.yaml new file mode 100644 index 00000000..4dc63d66 --- /dev/null +++ b/HelmCharts/repostajes-chart/templates/php-myadmin-deployment.yaml @@ -0,0 +1,57 @@ +apiVersion: v1 +kind: Service +metadata: + name: phpmyadmin-repostajes + namespace: repostajes + labels: + app: repostajes +spec: + selector: + app: repostajes + tier: phpmyadmin + type: NodePort + ports: + - name: phpadmin + port: 80 + nodePort: 30386 + targetPort: phpmyadm +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: phpmyadmin-repostajes + namespace: repostajes + labels: + app: repostajes +spec: + selector: + matchLabels: + app: repostajes + tier: phpmyadmin + strategy: + type: Recreate + template: + metadata: + labels: + app: repostajes + tier: phpmyadmin + spec: + containers: + - name: phpmyadmin + image: phpmyadmin + ports: + - containerPort: 80 + name: phpmyadm + env: + - name: PMA_HOST + value: repostajes-mysql + - name: PMA_PORT + value: "3306" + - name: MYSQL_ROOT_PASSWORD + valueFrom: + secretKeyRef: + name: mysql-pass + key: password + imagePullSecrets: + - name: reg-cred-secret + diff --git a/HelmCharts/repostajes-chart/templates/pv-local-mysql.yaml b/HelmCharts/repostajes-chart/templates/pv-local-mysql.yaml new file mode 100644 index 00000000..b35b4498 --- /dev/null +++ b/HelmCharts/repostajes-chart/templates/pv-local-mysql.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: PersistentVolume +metadata: + name: repostajes-data + labels: + app: mysql +spec: + capacity: + storage: 25Gi + accessModes: + - ReadWriteOnce + hostPath: + path: "/mnt/Externo/repostajes/repostajes-db" diff --git a/HelmCharts/repostajes-chart/templates/pv-local-repostajes.yaml b/HelmCharts/repostajes-chart/templates/pv-local-repostajes.yaml new file mode 100644 index 00000000..27a61ff4 --- /dev/null +++ b/HelmCharts/repostajes-chart/templates/pv-local-repostajes.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: PersistentVolume +metadata: + name: repostajes-app-folder + labels: + app: repostajes +spec: + capacity: + storage: 5Gi + accessModes: + - ReadWriteOnce + hostPath: + path: "/mnt/Externo/repostajes/repostajes-app" + diff --git a/HelmCharts/repostajes-chart/templates/registry-secrets.yaml b/HelmCharts/repostajes-chart/templates/registry-secrets.yaml new file mode 100644 index 00000000..8a142289 --- /dev/null +++ b/HelmCharts/repostajes-chart/templates/registry-secrets.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +data: + .dockerconfigjson: eyJhdXRocyI6eyJkb2NrZXItcmVnaXN0cnk6MzIwMDAiOnsidXNlcm5hbWUiOiJjcmV5bG9wZXoiLCJwYXNzd29yZCI6IlJleS0xMTc2IiwiYXV0aCI6IlkzSmxlV3h2Y0dWNk9sSmxlUzB4TVRjMiJ9fX0= +kind: Secret +metadata: + creationTimestamp: "2023-01-29T10:54:14Z" + name: reg-cred-secret + namespace: repostajes + resourceVersion: "19890385" + uid: 66b3b7c5-26c1-4e5a-af4e-dc973aaafe4b +type: kubernetes.io/dockerconfigjson diff --git a/HelmCharts/repostajes-chart/templates/repostajes-deployment.yaml b/HelmCharts/repostajes-chart/templates/repostajes-deployment.yaml new file mode 100644 index 00000000..985974d3 --- /dev/null +++ b/HelmCharts/repostajes-chart/templates/repostajes-deployment.yaml @@ -0,0 +1,70 @@ +apiVersion: v1 +kind: Service +metadata: + name: repostajes + namespace: repostajes + labels: + app: repostajes +spec: + type: NodePort + ports: + - port: 80 + nodePort: 30080 + targetPort: repostajes + selector: + app: repostajes + tier: frontend +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: repostajes-pv-claim + namespace: repostajes + labels: + app: repostajes +spec: + accessModes: + - ReadWriteOnce + storageClassName: "" + resources: + requests: + storage: 5Gi + selector: + matchLabels: + app: repostajes +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: repostajes + namespace: repostajes + labels: + app: repostajes +spec: + selector: + matchLabels: + app: repostajes + tier: frontend + strategy: + type: Recreate + template: + metadata: + labels: + app: repostajes + tier: frontend + spec: + containers: + - image: docker-registry:32000/phpmysql:1.0 + name: repostajes + ports: + - containerPort: 80 + name: repostajes + volumeMounts: + - name: repostajes-persistent-storage + mountPath: /var/www/html + imagePullSecrets: + - name: reg-cred-secret + volumes: + - name: repostajes-persistent-storage + persistentVolumeClaim: + claimName: repostajes-pv-claim diff --git a/HelmCharts/repostajes-chart/templates/repostajes-secrets.yaml b/HelmCharts/repostajes-chart/templates/repostajes-secrets.yaml new file mode 100644 index 00000000..1fdd2920 --- /dev/null +++ b/HelmCharts/repostajes-chart/templates/repostajes-secrets.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Secret +metadata: + name: mysql-pass + namespace: repostajes +type: Opaque +stringData: + db_password: Dsa-0213 + password: Dsa-0213 + db_user: root diff --git a/HelmCharts/repostajes-chart/values.yaml b/HelmCharts/repostajes-chart/values.yaml new file mode 100644 index 00000000..c598d42b --- /dev/null +++ b/HelmCharts/repostajes-chart/values.yaml @@ -0,0 +1,82 @@ +# Default values for repostajes-chart. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: nginx + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {} diff --git a/PHPMysql/Dockerfile b/PHPMysql/Dockerfile new file mode 100644 index 00000000..c4290c24 --- /dev/null +++ b/PHPMysql/Dockerfile @@ -0,0 +1,8 @@ +FROM php:8.2-apache +LABEL maintainer="Celestino Rey " +# Install any necessary packages +WORKDIR /var/www/html +RUN apt-get update +RUN docker-php-ext-install mysqli pdo pdo_mysql +RUN docker-php-ext-enable mysqli + diff --git a/PHPMysql/creaImagen.sh b/PHPMysql/creaImagen.sh new file mode 100644 index 00000000..5f7c9a28 --- /dev/null +++ b/PHPMysql/creaImagen.sh @@ -0,0 +1,2 @@ +docker build --no-cache -t docker-registry:32000/phpmysql:1.0 . +docker push docker-registry:32000/phpmysql:1.0 diff --git a/repostajes-20230712.tar.gz b/repostajes-20230712.tar.gz new file mode 100644 index 00000000..e2c6b019 Binary files /dev/null and b/repostajes-20230712.tar.gz differ