Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove envoy from default docker compose #37

Merged
merged 1 commit into from
Mar 22, 2024
Merged
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ Charge stations can connect to the CSMS using:
* `ws://localhost/ws/<cs-id>`
* `wss://localhost/ws/<cs-id>`

If the charge station is also running in a Docker container then the charge
station docker container can connect to the `maeve-csms` network and the
charge station can connect to the CSMS using:
* `ws://gateway:9310/ws/<cs-id>`
* `wss://gateway:9311/ws/<cs-id>`

Charge stations can use either OCPP 1.6j or OCPP 2.0.1.

For TLS, the charge station should use a certificate provisioned using the
Expand Down
2 changes: 1 addition & 1 deletion config/manager/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mqtt.urls = ["mqtt://mqtt:1883"]

[ocpi]
addr = ":9411"
external_url = "http://lb:9411"
external_url = "http://manager:9411"
country_code = "GB"
party_id = "TWK"

Expand Down
149 changes: 149 additions & 0 deletions docker-compose-with-lb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
networks:
default:
name: maeve-csms
enable_ipv6: true
ipam:
config:
- subnet: 2001:db8:a::/64
gateway: 2001:db8:a::1

services:
mqtt:
image: eclipse-mosquitto:2
volumes:
- type: bind
source: ./config/mosquitto
target: /mosquitto/config
read_only: true
ports:
- "1883:1883"
- "9000:9000"
user: "10000:10000"
healthcheck:
test: ["CMD-SHELL", "timeout 5 mosquitto_sub -t '$$SYS/#' -C 1 | grep -v Error || exit 1"]
interval: 10s
timeout: 10s
retries: 3

lb:
image: envoyproxy/envoy:v1.26-latest
command: ["-c", "/config/envoy.yaml"]
volumes:
- type: bind
source: ./config/envoy
target: /config
read_only: true
depends_on:
manager:
condition: service_healthy
gateway:
condition: service_healthy
ports:
- "80:80"
- "443:443"
- "9410:9410"
- "9411:9411"

gateway:
build:
context: gateway
depends_on:
mqtt:
condition: service_healthy
manager:
condition: service_healthy
command:
- "serve"
- "--ws-addr"
- ":9310"
- "--wss-addr"
- ":9311"
- "--status-addr"
- ":9312"
- "--tls-server-cert"
- "/certificates/csms.pem"
- "--tls-server-key"
- "/certificates/csms.key"
- "--tls-trust-cert"
- "/certificates/trust.pem"
- "--mqtt-addr"
- "mqtt://mqtt:1883"
- "--manager-api-addr"
- "http://manager:9410"
expose:
- "9310"
- "9311"
- "9312"
volumes:
- type: bind
source: ./config/certificates
target: /certificates
read_only: true
healthcheck:
test: ["CMD", "/usr/bin/curl", "-s", "--fail", "http://localhost:9312/health"]
interval: 10s
timeout: 10s
retries: 3
user: "10000:10000"

manager:
build:
context: manager
depends_on:
mqtt:
condition: service_healthy
environment:
ENVIRONMENT: dev
FIRESTORE_EMULATOR_HOST: firestore:8080
command:
- "serve"
- "-c"
- "/config/config.toml"
volumes:
- type: bind
source: ./config/certificates
target: /certificates
read_only: true
- type: bind
source: ./config/manager
target: /config
read_only: true
expose:
- "9410"
- "9411"
healthcheck:
test: ["CMD", "/usr/bin/curl", "-s", "--fail", "http://localhost:9410/health"]
interval: 10s
timeout: 10s
retries: 3
user: "10000:10000"

firestore:
image: google/cloud-sdk
command:
- gcloud
- emulators
- firestore
- start
- --host-port=0.0.0.0:8080
ports:
- "8080:8080"

grafana:
image: grafana/grafana:7.5.7
profiles:
- perf
ports:
- 3000:3000
restart: unless-stopped

prometheus:
image: prom/prometheus:v2.45.1
profiles:
- perf
ports:
- "9090:9090"
volumes:
- ./prometheus:/etc/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
52 changes: 7 additions & 45 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,6 @@ services:
timeout: 10s
retries: 3

lb:
image: envoyproxy/envoy:v1.26-latest
command: ["-c", "/config/envoy.yaml"]
volumes:
- type: bind
source: ./config/envoy
target: /config
read_only: true
depends_on:
manager:
condition: service_healthy
gateway:
condition: service_healthy
ports:
- "80:80"
- "443:443"
- "9410:9410"
- "9411:9411"

gateway:
build:
context: gateway
Expand All @@ -70,10 +51,10 @@ services:
- "mqtt://mqtt:1883"
- "--manager-api-addr"
- "http://manager:9410"
expose:
- "9310"
- "9311"
- "9312"
ports:
- "80:9310" # charge station ws
- "443:9311" # charge station wss
- "9312:9312" # status
volumes:
- type: bind
source: ./config/certificates
Expand Down Expand Up @@ -108,9 +89,9 @@ services:
source: ./config/manager
target: /config
read_only: true
expose:
- "9410"
- "9411"
ports:
- "9410:9410" # manager api
- "9411:9411" # status
healthcheck:
test: ["CMD", "/usr/bin/curl", "-s", "--fail", "http://localhost:9410/health"]
interval: 10s
Expand All @@ -128,22 +109,3 @@ services:
- --host-port=0.0.0.0:8080
ports:
- "8080:8080"

grafana:
image: grafana/grafana:7.5.7
profiles:
- perf
ports:
- 3000:3000
restart: unless-stopped

prometheus:
image: prom/prometheus:v2.45.1
profiles:
- perf
ports:
- "9090:9090"
volumes:
- ./prometheus:/etc/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
16 changes: 12 additions & 4 deletions manager/adminui/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
res embed.FS
)

func NewServer(externalAddr, orgName string, engine store.Engine, certificateProvider services.ChargeStationCertificateProvider) chi.Router {
func NewServer(host string, wsPort, wssPort int, orgName string, engine store.Engine, certificateProvider services.ChargeStationCertificateProvider) chi.Router {
r := chi.NewRouter()

templates := template.Must(template.ParseFS(res, "templates/*.gohtml"))
Expand Down Expand Up @@ -86,10 +86,14 @@ func NewServer(externalAddr, orgName string, engine store.Engine, certificatePro
_ = templates.ExecuteTemplate(w, "error.gohtml", nil)
return
}
optionalPort := ""
if wsPort != 80 {
optionalPort = fmt.Sprintf(":%d", wsPort)
}
data = map[string]string{
"csid": csId,
"auth": auth,
"url": fmt.Sprintf("ws://%s/ws/%s", externalAddr, csId),
"url": fmt.Sprintf("ws://%s%s/ws/%s", host, optionalPort, csId),
"password": password,
"invalidUsername": invalidUsername,
}
Expand All @@ -106,10 +110,14 @@ func NewServer(externalAddr, orgName string, engine store.Engine, certificatePro
_ = templates.ExecuteTemplate(w, "error.gohtml", nil)
return
}
optionalPort := ""
if wsPort != 443 {
optionalPort = fmt.Sprintf(":%d", wssPort)
}
data = map[string]string{
"csid": csId,
"auth": auth,
"url": fmt.Sprintf("wss://%s/ws/%s", externalAddr, csId),
"url": fmt.Sprintf("wss://%s%s/ws/%s", host, optionalPort, csId),
"password": password,
"invalidUsername": invalidUsername,
}
Expand All @@ -129,7 +137,7 @@ func NewServer(externalAddr, orgName string, engine store.Engine, certificatePro
data = map[string]string{
"csid": csId,
"auth": auth,
"url": fmt.Sprintf("wss://%s/ws/%s", externalAddr, csId),
"url": fmt.Sprintf("wss://%s/ws/%s", host, csId),
"clientCert": clientCert,
"clientKey": clientKey,
}
Expand Down
10 changes: 5 additions & 5 deletions manager/adminui/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestConnectWithUnsecuredAuth(t *testing.T) {
CertificateReader: services.StringSource{Data: caCert},
PrivateKeyReader: services.StringSource{Data: caKey},
}
server := NewServer("localhost:9410", "Example", engine, certificateProvider)
server := NewServer("localhost", 80, 443, "Example", engine, certificateProvider)

r := chi.NewRouter()
r.Mount("/adminui", server)
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestConnectWithBasicAuth(t *testing.T) {
CertificateReader: services.StringSource{Data: caCert},
PrivateKeyReader: services.StringSource{Data: caKey},
}
server := NewServer("localhost:9410", "Example", engine, certificateProvider)
server := NewServer("localhost", 80, 443, "Example", engine, certificateProvider)

r := chi.NewRouter()
r.Mount("/adminui", server)
Expand Down Expand Up @@ -125,7 +125,7 @@ func TestConnectWithMTLS(t *testing.T) {
CertificateReader: services.StringSource{Data: caCert},
PrivateKeyReader: services.StringSource{Data: caKey},
}
server := NewServer("localhost:9410", "Example", engine, certificateProvider)
server := NewServer("localhost", 80, 443, "Example", engine, certificateProvider)

r := chi.NewRouter()
r.Mount("/adminui", server)
Expand Down Expand Up @@ -165,7 +165,7 @@ func TestConnectWithMTLS(t *testing.T) {
func TestRegisterTokenWithShortUid(t *testing.T) {
engine := inmemory.NewStore(clock.RealClock{})

server := NewServer("localhost:9410", "Example", engine, nil)
server := NewServer("localhost", 80, 443, "Example", engine, nil)

r := chi.NewRouter()
r.Mount("/adminui", server)
Expand Down Expand Up @@ -207,7 +207,7 @@ func TestRegisterTokenWithShortUid(t *testing.T) {
func TestRegisterTokenWithLongUid(t *testing.T) {
engine := inmemory.NewStore(clock.RealClock{})

server := NewServer("localhost:9410", "Example", engine, nil)
server := NewServer("localhost", 80, 443, "Example", engine, nil)

r := chi.NewRouter()
r.Mount("/adminui", server)
Expand Down
8 changes: 5 additions & 3 deletions manager/config/base_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ type BaseConfig struct {
// read from the TOML file will overlay this configuration.
var DefaultConfig = BaseConfig{
Api: ApiSettingsConfig{
Addr: "localhost:9410",
ExternalAddr: "localhost:9410",
OrgName: "Thoughtworks",
Addr: "localhost:9410",
Host: "localhost",
WsPort: 80,
WssPort: 443,
OrgName: "Thoughtworks",
},
Transport: TransportConfig{
Type: "mqtt",
Expand Down
8 changes: 5 additions & 3 deletions manager/config/base_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ func TestParseConfig(t *testing.T) {

want := &config.BaseConfig{
Api: config.ApiSettingsConfig{
Addr: ":9410",
ExternalAddr: "https://example.com/",
OrgName: "Example",
Addr: ":9410",
Host: "example.com",
WsPort: 80,
WssPort: 443,
OrgName: "Example",
},
Transport: config.TransportConfig{
Type: "mqtt",
Expand Down
Loading
Loading