From 1f99d5a8a014e6ba238e24778bdad0759645f162 Mon Sep 17 00:00:00 2001 From: Roger Sacchelli Date: Sun, 7 Apr 2024 15:26:04 +0000 Subject: [PATCH 01/20] k8s deployment files --- deploy/kubernetes/adapter.yaml | 39 +++++++++++++++++++++++ deploy/kubernetes/controller.yaml | 39 +++++++++++++++++++++++ deploy/kubernetes/frontend.yaml | 36 ++++++++++++++++++++++ deploy/kubernetes/mongodb.yaml | 36 ++++++++++++++++++++++ deploy/kubernetes/mqtt-adapter.yaml | 44 ++++++++++++++++++++++++++ deploy/kubernetes/mqtt.yaml | 48 +++++++++++++++++++++++++++++ deploy/kubernetes/socketio.yaml | 21 +++++++++++++ 7 files changed, 263 insertions(+) create mode 100644 deploy/kubernetes/adapter.yaml create mode 100644 deploy/kubernetes/controller.yaml create mode 100644 deploy/kubernetes/frontend.yaml create mode 100644 deploy/kubernetes/mongodb.yaml create mode 100644 deploy/kubernetes/mqtt-adapter.yaml create mode 100644 deploy/kubernetes/mqtt.yaml create mode 100644 deploy/kubernetes/socketio.yaml diff --git a/deploy/kubernetes/adapter.yaml b/deploy/kubernetes/adapter.yaml new file mode 100644 index 0000000..d2d2d23 --- /dev/null +++ b/deploy/kubernetes/adapter.yaml @@ -0,0 +1,39 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: adapter +spec: + replicas: 1 + selector: + matchLabels: + app: adapter + strategy: + type: Recreate # Specify the Recreate strategy + template: + metadata: + labels: + app: adapter + spec: + containers: + - name: adapter + image: oktopusp/adapter:latest + resources: + requests: + memory: 64Mi + cpu: 0.1 + limits: + memory: 128Mi + cpu: 0.2 + imagePullPolicy: IfNotPresent + env: + - name: NATS_URL + value: "nats://nats:4222" + - name: NATS_NAME + value: "adapter" + - name: NATS_VERIFY_CERTIFICATES + value: "false" + - name: MONGO_URI + value: "mongodb://oktopusp:oktopusp@mongodb-0.mongodb-svc.mongodb.svc.cluster.local:27017,mongodb-1.mongodb-svc.mongodb.svc.cluster.local:27017,mongodb-2.mongodb-svc.mongodb.svc.cluster.local:27017/adapter?replicaSet=mongodb&ssl=false" + - name: CONTROLLER_ID + value: "oktopusController" + diff --git a/deploy/kubernetes/controller.yaml b/deploy/kubernetes/controller.yaml new file mode 100644 index 0000000..02d3416 --- /dev/null +++ b/deploy/kubernetes/controller.yaml @@ -0,0 +1,39 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: controller +spec: + replicas: 1 + selector: + matchLabels: + app: controller + strategy: + type: Recreate # Specify the Recreate strategy + template: + metadata: + labels: + app: controller + spec: + containers: + - name: controller + image: oktopusp/controller:latest + resources: + #requests: + # memory: 64Mi + # cpu: 0.5 + #limits: + # memory: 256Mi + # cpu: 1 + imagePullPolicy: IfNotPresent + env: + - name: NATS_URL + value: "nats://nats:4222" + - name: NATS_NAME + value: "adapter" + - name: NATS_VERIFY_CERTIFICATES + value: "false" + - name: MONGO_URI + value: "mongodb://oktopusp:oktopusp@mongodb-0.mongodb-svc.mongodb.svc.cluster.local:27017,mongodb-1.mongodb-svc.mongodb.svc.cluster.local:27017,mongodb-2.mongodb-svc.mongodb.svc.cluster.local:27017/adapter?replicaSet=mongodb&ssl=false" + - name: REST_API_PORT + value: "8000" + diff --git a/deploy/kubernetes/frontend.yaml b/deploy/kubernetes/frontend.yaml new file mode 100644 index 0000000..d698898 --- /dev/null +++ b/deploy/kubernetes/frontend.yaml @@ -0,0 +1,36 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: frontend +spec: + replicas: 1 + selector: + matchLabels: + app: frontend + strategy: + type: Recreate # Specify the Recreate strategy + template: + metadata: + labels: + app: frontend + spec: + containers: + - name: frontend + image: oktopusp/frontend:latest + ports: + - containerPort: 3000 + imagePullPolicy: IfNotPresent +--- +apiVersion: v1 +kind: Service +metadata: + name: frontend-svc +spec: + selector: + app: frontend + ports: + - protocol: TCP + port: 3000 + targetPort: 3000 + nodePort: 30001 + type: NodePort diff --git a/deploy/kubernetes/mongodb.yaml b/deploy/kubernetes/mongodb.yaml new file mode 100644 index 0000000..aeb36b0 --- /dev/null +++ b/deploy/kubernetes/mongodb.yaml @@ -0,0 +1,36 @@ +--- +apiVersion: mongodbcommunity.mongodb.com/v1 +kind: MongoDBCommunity +metadata: + name: mongodb +spec: + members: 3 + type: ReplicaSet + version: "6.0.5" + security: + authentication: + modes: ["SCRAM"] + users: + - name: oktopusp + db: admin + passwordSecretRef: # a reference to the secret that will be used to generate the user's password + name: mongo-secret + roles: + - name: clusterAdmin + db: admin + - name: userAdminAnyDatabase + db: admin + scramCredentialsSecretName: my-scram + additionalMongodConfig: + storage.wiredTiger.engineConfig.journalCompressor: zlib + +# the user credentials will be generated from this secret +# once the credentials are generated, this secret is no longer required +--- +apiVersion: v1 +kind: Secret +metadata: + name: mongo-secret +type: Opaque +stringData: + password: oktopusp diff --git a/deploy/kubernetes/mqtt-adapter.yaml b/deploy/kubernetes/mqtt-adapter.yaml new file mode 100644 index 0000000..3d7b7b5 --- /dev/null +++ b/deploy/kubernetes/mqtt-adapter.yaml @@ -0,0 +1,44 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: mqtt-adapter +spec: + replicas: 1 + selector: + matchLabels: + app: mqtt-adapter + template: + metadata: + labels: + app: mqtt-adapter + spec: + containers: + - name: mqtt-adapter + image: oktopusp/mqtt-adapter:latest + resources: + requests: + memory: 64Mi + cpu: 0.1 + limits: + memory: 128Mi + cpu: 0.2 + imagePullPolicy: IfNotPresent + env: + - name: NATS_URL + value: "nats:4222" + - name: NATS_NAME + value: "mqtt-adapter" + - name: NATS_VERIFY_CERTIFICATES + value: "false" + - name: MQTT_URL + value: "tcp://mqtt:1883" + - name: MQTT_CLIENT_ID + value: "mqtt-adapter" + - name: MQTT_USERNAME + value: "" + - name: MQTT_PASSWORD + value: "" + - name: MQTT_QOS + value: "1" + - name: MQTT_SERVICE_HOST + value: "mqtt" diff --git a/deploy/kubernetes/mqtt.yaml b/deploy/kubernetes/mqtt.yaml new file mode 100644 index 0000000..8ff06c7 --- /dev/null +++ b/deploy/kubernetes/mqtt.yaml @@ -0,0 +1,48 @@ +apiVersion: v1 +kind: Service +metadata: + name: mqtt +spec: + selector: + app: mqtt + ports: + - protocol: TCP + port: 1883 + targetPort: 1883 + nodePort: 30000 + type: NodePort +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: mqtt +spec: + replicas: 1 + selector: + matchLabels: + app: mqtt + template: + metadata: + labels: + app: mqtt + spec: + containers: + - name: mqtt + image: rogersacchelli/mqtt:latest + ports: + - containerPort: 1883 + resources: + requests: + memory: 64Mi + cpu: 0.1 + limits: + memory: 128Mi + cpu: 0.2 + imagePullPolicy: IfNotPresent + env: + - name: MQTT_PORT + value: ":1883" + - name: MQTT_TLS + value: "false" + - name: LOG_LEVEL + value: "0" # 0 - DEBUG diff --git a/deploy/kubernetes/socketio.yaml b/deploy/kubernetes/socketio.yaml new file mode 100644 index 0000000..86a9e5a --- /dev/null +++ b/deploy/kubernetes/socketio.yaml @@ -0,0 +1,21 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: socketio +spec: + replicas: 1 + selector: + matchLabels: + app: socketio + template: + metadata: + labels: + app: socketio + spec: + containers: + - name: socketio + image: oktopusp/socketio:latest + imagePullPolicy: IfNotPresent + env: + - name: NATS_URL + value: "nats:4222" From 76ddc8328a622619aed24be624cb79212c789ea1 Mon Sep 17 00:00:00 2001 From: Roger Sacchelli Date: Tue, 9 Apr 2024 22:34:40 -0300 Subject: [PATCH 02/20] frontend actions --- .github/workflow/frontend.yaml | 43 ++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflow/frontend.yaml diff --git a/.github/workflow/frontend.yaml b/.github/workflow/frontend.yaml new file mode 100644 index 0000000..bd87ef0 --- /dev/null +++ b/.github/workflow/frontend.yaml @@ -0,0 +1,43 @@ +name: Oktopus Frontend + +# Controls when the action will run. Triggers the workflow on push or pull request +# events but only for the master branch +on: + push: + branches: [ dev ] + pull_request: + branches: [ dev ] + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + - + name: Checkout + uses: actions/checkout@v2 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - + name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push + uses: docker/build-push-action@v2 + with: + context: ./ + file: ./frontend/build/Dockerfile + platforms: linux/amd64 + push: true + tags: rogersacchelli/frontend:latest \ No newline at end of file From 26cb9760d63d14623b8ecc71cc58aefc31a8f773 Mon Sep 17 00:00:00 2001 From: Roger Sacchelli Date: Tue, 9 Apr 2024 22:38:55 -0300 Subject: [PATCH 03/20] frontend wf --- .github/{workflow => workflows}/frontend.yaml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{workflow => workflows}/frontend.yaml (100%) diff --git a/.github/workflow/frontend.yaml b/.github/workflows/frontend.yaml similarity index 100% rename from .github/workflow/frontend.yaml rename to .github/workflows/frontend.yaml From 79523310e11df1db8aafa10e07a7507c133c5b0e Mon Sep 17 00:00:00 2001 From: vagrant Date: Wed, 10 Apr 2024 01:52:02 +0000 Subject: [PATCH 04/20] mqtt request to 256Mib --- deploy/kubernetes/mqtt.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/kubernetes/mqtt.yaml b/deploy/kubernetes/mqtt.yaml index 8ff06c7..b1b9b13 100644 --- a/deploy/kubernetes/mqtt.yaml +++ b/deploy/kubernetes/mqtt.yaml @@ -36,7 +36,7 @@ spec: memory: 64Mi cpu: 0.1 limits: - memory: 128Mi + memory: 256Mi cpu: 0.2 imagePullPolicy: IfNotPresent env: From 5a8cdb813e41e16dd9196c0a35471e39f46606f1 Mon Sep 17 00:00:00 2001 From: Roger Sacchelli Date: Tue, 9 Apr 2024 23:26:14 -0300 Subject: [PATCH 05/20] build edit wf test --- .github/workflows/frontend.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/frontend.yaml b/.github/workflows/frontend.yaml index bd87ef0..5807825 100644 --- a/.github/workflows/frontend.yaml +++ b/.github/workflows/frontend.yaml @@ -11,7 +11,7 @@ on: # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: # This workflow contains a single job called "build" - build: + build-frontend: # The type of runner that the job will run on runs-on: ubuntu-latest @@ -36,7 +36,7 @@ jobs: name: Build and push uses: docker/build-push-action@v2 with: - context: ./ + context: ../ file: ./frontend/build/Dockerfile platforms: linux/amd64 push: true From 020f4542a767aa149799f1880d0ede861d406a09 Mon Sep 17 00:00:00 2001 From: Roger Sacchelli Date: Tue, 9 Apr 2024 23:30:30 -0300 Subject: [PATCH 06/20] mqtt workflow --- .github/workflows/mqtt.yaml | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/mqtt.yaml diff --git a/.github/workflows/mqtt.yaml b/.github/workflows/mqtt.yaml new file mode 100644 index 0000000..3cf9d59 --- /dev/null +++ b/.github/workflows/mqtt.yaml @@ -0,0 +1,43 @@ +name: Oktopus MQTT Brocker + +# Controls when the action will run. Triggers the workflow on push or pull request +# events but only for the master branch +on: + push: + branches: [ dev ] + pull_request: + branches: [ dev ] + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build-mqtt: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + - + name: Checkout + uses: actions/checkout@v2 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - + name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push + uses: docker/build-push-action@v2 + with: + context: ../ + file: ./backend/mtp/mqtt/build/Dockerfile + platforms: linux/amd64 + push: true + tags: rogersacchelli/mqtt:latest \ No newline at end of file From 9e7a06d99366c7da4c0302c1e4571b31664d0a23 Mon Sep 17 00:00:00 2001 From: Roger Sacchelli Date: Tue, 9 Apr 2024 23:34:14 -0300 Subject: [PATCH 07/20] fix path mqtt --- .github/workflows/mqtt.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/mqtt.yaml b/.github/workflows/mqtt.yaml index 3cf9d59..5bb6d72 100644 --- a/.github/workflows/mqtt.yaml +++ b/.github/workflows/mqtt.yaml @@ -37,7 +37,7 @@ jobs: uses: docker/build-push-action@v2 with: context: ../ - file: ./backend/mtp/mqtt/build/Dockerfile + file: ./backend/services/mtp/mqtt/build/Dockerfile platforms: linux/amd64 push: true tags: rogersacchelli/mqtt:latest \ No newline at end of file From 8d8423d082990b10df360d8ee751b4013f58f725 Mon Sep 17 00:00:00 2001 From: Roger Date: Wed, 10 Apr 2024 17:03:59 +0000 Subject: [PATCH 08/20] Missing Files for Deployment --- deploy/kubernetes/controller.yaml | 28 ++++++++++++----- deploy/kubernetes/frontend.yaml | 8 ++++- deploy/kubernetes/socketio.yaml | 14 +++++++++ deploy/kubernetes/ws-adapter.yaml | 46 +++++++++++++++++++++++++++ deploy/kubernetes/ws.yaml | 52 +++++++++++++++++++++++++++++++ frontend/build/Dockerfile | 4 +-- 6 files changed, 142 insertions(+), 10 deletions(-) create mode 100644 deploy/kubernetes/ws-adapter.yaml create mode 100644 deploy/kubernetes/ws.yaml diff --git a/deploy/kubernetes/controller.yaml b/deploy/kubernetes/controller.yaml index 02d3416..a4dba2b 100644 --- a/deploy/kubernetes/controller.yaml +++ b/deploy/kubernetes/controller.yaml @@ -8,7 +8,7 @@ spec: matchLabels: app: controller strategy: - type: Recreate # Specify the Recreate strategy + type: Recreate template: metadata: labels: @@ -18,12 +18,12 @@ spec: - name: controller image: oktopusp/controller:latest resources: - #requests: - # memory: 64Mi - # cpu: 0.5 - #limits: - # memory: 256Mi - # cpu: 1 + # requests: + # memory: 64Mi + # cpu: 0.5 + # limits: + # memory: 256Mi + # cpu: 1 imagePullPolicy: IfNotPresent env: - name: NATS_URL @@ -36,4 +36,18 @@ spec: value: "mongodb://oktopusp:oktopusp@mongodb-0.mongodb-svc.mongodb.svc.cluster.local:27017,mongodb-1.mongodb-svc.mongodb.svc.cluster.local:27017,mongodb-2.mongodb-svc.mongodb.svc.cluster.local:27017/adapter?replicaSet=mongodb&ssl=false" - name: REST_API_PORT value: "8000" +--- +apiVersion: v1 +kind: Service +metadata: + name: controller-svc +spec: + selector: + app: controller + ports: + - protocol: TCP + port: 8000 + targetPort: 8000 + nodePort: 30003 + type: NodePort diff --git a/deploy/kubernetes/frontend.yaml b/deploy/kubernetes/frontend.yaml index d698898..bacd928 100644 --- a/deploy/kubernetes/frontend.yaml +++ b/deploy/kubernetes/frontend.yaml @@ -16,10 +16,16 @@ spec: spec: containers: - name: frontend - image: oktopusp/frontend:latest + image: rogersacchelli/frontend:latest ports: - containerPort: 3000 imagePullPolicy: IfNotPresent + env: + - name: NEXT_PUBLIC_REST_ENPOINT + value: "tcp://10.10.10.10:1234" + - name: NEXT_PUBLIC_WS_ENPOINT + value: "tcp://10.11.12.13:2343" + --- apiVersion: v1 kind: Service diff --git a/deploy/kubernetes/socketio.yaml b/deploy/kubernetes/socketio.yaml index 86a9e5a..76c730d 100644 --- a/deploy/kubernetes/socketio.yaml +++ b/deploy/kubernetes/socketio.yaml @@ -19,3 +19,17 @@ spec: env: - name: NATS_URL value: "nats:4222" +--- +apiVersion: v1 +kind: Service +metadata: + name: socketio-svc +spec: + selector: + app: socketio + ports: + - protocol: TCP + port: 5000 + targetPort: 5000 + NodePort: 30002 + type: NodePort diff --git a/deploy/kubernetes/ws-adapter.yaml b/deploy/kubernetes/ws-adapter.yaml new file mode 100644 index 0000000..3be4722 --- /dev/null +++ b/deploy/kubernetes/ws-adapter.yaml @@ -0,0 +1,46 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: ws-adapter +spec: + replicas: 1 + selector: + matchLabels: + app: ws-adapter + template: + metadata: + labels: + app: ws-adapter + spec: + containers: + - name: ws-adapter + image: oktopusp/ws-adapter:latest + resources: + #requests: + # memory: 64Mi + # cpu: 0.1 + #limits: + # memory: 256Mi + # cpu: 0.2 + imagePullPolicy: IfNotPresent + env: + - name: NATS_URL + value: "nats://nats:4222" + - name: NATS_NAME + value: "ws-adapter" + - name: NATS_VERIFY_CERTIFICATES + value: "0" # 0 - DEBUG + - name: WS_TOKEN + value: "" + - name: WS_AUTH_ENABLE + value: "false" + - name: WS_ADDR + value: "ws-svc" + - name: WS_PORT + value: ":8080" + - name: WS_ROUTE + value: "/ws/controller" + - name: WS_TLS_ENABLE + value: "false" + - name: WS_SKIP_TLS_VERIFY + value: "false" diff --git a/deploy/kubernetes/ws.yaml b/deploy/kubernetes/ws.yaml new file mode 100644 index 0000000..df38bc3 --- /dev/null +++ b/deploy/kubernetes/ws.yaml @@ -0,0 +1,52 @@ +apiVersion: v1 +kind: Service +metadata: + name: ws-svc +spec: + selector: + app: ws + ports: + - protocol: TCP + port: 8080 + targetPort: 8080 + nodePort: 30005 + type: NodePort +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: ws +spec: + replicas: 1 + selector: + matchLabels: + app: ws + template: + metadata: + labels: + app: ws + spec: + containers: + - name: ws + image: oktopusp/ws:latest + ports: + - containerPort: 8080 + #resources: + #requests: + #memory: 64Mi + #cpu: 0.1 + #limits: + #memory: 256Mi + #cpu: 0.2 + imagePullPolicy: IfNotPresent + env: + - name: SERVER_PORT + value: ":8080" + - name: SERVER_AUTH_TOKEN + value: "" + - name: SERVER_AUTH_ENABLE + value: "false" + - name: CONTROLLER_EID + value: "oktopusController" + - name: SERVER_TLS_ENABLE + value: "false" diff --git a/frontend/build/Dockerfile b/frontend/build/Dockerfile index 5c9d862..8a9893e 100644 --- a/frontend/build/Dockerfile +++ b/frontend/build/Dockerfile @@ -2,7 +2,7 @@ FROM node:16.20.2-alpine as builder WORKDIR /app -COPY ../ . +COPY ./ ./ RUN npm install @@ -26,4 +26,4 @@ RUN chmod 755 entrypoint.sh ENTRYPOINT ["/app/entrypoint.sh"] -CMD [ "npm", "run", "start" ] \ No newline at end of file +CMD [ "npm", "run", "start" ] From f9f6921e7be09a343e80fa7e0ea2cc5538e0461b Mon Sep 17 00:00:00 2001 From: Roger Date: Fri, 12 Apr 2024 02:05:45 +0000 Subject: [PATCH 09/20] frontend and socketio --- deploy/kubernetes/frontend.yaml | 4 ++-- deploy/kubernetes/socketio.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/deploy/kubernetes/frontend.yaml b/deploy/kubernetes/frontend.yaml index bacd928..78a8421 100644 --- a/deploy/kubernetes/frontend.yaml +++ b/deploy/kubernetes/frontend.yaml @@ -22,9 +22,9 @@ spec: imagePullPolicy: IfNotPresent env: - name: NEXT_PUBLIC_REST_ENPOINT - value: "tcp://10.10.10.10:1234" + value: "192.168.1.130:30003" - name: NEXT_PUBLIC_WS_ENPOINT - value: "tcp://10.11.12.13:2343" + value: "192.168.1.130:30002" --- apiVersion: v1 diff --git a/deploy/kubernetes/socketio.yaml b/deploy/kubernetes/socketio.yaml index 76c730d..a51c5fd 100644 --- a/deploy/kubernetes/socketio.yaml +++ b/deploy/kubernetes/socketio.yaml @@ -31,5 +31,5 @@ spec: - protocol: TCP port: 5000 targetPort: 5000 - NodePort: 30002 + nodePort: 30002 type: NodePort From 2ae3286e87f2e8fc8409025fb4e2911fac0111fc Mon Sep 17 00:00:00 2001 From: Roger Date: Fri, 12 Apr 2024 03:47:00 +0000 Subject: [PATCH 10/20] Fix MQTT Workflow, mongodb operator user permissions --- .github/workflows/mqtt.yaml | 8 ++++---- backend/services/mtp/mqtt/build/Dockerfile | 4 ++-- deploy/kubernetes/controller.yaml | 2 +- deploy/kubernetes/frontend.yaml | 2 +- deploy/kubernetes/mongodb.yaml | 2 ++ 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/mqtt.yaml b/.github/workflows/mqtt.yaml index 5bb6d72..13c2286 100644 --- a/.github/workflows/mqtt.yaml +++ b/.github/workflows/mqtt.yaml @@ -1,4 +1,4 @@ -name: Oktopus MQTT Brocker +name: Oktopus MQTT Broker # Controls when the action will run. Triggers the workflow on push or pull request # events but only for the master branch @@ -36,8 +36,8 @@ jobs: name: Build and push uses: docker/build-push-action@v2 with: - context: ../ - file: ./backend/services/mtp/mqtt/build/Dockerfile + context: ./backend/services/mtp/mqtt/ + file: ./build/Dockerfile platforms: linux/amd64 push: true - tags: rogersacchelli/mqtt:latest \ No newline at end of file + tags: rogersacchelli/mqtt:latest diff --git a/backend/services/mtp/mqtt/build/Dockerfile b/backend/services/mtp/mqtt/build/Dockerfile index 2d59c5e..622703d 100644 --- a/backend/services/mtp/mqtt/build/Dockerfile +++ b/backend/services/mtp/mqtt/build/Dockerfile @@ -1,8 +1,8 @@ FROM golang:1.22@sha256:82e07063a1ac3ee59e6f38b1222e32ce88469e4431ff6496cc40fb9a0fc18229 as builder WORKDIR /app -COPY ../ . +COPY . . RUN CGO_ENABLED=0 GOOS=linux go build -o mqtt cmd/mqtt/main.go FROM alpine:3.14@sha256:0f2d5c38dd7a4f4f733e688e3a6733cb5ab1ac6e3cb4603a5dd564e5bfb80eed COPY --from=builder /app/mqtt / -ENTRYPOINT ["/mqtt"] \ No newline at end of file +ENTRYPOINT ["/mqtt"] diff --git a/deploy/kubernetes/controller.yaml b/deploy/kubernetes/controller.yaml index a4dba2b..450317d 100644 --- a/deploy/kubernetes/controller.yaml +++ b/deploy/kubernetes/controller.yaml @@ -33,7 +33,7 @@ spec: - name: NATS_VERIFY_CERTIFICATES value: "false" - name: MONGO_URI - value: "mongodb://oktopusp:oktopusp@mongodb-0.mongodb-svc.mongodb.svc.cluster.local:27017,mongodb-1.mongodb-svc.mongodb.svc.cluster.local:27017,mongodb-2.mongodb-svc.mongodb.svc.cluster.local:27017/adapter?replicaSet=mongodb&ssl=false" + value: "mongodb://oktopusp:oktopusp@mongodb-0.mongodb-svc.mongodb.svc.cluster.local:27017,mongodb-1.mongodb-svc.mongodb.svc.cluster.local:27017,mongodb-2.mongodb-svc.mongodb.svc.cluster.local:27017/?replicaSet=mongodb&ssl=false" - name: REST_API_PORT value: "8000" --- diff --git a/deploy/kubernetes/frontend.yaml b/deploy/kubernetes/frontend.yaml index 78a8421..60a21d4 100644 --- a/deploy/kubernetes/frontend.yaml +++ b/deploy/kubernetes/frontend.yaml @@ -16,7 +16,7 @@ spec: spec: containers: - name: frontend - image: rogersacchelli/frontend:latest + image: oktopusp/frontend:latest ports: - containerPort: 3000 imagePullPolicy: IfNotPresent diff --git a/deploy/kubernetes/mongodb.yaml b/deploy/kubernetes/mongodb.yaml index aeb36b0..c8aaf12 100644 --- a/deploy/kubernetes/mongodb.yaml +++ b/deploy/kubernetes/mongodb.yaml @@ -20,6 +20,8 @@ spec: db: admin - name: userAdminAnyDatabase db: admin + - name: readWriteAnyDatabase + db: admin scramCredentialsSecretName: my-scram additionalMongodConfig: storage.wiredTiger.engineConfig.journalCompressor: zlib From a09c691e81db2d3cb10001a4131a16c2a3861daa Mon Sep 17 00:00:00 2001 From: Roger Sacchelli Date: Fri, 12 Apr 2024 00:50:20 -0300 Subject: [PATCH 11/20] mqtt build --- .github/workflows/mqtt.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/mqtt.yaml b/.github/workflows/mqtt.yaml index 13c2286..9666cfa 100644 --- a/.github/workflows/mqtt.yaml +++ b/.github/workflows/mqtt.yaml @@ -36,7 +36,7 @@ jobs: name: Build and push uses: docker/build-push-action@v2 with: - context: ./backend/services/mtp/mqtt/ + context: ../backend/services/mtp/mqtt/ file: ./build/Dockerfile platforms: linux/amd64 push: true From 317a682e27f132b6ed1fedc10c6de07c7a228b49 Mon Sep 17 00:00:00 2001 From: Roger Sacchelli Date: Fri, 12 Apr 2024 01:06:33 -0300 Subject: [PATCH 12/20] wf mqtt --- .github/workflows/mqtt.yaml | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/.github/workflows/mqtt.yaml b/.github/workflows/mqtt.yaml index 9666cfa..87ec422 100644 --- a/.github/workflows/mqtt.yaml +++ b/.github/workflows/mqtt.yaml @@ -20,9 +20,6 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 @@ -32,12 +29,11 @@ jobs: with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push - uses: docker/build-push-action@v2 - with: - context: ../backend/services/mtp/mqtt/ - file: ./build/Dockerfile - platforms: linux/amd64 - push: true - tags: rogersacchelli/mqtt:latest + + - + name: Build Docker image + run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/mqtt:latest -f backend/services/mtp/mqtt/build/Dockerfile . + - + name: Push Docker image to Docker Hub + run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/mqtt:latest + From c7007538cf1658f71f76ad30ea824cd78344a7be Mon Sep 17 00:00:00 2001 From: Roger Sacchelli Date: Fri, 12 Apr 2024 01:11:51 -0300 Subject: [PATCH 13/20] Dockerfile for mqtt fixed --- backend/services/mtp/mqtt/build/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/services/mtp/mqtt/build/Dockerfile b/backend/services/mtp/mqtt/build/Dockerfile index 622703d..5ea1214 100644 --- a/backend/services/mtp/mqtt/build/Dockerfile +++ b/backend/services/mtp/mqtt/build/Dockerfile @@ -1,6 +1,6 @@ FROM golang:1.22@sha256:82e07063a1ac3ee59e6f38b1222e32ce88469e4431ff6496cc40fb9a0fc18229 as builder WORKDIR /app -COPY . . +COPY ../ ./ RUN CGO_ENABLED=0 GOOS=linux go build -o mqtt cmd/mqtt/main.go FROM alpine:3.14@sha256:0f2d5c38dd7a4f4f733e688e3a6733cb5ab1ac6e3cb4603a5dd564e5bfb80eed From 2cf7dc1046f89861780c9290fdc23364b8825bdb Mon Sep 17 00:00:00 2001 From: Roger Sacchelli Date: Fri, 12 Apr 2024 01:16:38 -0300 Subject: [PATCH 14/20] absolute path set --- .github/workflows/mqtt.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/mqtt.yaml b/.github/workflows/mqtt.yaml index 87ec422..589cb19 100644 --- a/.github/workflows/mqtt.yaml +++ b/.github/workflows/mqtt.yaml @@ -32,7 +32,7 @@ jobs: - name: Build Docker image - run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/mqtt:latest -f backend/services/mtp/mqtt/build/Dockerfile . + run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/mqtt:latest -f backend/services/mtp/mqtt/build/Dockerfile backend/services/mtp/mqtt - name: Push Docker image to Docker Hub run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/mqtt:latest From 772198b63180935e9497c5078915658cf10d80a5 Mon Sep 17 00:00:00 2001 From: Roger Sacchelli Date: Fri, 12 Apr 2024 01:28:07 -0300 Subject: [PATCH 15/20] manual workflow --- .github/workflows/frontend.yaml | 29 +++++++++++++---------------- .github/workflows/mqtt.yaml | 9 +++++---- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/.github/workflows/frontend.yaml b/.github/workflows/frontend.yaml index 5807825..23a52d7 100644 --- a/.github/workflows/frontend.yaml +++ b/.github/workflows/frontend.yaml @@ -3,10 +3,11 @@ name: Oktopus Frontend # Controls when the action will run. Triggers the workflow on push or pull request # events but only for the master branch on: - push: - branches: [ dev ] - pull_request: - branches: [ dev ] + workflow_dispatch: # This event triggers the workflow manually + #push: + # branches: [ dev ] + #pull_request: + # branches: [ dev ] # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: @@ -20,9 +21,6 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 @@ -32,12 +30,11 @@ jobs: with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push - uses: docker/build-push-action@v2 - with: - context: ../ - file: ./frontend/build/Dockerfile - platforms: linux/amd64 - push: true - tags: rogersacchelli/frontend:latest \ No newline at end of file + + - + name: Build Docker image + run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/frontend:latest -f frontend/build/Dockerfile frontend + - + name: Push Docker image to Docker Hub + run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/mqtt:latest + diff --git a/.github/workflows/mqtt.yaml b/.github/workflows/mqtt.yaml index 589cb19..d2cd677 100644 --- a/.github/workflows/mqtt.yaml +++ b/.github/workflows/mqtt.yaml @@ -3,10 +3,11 @@ name: Oktopus MQTT Broker # Controls when the action will run. Triggers the workflow on push or pull request # events but only for the master branch on: - push: - branches: [ dev ] - pull_request: - branches: [ dev ] + workflow_dispatch: # This event triggers the workflow manually + #push: + # branches: [ dev ] + #pull_request: + # branches: [ dev ] # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: From e4b81a8dc0043eac7c5edf7d03e6c8c1c181dc86 Mon Sep 17 00:00:00 2001 From: Roger Sacchelli Date: Fri, 12 Apr 2024 01:34:25 -0300 Subject: [PATCH 16/20] wf dispatch --- .github/workflows/frontend.yaml | 4 ++-- .github/workflows/mqtt.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/frontend.yaml b/.github/workflows/frontend.yaml index 23a52d7..52a0c4f 100644 --- a/.github/workflows/frontend.yaml +++ b/.github/workflows/frontend.yaml @@ -2,8 +2,8 @@ name: Oktopus Frontend # Controls when the action will run. Triggers the workflow on push or pull request # events but only for the master branch -on: - workflow_dispatch: # This event triggers the workflow manually +on: + workflow_dispatch # This event triggers the workflow manually #push: # branches: [ dev ] #pull_request: diff --git a/.github/workflows/mqtt.yaml b/.github/workflows/mqtt.yaml index d2cd677..159fb63 100644 --- a/.github/workflows/mqtt.yaml +++ b/.github/workflows/mqtt.yaml @@ -3,7 +3,7 @@ name: Oktopus MQTT Broker # Controls when the action will run. Triggers the workflow on push or pull request # events but only for the master branch on: - workflow_dispatch: # This event triggers the workflow manually + workflow_dispatch # This event triggers the workflow manually #push: # branches: [ dev ] #pull_request: From 5015633ef4ae52a8a59b99db907cae172dd7a211 Mon Sep 17 00:00:00 2001 From: Roger Sacchelli Date: Fri, 12 Apr 2024 01:36:59 -0300 Subject: [PATCH 17/20] workflow only if commit on main --- .github/workflows/frontend.yaml | 9 ++++----- .github/workflows/mqtt.yaml | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/.github/workflows/frontend.yaml b/.github/workflows/frontend.yaml index 52a0c4f..29831d2 100644 --- a/.github/workflows/frontend.yaml +++ b/.github/workflows/frontend.yaml @@ -3,11 +3,10 @@ name: Oktopus Frontend # Controls when the action will run. Triggers the workflow on push or pull request # events but only for the master branch on: - workflow_dispatch # This event triggers the workflow manually - #push: - # branches: [ dev ] - #pull_request: - # branches: [ dev ] + push: + branches: [ main ] + pull_request: + branches: [ main ] # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: diff --git a/.github/workflows/mqtt.yaml b/.github/workflows/mqtt.yaml index 159fb63..a3d5d91 100644 --- a/.github/workflows/mqtt.yaml +++ b/.github/workflows/mqtt.yaml @@ -3,11 +3,10 @@ name: Oktopus MQTT Broker # Controls when the action will run. Triggers the workflow on push or pull request # events but only for the master branch on: - workflow_dispatch # This event triggers the workflow manually - #push: - # branches: [ dev ] - #pull_request: - # branches: [ dev ] + push: + branches: [ main ] + pull_request: + branches: [ main ] # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: From be5a69f37cb9d934a49e85f8b8243eea0b22217a Mon Sep 17 00:00:00 2001 From: Roger Date: Tue, 16 Apr 2024 23:59:55 +0000 Subject: [PATCH 18/20] Config Map for HAProxy Ingress Controller --- backend/services/mtp/mqtt/build/Dockerfile | 2 +- deploy/kubernetes/README.md | 16 ++++++++++++++++ deploy/kubernetes/frontend.yaml | 8 ++++---- .../haproxy-kubernetes-ingress-cm.yaml | 7 +++++++ deploy/kubernetes/haproxy-tcp-services-cm.yaml | 8 ++++++++ deploy/kubernetes/haproxy-tcp-services.yaml | 8 ++++++++ deploy/kubernetes/mqtt.yaml | 5 ++--- frontend/.env | 10 +++++----- frontend/build/entrypoint.sh | 14 +++++++------- 9 files changed, 58 insertions(+), 20 deletions(-) create mode 100644 deploy/kubernetes/README.md create mode 100644 deploy/kubernetes/haproxy-kubernetes-ingress-cm.yaml create mode 100644 deploy/kubernetes/haproxy-tcp-services-cm.yaml create mode 100644 deploy/kubernetes/haproxy-tcp-services.yaml diff --git a/backend/services/mtp/mqtt/build/Dockerfile b/backend/services/mtp/mqtt/build/Dockerfile index 622703d..7025ca2 100644 --- a/backend/services/mtp/mqtt/build/Dockerfile +++ b/backend/services/mtp/mqtt/build/Dockerfile @@ -2,7 +2,7 @@ FROM golang:1.22@sha256:82e07063a1ac3ee59e6f38b1222e32ce88469e4431ff6496cc40fb9a WORKDIR /app COPY . . RUN CGO_ENABLED=0 GOOS=linux go build -o mqtt cmd/mqtt/main.go - +CMD pwd FROM alpine:3.14@sha256:0f2d5c38dd7a4f4f733e688e3a6733cb5ab1ac6e3cb4603a5dd564e5bfb80eed COPY --from=builder /app/mqtt / ENTRYPOINT ["/mqtt"] diff --git a/deploy/kubernetes/README.md b/deploy/kubernetes/README.md new file mode 100644 index 0000000..bdc26ac --- /dev/null +++ b/deploy/kubernetes/README.md @@ -0,0 +1,16 @@ +# Oktopus Kubernetes + +## Requirements + +### Standalone Installation + +Node: +* 8 vCPUs +* 8 GB RAM + +# Installation + + +## MongoBD + + diff --git a/deploy/kubernetes/frontend.yaml b/deploy/kubernetes/frontend.yaml index 60a21d4..4e61bba 100644 --- a/deploy/kubernetes/frontend.yaml +++ b/deploy/kubernetes/frontend.yaml @@ -16,14 +16,14 @@ spec: spec: containers: - name: frontend - image: oktopusp/frontend:latest + image: rogersacchelli/frontend:1.0.3 ports: - containerPort: 3000 - imagePullPolicy: IfNotPresent + imagePullPolicy: Always env: - - name: NEXT_PUBLIC_REST_ENPOINT + - name: NEXT_PUBLIC_REST_ENDPOINT value: "192.168.1.130:30003" - - name: NEXT_PUBLIC_WS_ENPOINT + - name: NEXT_PUBLIC_WS_ENDPOINT value: "192.168.1.130:30002" --- diff --git a/deploy/kubernetes/haproxy-kubernetes-ingress-cm.yaml b/deploy/kubernetes/haproxy-kubernetes-ingress-cm.yaml new file mode 100644 index 0000000..c4aabd9 --- /dev/null +++ b/deploy/kubernetes/haproxy-kubernetes-ingress-cm.yaml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: haproxy-kubernetes-ingress + namespace: haproxy-controller +data: + syslog-server: "address:stdout, format: raw, facility:daemon" diff --git a/deploy/kubernetes/haproxy-tcp-services-cm.yaml b/deploy/kubernetes/haproxy-tcp-services-cm.yaml new file mode 100644 index 0000000..a4b8f7f --- /dev/null +++ b/deploy/kubernetes/haproxy-tcp-services-cm.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: haproxy-tcp + namespace: default +data: + 1883: # Port where the frontend is going to listen to. + default/mqtt-svc:1883 # Kubernetes service in the format NS/ServiceName:ServicePort diff --git a/deploy/kubernetes/haproxy-tcp-services.yaml b/deploy/kubernetes/haproxy-tcp-services.yaml new file mode 100644 index 0000000..77db1d6 --- /dev/null +++ b/deploy/kubernetes/haproxy-tcp-services.yaml @@ -0,0 +1,8 @@ +controller: + service: + tcpPorts: + - name: mqtt + port: 1883 + targetPort: 1883 + extraArgs: + - --configmap-tcp-services=default/haproxy-tcp diff --git a/deploy/kubernetes/mqtt.yaml b/deploy/kubernetes/mqtt.yaml index b1b9b13..8d78cb6 100644 --- a/deploy/kubernetes/mqtt.yaml +++ b/deploy/kubernetes/mqtt.yaml @@ -1,7 +1,7 @@ apiVersion: v1 kind: Service metadata: - name: mqtt + name: mqtt-svc spec: selector: app: mqtt @@ -9,8 +9,7 @@ spec: - protocol: TCP port: 1883 targetPort: 1883 - nodePort: 30000 - type: NodePort + type: ClusterIP --- apiVersion: apps/v1 kind: Deployment diff --git a/frontend/.env b/frontend/.env index 32e4aa9..141984e 100644 --- a/frontend/.env +++ b/frontend/.env @@ -1,17 +1,17 @@ # ----------------------------- Local Environment ---------------------------- # -NEXT_PUBLIC_REST_ENPOINT="http://localhost:8000/api" -NEXT_PUBLIC_WS_ENPOINT="http://localhost:5000/" +NEXT_PUBLIC_REST_ENDPOINT="http://localhost:8000/api" +NEXT_PUBLIC_WS_ENDPOINT="http://localhost:5000/" # ---------------------------------------------------------------------------- # # -------------------------- Production Environment -------------------------- # -#NEXT_PUBLIC_REST_ENPOINT="https://demo.oktopus.app.br/api" -#NEXT_PUBLIC_WS_ENPOINT="https://demo.oktopus.app.br/" +#NEXT_PUBLIC_REST_ENDPOINT="https://demo.oktopus.app.br/api" +#NEXT_PUBLIC_WS_ENDPOINT="https://demo.oktopus.app.br/" # ---------------------------------------------------------------------------- # # ---------------------------- Mocked Environment ---------------------------- # -#NEXT_PUBLIC_REST_ENPOINT="https://d9962fd9-2464-4a30-9a86-a15a04b57ad0.mock.pstmn.io" +#NEXT_PUBLIC_REST_ENDPOINT="https://d9962fd9-2464-4a30-9a86-a15a04b57ad0.mock.pstmn.io" # ---------------------------------------------------------------------------- # diff --git a/frontend/build/entrypoint.sh b/frontend/build/entrypoint.sh index f4abca7..bf43c58 100644 --- a/frontend/build/entrypoint.sh +++ b/frontend/build/entrypoint.sh @@ -3,16 +3,16 @@ set -Ex function apply_path { - echo "Check that we have NEXT_PUBLIC_REST_ENPOINT vars" - test -n "$NEXT_PUBLIC_REST_ENPOINT" + echo "Check that we have NEXT_PUBLIC_REST_ENDPOINT vars" + test -n "$NEXT_PUBLIC_REST_ENDPOINT" - echo "Check that we have NEXT_PUBLIC_WS_ENPOINT vars" - test -n "$NEXT_PUBLIC_WS_ENPOINT" + echo "Check that we have NEXT_PUBLIC_WS_ENDPOINT vars" + test -n "$NEXT_PUBLIC_WS_ENDPOINT" - find /app/.next \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#REST_API_URL#$NEXT_PUBLIC_REST_ENPOINT#g" - find /app/.next \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#WS_URL#$NEXT_PUBLIC_WS_ENPOINT#g" + find /app/.next \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#REST_API_URL#$NEXT_PUBLIC_REST_ENDPOINT#g" + find /app/.next \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#WS_URL#$NEXT_PUBLIC_WS_ENDPOINT#g" } apply_path echo "Starting Nextjs" -exec "$@" \ No newline at end of file +exec "$@" From 61f93f49e5aeb1dd52cabee1bcc7381711f74e50 Mon Sep 17 00:00:00 2001 From: Roger Sacchelli Date: Tue, 16 Apr 2024 22:56:47 -0300 Subject: [PATCH 19/20] Kubernetes Deployment - WIP --- backend/services/mtp/mqtt/build/Dockerfile | 2 +- deploy/kubernetes/README.md | 77 +++++++++++++++++++++- deploy/kubernetes/backend.yaml | 21 ------ deploy/kubernetes/frontend.yaml | 18 +++-- deploy/kubernetes/mqtt.yaml | 7 +- deploy/kubernetes/ws.yaml | 14 ++-- frontend/build/Dockerfile | 2 +- 7 files changed, 101 insertions(+), 40 deletions(-) delete mode 100644 deploy/kubernetes/backend.yaml diff --git a/backend/services/mtp/mqtt/build/Dockerfile b/backend/services/mtp/mqtt/build/Dockerfile index cb80675..5ea1214 100644 --- a/backend/services/mtp/mqtt/build/Dockerfile +++ b/backend/services/mtp/mqtt/build/Dockerfile @@ -2,7 +2,7 @@ FROM golang:1.22@sha256:82e07063a1ac3ee59e6f38b1222e32ce88469e4431ff6496cc40fb9a WORKDIR /app COPY ../ ./ RUN CGO_ENABLED=0 GOOS=linux go build -o mqtt cmd/mqtt/main.go -CMD pwd + FROM alpine:3.14@sha256:0f2d5c38dd7a4f4f733e688e3a6733cb5ab1ac6e3cb4603a5dd564e5bfb80eed COPY --from=builder /app/mqtt / ENTRYPOINT ["/mqtt"] diff --git a/deploy/kubernetes/README.md b/deploy/kubernetes/README.md index bdc26ac..9ef30ea 100644 --- a/deploy/kubernetes/README.md +++ b/deploy/kubernetes/README.md @@ -2,15 +2,90 @@ ## Requirements +Kubernetes 1.28+ + ### Standalone Installation -Node: +Single Node: * 8 vCPUs * 8 GB RAM # Installation +## Download Files + +```shell +git clone https://github.com/OktopUSP/oktopus +export DEPLOYMENT_PATH=oktopus/deploy/kubernetes +``` + ## MongoBD +```shell +# Mongo DB Operator at mongodb namespace +helm repo add mongodb https://mongodb.github.io/helm-charts + +helm install community-operator mongodb/community-operator --namespace mongodb --create-namespace + +# Mongo DB ReplicaSet +export DEPLOYMENT_PATH=oktopus/deploy/kubernetes + +kubectl apply -f $DEPLOYMENT_PATH/mongodb.yaml -n mongodb + +# Check Installation +kubectl get pods -n mongodb +``` + +## NATS Server + +```shell +# Download the NATS charts +helm repo add nats https://nats-io.github.io/k8s/helm/charts/ + +# Install NATS with Jetstream Enabled +helm install nats nats/nats --set config.jetstream.enabled=true +``` +## Oktopus + + +Node Ports + +For this deployment, we are not using a load balancer and kubernetes is deployed on-premises so we are using Nodeports to insource the client traffic into cluster. below the ports set on deployment files: + +1. MQTT broker service (mqtt-svc): 30000 +2. Frontend (frontend-svc): 30001 +3. SocketIO: (socketio-svc): 30002 +4. Controller (controller-svc): 30003 +5. WebSocket (ws-svc): 30005 + +Before deploying the files, edit the frontend.yaml file to set the correct enviroment variables: + +```yaml +env: + - name: NEXT_PUBLIC_REST_ENDPOINT + value: ":30003" + - name: NEXT_PUBLIC_WS_ENDPOINT + value: ":30005" +``` + +```shell +kubectl apply -f $DEPLOYMENT_PATH/mqtt.yaml +kubectl apply -f $DEPLOYMENT_PATH/mqtt-adapter.yaml +kubectl apply -f $DEPLOYMENT_PATH/adapter.yaml +kubectl apply -f $DEPLOYMENT_PATH/controller.yaml +kubectl apply -f $DEPLOYMENT_PATH/socketio.yaml +kubectl apply -f $DEPLOYMENT_PATH/frontend.yaml +kubectl apply -f $DEPLOYMENT_PATH/ws.yaml +kubectl apply -f $DEPLOYMENT_PATH/ws-adapter.yaml +``` + +### Checking cluster status: + +```shell + +kubectl get pods +kubectl get svc + +``` \ No newline at end of file diff --git a/deploy/kubernetes/backend.yaml b/deploy/kubernetes/backend.yaml deleted file mode 100644 index 10a45db..0000000 --- a/deploy/kubernetes/backend.yaml +++ /dev/null @@ -1,21 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: backend - labels: - app: backend -spec: - replicas: 1 - selector: - matchLabels: - app: backend - template: - metadata: - labels: - app: backend - spec: - containers: - - name: backend - image: backend:latest - ports: - - containerPort: 8080 \ No newline at end of file diff --git a/deploy/kubernetes/frontend.yaml b/deploy/kubernetes/frontend.yaml index 4e61bba..6731899 100644 --- a/deploy/kubernetes/frontend.yaml +++ b/deploy/kubernetes/frontend.yaml @@ -8,7 +8,7 @@ spec: matchLabels: app: frontend strategy: - type: Recreate # Specify the Recreate strategy + type: Recreate # Specify the Recreate strategy template: metadata: labels: @@ -16,16 +16,22 @@ spec: spec: containers: - name: frontend - image: rogersacchelli/frontend:1.0.3 - ports: + image: oktopusp/frontend:latest + resources: + requests: + memory: 64Mi + cpu: 100m + limits: + memory: 256Mi + cpu: 200m + ports: - containerPort: 3000 - imagePullPolicy: Always + imagePullPolicy: IfNotPresent env: - name: NEXT_PUBLIC_REST_ENDPOINT value: "192.168.1.130:30003" - name: NEXT_PUBLIC_WS_ENDPOINT - value: "192.168.1.130:30002" - + value: "192.168.1.130:30005" --- apiVersion: v1 kind: Service diff --git a/deploy/kubernetes/mqtt.yaml b/deploy/kubernetes/mqtt.yaml index 8d78cb6..0d705ee 100644 --- a/deploy/kubernetes/mqtt.yaml +++ b/deploy/kubernetes/mqtt.yaml @@ -9,7 +9,8 @@ spec: - protocol: TCP port: 1883 targetPort: 1883 - type: ClusterIP + nodePort: 30000 + type: NodePort --- apiVersion: apps/v1 kind: Deployment @@ -33,10 +34,10 @@ spec: resources: requests: memory: 64Mi - cpu: 0.1 + cpu: 100m limits: memory: 256Mi - cpu: 0.2 + cpu: 200m imagePullPolicy: IfNotPresent env: - name: MQTT_PORT diff --git a/deploy/kubernetes/ws.yaml b/deploy/kubernetes/ws.yaml index df38bc3..f53f334 100644 --- a/deploy/kubernetes/ws.yaml +++ b/deploy/kubernetes/ws.yaml @@ -31,13 +31,13 @@ spec: image: oktopusp/ws:latest ports: - containerPort: 8080 - #resources: - #requests: - #memory: 64Mi - #cpu: 0.1 - #limits: - #memory: 256Mi - #cpu: 0.2 + resources: + requests: + memory: 64Mi + cpu: 100m + limits: + memory: 256Mi + cpu: 200m imagePullPolicy: IfNotPresent env: - name: SERVER_PORT diff --git a/frontend/build/Dockerfile b/frontend/build/Dockerfile index 8a9893e..f7512cb 100644 --- a/frontend/build/Dockerfile +++ b/frontend/build/Dockerfile @@ -6,7 +6,7 @@ COPY ./ ./ RUN npm install -RUN NEXT_PUBLIC_REST_ENPOINT=REST_API_URL NEXT_PUBLIC_WS_ENPOINT=WS_URL npm run build +RUN NEXT_PUBLIC_REST_ENDPOINT=REST_API_URL NEXT_PUBLIC_WS_ENDPOINT=WS_URL npm run build RUN ls -la && echo "Listing directory contents done" From f39cd325b7046fdc0ec11040bf8f91f16222afef Mon Sep 17 00:00:00 2001 From: Roger Sacchelli Date: Tue, 16 Apr 2024 23:06:08 -0300 Subject: [PATCH 20/20] minor changes on Dockerfiles frontend --- backend/services/mtp/mqtt/build/Dockerfile | 2 +- frontend/build/Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/services/mtp/mqtt/build/Dockerfile b/backend/services/mtp/mqtt/build/Dockerfile index 5ea1214..6a912db 100644 --- a/backend/services/mtp/mqtt/build/Dockerfile +++ b/backend/services/mtp/mqtt/build/Dockerfile @@ -1,6 +1,6 @@ FROM golang:1.22@sha256:82e07063a1ac3ee59e6f38b1222e32ce88469e4431ff6496cc40fb9a0fc18229 as builder WORKDIR /app -COPY ../ ./ +COPY ../ . RUN CGO_ENABLED=0 GOOS=linux go build -o mqtt cmd/mqtt/main.go FROM alpine:3.14@sha256:0f2d5c38dd7a4f4f733e688e3a6733cb5ab1ac6e3cb4603a5dd564e5bfb80eed diff --git a/frontend/build/Dockerfile b/frontend/build/Dockerfile index f7512cb..a5d60f8 100644 --- a/frontend/build/Dockerfile +++ b/frontend/build/Dockerfile @@ -2,7 +2,7 @@ FROM node:16.20.2-alpine as builder WORKDIR /app -COPY ./ ./ +COPY ../ ./ RUN npm install