Skip to content

Commit

Permalink
Merge pull request #136 from Backendless/stage
Browse files Browse the repository at this point in the history
Stage -> master
  • Loading branch information
ksv510 authored Mar 5, 2024
2 parents 32c706c + d99582e commit a9d952f
Show file tree
Hide file tree
Showing 30 changed files with 493 additions and 171 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"no-unused-vars": "warn",
"max-len": [
"warn",
120
170
],
// require or disallow use of semicolons instead of ASI
"semi": [
Expand Down
9 changes: 8 additions & 1 deletion install-ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

set -e

proManagerBranch=${1:-"main"}

echo "Passed branch is '$proManagerBranch'"

echo "creating user bl-pro-manger"
sudo adduser --gecos 'user for backendless pro-manager' --disabled-password --quiet bl-pro-manager
sudo passwd -d bl-pro-manager
sudo adduser bl-pro-manager sudo
sudo adduser bl-pro-manager adm
sudo adduser bl-pro-manager systemd-journal
export proManagerBranch=$proManagerBranch
su bl-pro-manager

work_dir="/home/bl-pro-manager"
Expand Down Expand Up @@ -43,7 +48,9 @@ sudo k3s kubectl config view --raw > ~/.kube/config

echo "saved k3s config to work dir"

git clone https://github.com/Backendless/pro-manager.git
echo "cloning $proManagerBranch"

git clone -b "$proManagerBranch" https://github.com/Backendless/pro-manager.git

cd pro-manager

Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The following way of installation should work for any Debian-based OS.

Open terminal and execute the following command
```
curl -o- https://raw.githubusercontent.com/Backendless/pro-manager/main/install-ubuntu.sh | bash
curl -o- https://raw.githubusercontent.com/Backendless/pro-manager/main/install-ubuntu.sh | bash -s -- main
```

At the end, Pro Manager will be available in a browser by the following link `http://<your-ip>:5050`.
Expand Down
1 change: 1 addition & 0 deletions src/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mainRouter.use('/services/manage/loadbalancer/nginx', auth(), require('./manage/
mainRouter.use('/services/manage/loadbalancer/ingress', auth(), require('./manage/loadbalancer/ingress').router)
mainRouter.use('/services/manage/cert', auth(), require('./manage/cert').router)
mainRouter.use('/services/manage/cert-manager', auth(), require('./manage/cert-manager').router)
mainRouter.use('/services/manage/consul', auth(), require('./manage/consul').router)

mainRouter.use('/services/manage', auth(), require('./manager').router)

Expand Down
11 changes: 11 additions & 0 deletions src/controllers/k8s.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { createConfigMap, replaceConfigMap } from '../services/k8s/k8s-config-ma
import { statefulsetRead } from '../services/k8s/k8s-statefulset-read'
import { BaseConfig } from '../config/base-config'
import { listPods } from '../services/k8s/k8s-list-pods'
import { getPodEvents, getDeploymentEvents } from '../services/k8s/k8s-events-manager'

export const router = new Router()

Expand Down Expand Up @@ -42,4 +43,14 @@ router.get('/map/replace', handler(() => {

router.get('/map/create', handler(() => {
return createConfigMap('bl-test',{ some:'and it is value' })
}))

router.get('/pod/events/:podName', handler(({ params }) => {
const { podName } = params
return getPodEvents(podName)
}))

router.get('/deployment/events/:serviceName', handler(({ params }) => {
const { serviceName } = params
return getDeploymentEvents(serviceName)
}))
20 changes: 20 additions & 0 deletions src/controllers/manage/consul.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { handler, Router } from '../../utils/router'
import { certManager } from '../../services/manage/cert-manager/cert-manager'
import { changeConsulPortAvailability } from '../../services/manage/consul/change-consul-port-availability'

export const router = new Router()


router.get('/', handler(() => {
return certManager.getIssuers()
}))

router.put('/external-port/:action', handler(({ params }) => {
const enableNodePort = params.action === 'enable'
return changeConsulPortAvailability(enableNodePort)
}))

router.delete('/:type', handler(async ({ params }) => {
const isProd = params.type === 'prod'
return certManager.deleteIssuer(isProd)
}))
12 changes: 6 additions & 6 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ export function start() {
process.exit(1)
}

logger.info('')
logger.info('*************************************************************************************')
logger.info('*** Backendless Pro Manage is running, talking to API server on %s', Config.apiUrl)
logger.info(`*** Open http://localhost:${Config.port} in a browser to view the app.`)
logger.info('*************************************************************************************')
logger.info('')
console.log('')
console.log('*****************************************************************')
console.log('*** Backendless Pro Manage is running.')
console.log(`*** Open http://localhost:${Config.port} in a browser to experience the app.`)
console.log('*****************************************************************')
console.log('')
}))

const startGracefulShutdown = signal => {
Expand Down
5 changes: 2 additions & 3 deletions src/services/install/db/install-consul.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { k8sAppsV1Api, k8sCoreV1Api } from '../../k8s/k8s'
import { installStatus } from '../install-status'
import { readFileContent } from '../../../utils/fs'
import { k8sConfig } from '../../../config/k8s-config'
import path from 'path'
import { ConsulConfig } from '../../k8s/config/consul-config'

export async function installConsul({ mountPath }) {
const consulK8sConfig = JSON.parse(await readFileContent(path.resolve( __dirname, '../../k8s/config/consul.json')))
const consulK8sConfig = new ConsulConfig()
installStatus.info('installing consul...')
const workload = consulK8sConfig.workload
workload.spec.template.spec.volumes.push({
Expand Down
5 changes: 3 additions & 2 deletions src/services/install/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,12 @@ class InstallService {

installStatus.info('bl-init-config-values job created')

await waitForInitConsulJobComplete()

if (install.license) {
await consul.put('license', install.license)
await consul.put('config/license/id', install.license)
}

await waitForInitConsulJobComplete()
await setupPublicDomain(installStatus)

const containers = Object.entries(blContainers.bl)
Expand Down
30 changes: 8 additions & 22 deletions src/services/install/setup-public-domain.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,29 @@
import { checkIfEndpointAvailableForGet } from '../manage/check-if-endpoint-available'
import { getPublicIp } from '../manage/get-public-ip'
import { Logger } from '../../logger'
import Config from '../../../config/config.json'
import { domainConfigurationService } from '../manage/configuration/domain'
import { getDefaultDomainAndPorts } from '../manage/get-default-domain-and-ports'

const localLogger = Logger('setup-public-domain')

export const setupPublicDomain = async statusLogger => {

export const setupPublicDomain = async (statusLogger) => {
const logger = statusLogger || localLogger

logger.info('start setup public domains')

const publicIp = await getPublicIp()

logger.info(`public ip is ${publicIp}`)

const proManagerPort = Config.port
const proManagerEndpoint = `http://${publicIp}:${proManagerPort}`
const isProManagerAvailableWithPublicIp = await checkIfEndpointAvailableForGet(proManagerEndpoint)

logger.info(`pro manager is ${isProManagerAvailableWithPublicIp ? '' : 'NOT '}available by the endpoint [${proManagerEndpoint}]`)

const ip = isProManagerAvailableWithPublicIp ? publicIp : '127.0.0.1'
logger.info(`will be used ip [${ip}]`)
const { domain, ports } = await getDefaultDomainAndPorts()

const domains = await domainConfigurationService.getAll()
localLogger.info(`found domains ${JSON.stringify(domains)}`)

domains.rt.Port = 32700
domains.rt.Host = ip
domains.rt.Port = ports.rt
domains.rt.Host = domain

domains.api.Port = 32300
domains.api.Host = ip
domains.api.Port = ports.api
domains.api.Host = domain

const domainDescription = await domainConfigurationService.describeConfiguration()
const consoleUrlName = domainDescription.console[0].name
localLogger.info(`consoleUrlName is [${consoleUrlName}]`)
domains.console[consoleUrlName] = `http://${ip}:32400`
domains.console[consoleUrlName] = `http://${domain}:${ports.console}`

await domainConfigurationService.saveAll(domains)

Expand Down
97 changes: 97 additions & 0 deletions src/services/k8s/config/consul-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
export class ConsulConfig {
workload = {
'apiVersion': 'apps/v1',
'kind': 'StatefulSet',
'metadata': {
'annotations': {
'name': 'bl-consul'
},
'name': 'bl-consul'
},
'spec': {
'progressDeadlineSeconds': 60,
'replicas': 1,
'selector': {
'matchLabels': {
'app': 'bl-consul'
}
},
'strategy': {
'rollingUpdate': {
'maxSurge': 1,
'maxUnavailable': 0
},
'type': 'RollingUpdate'
},
'template': {
'metadata': {
'labels': {
'app': 'bl-consul'
}
},
'spec': {
'containers': [
{
'args': [
'agent',
'-server',
'-bootstrap-expect',
'1',
'-ui',
'-client',
'0.0.0.0',
'-data-dir=/consul/data',
'-disable-host-node-id=true'
],
'image': 'consul:1.1.0',
'imagePullPolicy': 'IfNotPresent',
'name': 'bl-consul',
'ports': [
{
'containerPort': 8500,
'name': 'bl-consul',
'protocol': 'TCP'
}
],
'volumeMounts': [
{
'mountPath': '/consul/data',
'name': 'consul-data'
}
]
}
],
'restartPolicy': 'Always',
'volumes': [

]
}
}
}
}

service = {
'apiVersion': 'v1',
'kind': 'Service',
'metadata': {
'name': 'bl-consul',
'labels': {
'app': 'bl-consul'
}
},
'spec': {
'type': 'NodePort',
'ports': [
{
'port': 8500,
'targetPort': 8500,
'name': 'bl-consul',
'nodePort': 32600
}
],
'selector': {
'app': 'bl-consul'
}
}
}
}
96 changes: 0 additions & 96 deletions src/services/k8s/config/consul.json

This file was deleted.

Loading

0 comments on commit a9d952f

Please sign in to comment.