import (
"broker/pkg/handlers/model"
- "os"
-
+ "fmt"
"github.com/jinzhu/gorm"
+ _ "github.com/jinzhu/gorm/dialects/postgres"
"github.com/sirupsen/logrus"
+ "os"
)
-// DB name
-const DbName = "applcmDB"
+var (
+ username = os.Getenv("POSTGRES_USER")
+ password = os.Getenv("POSTGRES_PASSWORD")
+ dbName = os.Getenv("POSTGRES_DATABASE")
+ dbHost = os.Getenv("DBHOST")
+
+)
// Database adapter
type DbAdapter struct {
func (adapter *DbAdapter) CreateDatabase() {
adapter.logger.Infof("creating Database...")
- usrpswd := os.Getenv("MYSQL_USER") + ":" + os.Getenv("MYSQL_PASSWORD")
- host := "@tcp(" + "dbhost" + ":3306)/"
+ dbUri := fmt.Sprintf("host=%s user=%s dbname=%s sslmode=disable password=%s", dbHost, username, dbName, password) //Build connection string
- db, err := gorm.Open("mysql", usrpswd+host)
+ conn, err := gorm.Open("postgres", dbUri)
if err != nil {
- adapter.logger.Fatalf("Database connect error", err.Error())
+ fmt.Print(err)
}
- db.Exec("CREATE DATABASE " + DbName)
- db.Exec("USE applcmDB")
- gorm.DefaultCallback.Create().Remove("mysql:set_identity_insert")
-
- adapter.logger.Infof("Migrating models...")
+ db := conn
db.AutoMigrate(&model.AppPackageInfo{})
db.AutoMigrate(&model.AppInstanceInfo{})
adapter.db = db
value: /go/release/logfile
- name: LOGGER_LEVEL
value: info
- - name: MYSQL_DATABASE
- value: db
- - name: MYSQL_PASSWORD
+ - name: POSTGRES_DATABASE
+ value: mecmdb
+ - name: DBHOST
+ value: mecmdb
+ - name: POSTGRES_PASSWORD
value: password
- - name: MYSQL_ROOT_PASSWORD
+ - name: POSTGRES_ROOT_PASSWORD
value: password
- - name: MYSQL_USER
+ - name: POSTGRES_USER
value: root
- name: PACKAGE_ARTIFACT_PATH
value: /Artifacts/Deployment/
+++ /dev/null
-# Copyright 2020 Huawei Technologies Co., Ltd.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# yamllint disable
-apiVersion: apps/v1
-kind: Deployment
-metadata:
- annotations:
- kompose.cmd: kompose convert
- kompose.version: 1.21.0 (992df58d8)
- creationTimestamp: null
- labels:
- io.kompose.service: db
- name: db
-spec:
- replicas: 1
- selector:
- matchLabels:
- io.kompose.service: db
- strategy:
- type: Recreate
- template:
- metadata:
- annotations:
- kompose.cmd: kompose convert
- kompose.version: 1.21.0 (992df58d8)
- creationTimestamp: null
- labels:
- io.kompose.service: db
- spec:
- containers:
- - env:
- - name: MYSQL_DATABASE
- value: db
- - name: MYSQL_PASSWORD
- value: password
- - name: MYSQL_ROOT_PASSWORD
- value: password
- - name: MYSQL_USER
- value: root
- image: mysql/mysql-server
- imagePullPolicy: ""
- name: db
- ports:
- - containerPort: 3306
- resources: {}
- volumeMounts:
- - mountPath: /var/lib/mysql
- name: my-db
- restartPolicy: Always
- serviceAccountName: ""
- volumes:
- - name: my-db
- hostPath:
- path: /data
- type: DirectoryOrCreate
-status: {}
-
-# yamllint enable
+++ /dev/null
-# Copyright 2020 Huawei Technologies Co., Ltd.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# yamllint disable
-apiVersion: v1
-kind: Service
-metadata:
- annotations:
- kompose.cmd: kompose convert
- kompose.version: 1.21.0 (992df58d8)
- creationTimestamp: null
- labels:
- io.kompose.service: db
- name: dbhost
-spec:
- ports:
- - name: "3306"
- port: 3306
- targetPort: 3306
- selector:
- io.kompose.service: db
-status:
- loadBalancer: {}
-
-# yamllint enable
# See the License for the specific language governing permissions and
# limitations under the License.
-# yamllint disable
+
+# persistent volume
+---
+kind: PersistentVolume
apiVersion: v1
+metadata:
+ name: postgres-pv-volume
+ labels:
+ type: local
+ app: postgres
+spec:
+ storageClassName: manual
+ capacity:
+ storage: 5Gi
+ accessModes:
+ - ReadWriteMany
+ hostPath:
+ path: "/data"
+
+# pvc
+---
kind: PersistentVolumeClaim
+apiVersion: v1
metadata:
- creationTimestamp: null
+ name: postgres-pv-claim
+ namespace: default
labels:
- io.kompose.service: my-db
- name: my-db
+ app: postgres
spec:
+ storageClassName: manual
accessModes:
- - ReadWriteOnce
+ - ReadWriteMany
resources:
requests:
- storage: 100Mi
-status: {}
-
-# yamllint enable
+ storage: 5Gi
--- /dev/null
+# Copyright 2020 Huawei Technologies Co., Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+# postgres database
+---
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: postgres-db
+ namespace: default
+ labels:
+ app: postgres-db
+spec:
+ replicas: 1
+ selector:
+ matchLabels:
+ app: postgres-db
+ template:
+ metadata:
+ labels:
+ app: postgres-db
+ spec:
+ volumes:
+ - name: postgres-data
+ persistentVolumeClaim:
+ claimName: postgres-pv-claim
+ containers:
+ - name: postgres-db
+ image: postgres:9.6
+ imagePullPolicy: "IfNotPresent"
+ env:
+ - name: POSTGRES_DB
+ value: mecmdb
+ - name: POSTGRES_USER
+ value: root
+ - name: POSTGRES_PASSWORD
+ value: password
+ volumeMounts:
+ - mountPath: /var/lib/postgresql/data
+ name: postgres-data
+ ports:
+ - containerPort: 5432
+
+# postgres service
+---
+apiVersion: v1
+kind: Service
+metadata:
+ name: mecmdb
+ namespace: default
+spec:
+ selector:
+ app: postgres-db
+ ports:
+ - name: "5432"
+ port: 5432
+ targetPort: 5432
my-db:
services:
- db:
+ mecmdb:
network_mode: bridge
- image: mysql:5.7
+ image: postgres:9.6
environment:
- MYSQL_DATABASE: 'db'
- MYSQL_USER: 'root'
- MYSQL_PASSWORD: 'password'
- # Password for root access
- MYSQL_ROOT_PASSWORD: 'password'
+ POSTGRES_DB: 'mecmdb'
+ POSTGRES_USER: 'root'
+ POSTGRES_PASSWORD: 'password'
+ POSTGRES_ROOT_PASSWORD: 'password'
ports:
- - '3306:3306'
+ - '5432:5432'
expose:
- - '3306'
+ - '5432'
volumes:
- - my-db:/var/lib/mysql
+ - my-db:/var/lib/postgresql/data
logging:
driver: "json-file"
options:
network_mode: bridge
image: ealtedge/applcm-broker:latest
depends_on:
- - db
+ - mecmdb
- helm-plugin
links:
- - db:dbhost
+ - mecmdb:mecmdb
- helm-plugin:helmplugin
restart: always
container_name: applcm-broker
environment:
- MYSQL_DATABASE: 'db'
- MYSQL_USER: 'root'
- MYSQL_PASSWORD: 'password'
- MYSQL_ROOT_PASSWORD: 'password'
+ POSTGRES_DATABASE: 'mecmdb'
+ DBHOST: 'mecmdb'
+ POSTGRES_USER: 'root'
+ POSTGRES_PASSWORD: 'password'
+ POSTGRES_ROOT_PASSWORD: 'password'
HELM_PLUGIN_PORT: '50051'
KUBERNETES_PLUGIN_PORT: '50052'
LOGFILE_PATH: "/go/release/logfile"