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

Dockerize cloudcore server #3

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion cmd/cloudcore-server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ FROM scratch

COPY cloudcore /cloudcore

ENTRYPOINT ["cloudcore"]
ENTRYPOINT ["/cloudcore"]
9 changes: 7 additions & 2 deletions cmd/cloudcore-server/server/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package server

import (
"context"
"fmt"
"github.com/clarkmcc/brpc"
"github.com/clarkmcc/cloudcore/cmd/cloudcore-server/config"
"github.com/clarkmcc/cloudcore/cmd/cloudcore-server/database"
"github.com/clarkmcc/cloudcore/cmd/cloudcore-server/services"
"github.com/clarkmcc/cloudcore/internal/example"
"github.com/clarkmcc/cloudcore/internal/envtls"
"github.com/clarkmcc/cloudcore/internal/rpc"
"github.com/clarkmcc/cloudcore/internal/token"
"github.com/quic-go/quic-go"
Expand Down Expand Up @@ -39,7 +40,11 @@ func New(

lc.Append(fx.Hook{
OnStart: func(_ context.Context) error {
l, err := quic.ListenAddr(":"+strconv.Itoa(config.AgentServer.Port), example.TLSConfig(), nil)
cfg, err := envtls.TLSConfig()
if err != nil {
return fmt.Errorf("getting tls config: %w", err)
}
l, err := quic.ListenAddr(":"+strconv.Itoa(config.AgentServer.Port), cfg, nil)
if err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions deploy/helm/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.md
.git
.gitignore
5 changes: 5 additions & 0 deletions deploy/helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v2
name: cloudcore
description: A Helm chart for the CloudCore application
version: 0.1.0
appVersion: "0.1.0"
42 changes: 42 additions & 0 deletions deploy/helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: cloudcore
spec:
replicas: 1
selector:
matchLabels:
app: cloudcore
template:
metadata:
labels:
app: cloudcore
spec:
containers:
- name: cloudcore
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- containerPort: {{ .Values.service.agentServer.port }}
- containerPort: {{ .Values.service.appServer.port }}
env:
- name: AGENT_SERVER_PORT
value: "{{ .Values.env.agentServerPort }}"
- name: APP_SERVER_PORT
value: "{{ .Values.env.appServerPort }}"
- name: AUTH0_DOMAIN
value: "{{ .Values.env.auth0Domain }}"
- name: AUTH0_AUDIENCE
value: "{{ .Values.env.auth0Audience }}"
- name: LOGGING_LEVEL
value: "{{ .Values.env.loggingLevel }}"
- name: AUTH_TOKEN_SIGNING_SECRET
valueFrom:
secretKeyRef:
name: cloudcore-secret
key: authTokenSigningSecret
- name: DATABASE_CONNECTION_STRING
valueFrom:
secretKeyRef:
name: cloudcore-secret
key: databaseConnectionString
8 changes: 8 additions & 0 deletions deploy/helm/templates/secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Secret
metadata:
name: cloudcore-secret
type: Opaque
data:
authTokenSigningSecret: {{ randAlphaNum 32 | b64enc | quote }}
databaseConnectionString: {{ .Values.env.databaseConnectionString | b64enc | quote }}
25 changes: 25 additions & 0 deletions deploy/helm/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
apiVersion: v1
kind: Service
metadata:
name: agent-server-service
spec:
type: ClusterIP
ports:
- port: {{ .Values.service.agentServer.port }}
targetPort: {{ .Values.service.agentServer.port }}
selector:
app: cloudcore

---
apiVersion: v1
kind: Service
metadata:
name: app-server-service
spec:
type: ClusterIP
ports:
- port: {{ .Values.service.appServer.port }}
targetPort: {{ .Values.service.appServer.port }}
selector:
app: cloudcore
19 changes: 19 additions & 0 deletions deploy/helm/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
image:
repository: ghcr.io/clarkmcc/cloudcore
pullPolicy: Always
tag: "latest"

service:
agentServer:
port: 10000
appServer:
port: 10001

env:
agentServerPort: 10000
appServerPort: 10001
auth0Domain: ""
auth0Audience: ""
loggingLevel: ""
authTokenSigningSecret: "" # This will be set in the deployment
databaseConnectionString: "" # This will be set from a secret
27 changes: 27 additions & 0 deletions internal/envtls/envtls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//go:build !dev

package envtls

import (
"crypto/tls"
"fmt"
"os"
)

func TLSConfig() (*tls.Config, error) {
c := os.Getenv("TLS_CERTIFICATE")
if len(c) == 0 {
return nil, fmt.Errorf("missing tls certificate")
}
k := os.Getenv("TLS_PRIVATE_KEY")
if len(k) == 0 {
return nil, fmt.Errorf("missing tls certificate")
}
cert, err := tls.X509KeyPair([]byte(c), []byte(k))
if err != nil {
panic(err)
}
return &tls.Config{
Certificates: []tls.Certificate{cert},
}, nil
}
12 changes: 12 additions & 0 deletions internal/envtls/envtls_dev.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build dev

package envtls

import (
"crypto/tls"
"github.com/clarkmcc/cloudcore/internal/envtls/example"
)

func TLSConfig() (*tls.Config, error) {
return example.TLSConfig(), nil
}
File renamed without changes.
File renamed without changes.