Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Joatin committed Jan 7, 2025
1 parent 5c73072 commit 4352aac
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>
warn!("No DATABASE_URL env var provided, attempting to connect to database at localhost");
"postgres://postgres:password@localhost/postgres".to_string()
});
dbg!(&database_url);
let pool = PgPoolOptions::new()
.max_connections(5)
.connect(&database_url)
Expand Down
5 changes: 4 additions & 1 deletion api/src/start_server.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::api_service::ApiService;
use crate::ocpp_csms_server::api_server::ApiServer;
use shared::DataStore;
use std::env;
use std::net::SocketAddr;
use tonic::transport::Server;
use tracing::{info, instrument};
Expand All @@ -12,7 +13,9 @@ pub async fn start_server(
let (mut health_reporter, health_service) = tonic_health::server::health_reporter();
health_reporter.set_serving::<ApiServer<ApiService>>().await;

let addr: SocketAddr = "[::1]:50053".parse().unwrap();
let host = env::var("HOST").unwrap_or_else(|_| "127.0.0.1".to_string());
let port = env::var("PORT").unwrap_or_else(|_| "50053".to_string());
let addr: SocketAddr = format!("{}:{}", host, port).parse().unwrap();

info!(address = addr.to_string(), "starting grpc server endpoint");

Expand Down
4 changes: 2 additions & 2 deletions charts/ocpp-csms-server/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ 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.18
version: 0.1.19

# 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: "v0.1.3"
appVersion: "v0.1.4"

dependencies:
- name: postgresql
Expand Down
4 changes: 4 additions & 0 deletions charts/ocpp-csms-server/templates/api-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ spec:
containerPort: {{ .Values.api.service.port }}
protocol: TCP
env:
- name: "HOST"
value: "0.0.0.0"
- name: "PORT"
value: "{{ .Values.api.service.port }}"
- name: "LOG_LEVEL"
value: {{ .Values.api.logLevel }}
- name: "DATABASE_PASSWORD"
Expand Down
11 changes: 10 additions & 1 deletion charts/ocpp-csms-server/templates/ocpp-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,18 @@ spec:
command: [ "/bin/ocpp" ]
ports:
- name: http
containerPort: {{ .Values.ocpp.service.port }}
containerPort: {{ .Values.ocpp.service.ocppPort }}
protocol: TCP
- name: grpc
containerPort: {{ .Values.ocpp.service.apiPort }}
protocol: TCP
env:
- name: "HOST"
value: "0.0.0.0"
- name: "OCPP_PORT"
value: "{{ .Values.ocpp.service.ocppPort }}"
- name: "API_PORT"
value: "{{ .Values.ocpp.service.apiPort }}"
- name: "LOG_LEVEL"
value: {{ .Values.ocpp.logLevel }}
- name: DATABASE_PASSWORD
Expand Down
6 changes: 5 additions & 1 deletion charts/ocpp-csms-server/templates/ocpp-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ metadata:
spec:
type: {{ .Values.ocpp.service.type }}
ports:
- port: {{ .Values.ocpp.service.port }}
- port: {{ .Values.ocpp.service.ocppPort }}
targetPort: http
protocol: TCP
name: http
- port: {{ .Values.ocpp.service.apiPort }}
targetPort: grpc
protocol: TCP
name: grpc
selector:
{{ include "ocpp-csms-server.ocppSelectorLabels" . | nindent 4 }}
3 changes: 2 additions & 1 deletion charts/ocpp-csms-server/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ ocpp:
# This sets the service type more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types
type: ClusterIP
# This sets the ports more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#field-spec-ports
port: 80
ocppPort: 50051
apiPort: 50052

# This block is for setting up the ingress for more information can be found here: https://kubernetes.io/docs/concepts/services-networking/ingress/
ingress:
Expand Down
2 changes: 1 addition & 1 deletion ocpp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
edition = '2021'
name = "ocpp"
version = "0.1.3"
version = "0.1.4"
publish = false

[dependencies]
Expand Down
1 change: 0 additions & 1 deletion ocpp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>
warn!("No DATABASE_URL env var provided, attempting to connect to database at localhost");
"postgres://postgres:password@localhost/postgres".to_string()
});
dbg!(&database_url);
let pool = PgPoolOptions::new()
.max_connections(5)
.connect(&database_url)
Expand Down
9 changes: 8 additions & 1 deletion ocpp/src/ocpp/start_ocpp_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use crate::ocpp::ocpp_handler::ocpp_handler;
use poem::listener::TcpListener;
use poem::{get, EndpointExt, Route, Server};
use shared::{Config, DataStore};
use std::env;
use std::net::SocketAddr;
use std::sync::Arc;
use tokio::signal::unix::{signal, SignalKind};
use tracing::{info, instrument};
Expand All @@ -17,7 +19,12 @@ pub async fn start_ocpp_server(
"/:id",
get(ocpp_handler).data((config.clone(), data_store, charger_pool.clone())),
);
Server::new(TcpListener::bind("192.168.1.83:50051"))

let host = env::var("HOST").unwrap_or_else(|_| "127.0.0.1".to_string());
let port = env::var("OCPP_PORT").unwrap_or_else(|_| "50051".to_string());
let addr: SocketAddr = format!("{}:{}", host, port).parse().unwrap();

Server::new(TcpListener::bind(addr))
.run_with_graceful_shutdown(
app,
async {
Expand Down
5 changes: 4 additions & 1 deletion ocpp/src/server/start_server.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::charger::ChargerPool;
use crate::ocpp_csms_server::ocpp_server::OcppServer;
use crate::server::ocpp_service::OcppService;
use std::env;
use std::net::SocketAddr;
use tonic::transport::Server;
use tracing::{info, instrument};
Expand All @@ -14,7 +15,9 @@ pub async fn start_server(
.set_serving::<OcppServer<OcppService>>()
.await;

let addr: SocketAddr = "[::1]:50052".parse().unwrap();
let host = env::var("HOST").unwrap_or_else(|_| "127.0.0.1".to_string());
let port = env::var("API_PORT").unwrap_or_else(|_| "50052".to_string());
let addr: SocketAddr = format!("{}:{}", host, port).parse().unwrap();

info!(address = addr.to_string(), "starting grpc server endpoint");

Expand Down

0 comments on commit 4352aac

Please sign in to comment.