Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Commit

Permalink
Use custom buildpack to build Stratos UI (#1283)
Browse files Browse the repository at this point in the history
* Use custom buildpack to build Stratos UI

* Fix host name

* WIP: Add DB Migration

* Additions needed for db migration

* Tweaks fo goose

* Testing DB migration

* Final tweaks to get database migration working

* Tidy ups

* Removed debugging log

* Remove logging of DB params

* Refinements to reduce the droplet size

* Reduce memory needed and swicth to the SUSE hosted buildpack

* Fix db migration
  • Loading branch information
nwmac authored and Irfan Habib committed Oct 11, 2017
1 parent e255a2d commit 00a25cf
Show file tree
Hide file tree
Showing 12 changed files with 449 additions and 156 deletions.
9 changes: 9 additions & 0 deletions .cfignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,12 @@ dev-certs/
out/
outputs/
tmp/
CHANGELOG.md
test/
deploy/all-in-one/
deploy/ci/
deploy/containers/
deploy/docker-compose/
deploy/stratos-ui-release/
deploy/kubernetes/
docs/
1 change: 0 additions & 1 deletion Procfile

This file was deleted.

75 changes: 75 additions & 0 deletions deploy/cloud-foundry/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

set -e

BUILD_DIR=$1
CACHE_DIR=$2

echo "Preparing application folder for Cloud Foundry deployment"

CF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
TOP_LEVEL=${CF_DIR}/../../
BOWER_PATH=${NODE_HOME}/bin

export STRATOS_TEMP=$(mktemp -d)

# Copy the config file
cp ${CF_DIR}/config.properties ${TOP_LEVEL}

mv ${TOP_LEVEL}/plugins.json ${TOP_LEVEL}/plugins.json.bk
sed '2 a"cloud-foundry-hosting",' ${TOP_LEVEL}/plugins.json.bk > ${TOP_LEVEL}/plugins.json

# Hack for deleting testImports in glide files
# because unfortunately `glide install --skip-test` doesn't seem to work
find . -name glide.lock -exec sed -i '/^testImports.*/q' {} \;
find . -name glide.lock -exec sed -i 's/^testImports:$/testImports: []/g' {} \;

npm install -g gulp bower

cd ${TOP_LEVEL}

npm install --only=prod
${BOWER_PATH}/bower install

# Fetch Glide dependencies
npm run cf-get-backend-deps

npm run build

# Build backend components
npm run cf-build-backend

npm run build-cf

chmod +x portal-proxy

# Get the goose db migration tool
export DB_MIGRATE_DIR="$CF_DIR/db-migration"
export DB_DIR="$CF_DIR/../db/migrations"
export GOPATH=${CACHE_DIR}/migration
mkdir -p $GOPATH

go get bitbucket.org/liamstask/goose/lib/goose
go get github.com/lib/pq
go get github.com/mattn/go-sqlite3

# Build the migration tool
pushd ${DB_DIR}
go build -o migrateStratosDb
echo "Built DB migrator"
popd


# Build the migration helper
pushd ${DB_MIGRATE_DIR}
go build -o parseVcapServices
popd

# Clean up build folders
rm -rf ./dist
rm -rf ./outputs

# Don't need the source code after build
rm -rf ./components

echo "All done"
23 changes: 2 additions & 21 deletions deploy/cloud-foundry/db-migration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,9 @@ As described in the standard `cf push` instructions [here](../README.md) the con

* This enables the endpoints dashboard UI and specifies that the Console should bind to the service instance named `console_db`

1. Set up the database schema for the Console. Run the following from the root of the console:
1. Push the app via cf push
```
cf push -c "deploy/cloud-foundry/db-migration/db-migrate.sh" -u "process"
```
> **NOTE** All subsequent pushes, restarts, restaging will use this migration command.
It's therefore very important to execute the next step in order for the console to start

Wait for the database setup to complete, by viewing the application log and waiting for the message indicating setup is complete:

* To stream the logs
```
cf logs console
```

* Database setup complete log message
```
Database successfully migrated. Please restart the application via 'cf push -c "null"'
```

1. Restart the app via cf push
```
cf push -c "null"
cf push
```


46 changes: 0 additions & 46 deletions deploy/cloud-foundry/db-migration/db-migrate.sh

This file was deleted.

100 changes: 100 additions & 0 deletions deploy/cloud-foundry/db-migration/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package main

import (
"encoding/json"
"fmt"
"os"
)

const (
VCAP_SERVICES = "VCAP_SERVICES"
NAME = "name"
TAGS = "tags"
STRATOS_POSTGRES_TAG = "stratos_postgresql"
STRATOS_MYSQL_TAG = "stratos_mysql"
CREDENTIALS = "credentials"
HOSTNAME = "hostname"
PORT = "port"
USERNAME = "username"
PASSWORD = "password"
DBNAME = "dbname"
DATABASE_PROVIDER = "DATABASE_PROVIDER"
DB_TYPE = "DB_TYPE"
DB_HOST = "DB_HOST"
DB_PORT = "DB_PORT"
DB_USER = "DB_USER"
DB_PASSWORD = "DB_PASSWORD"
DB_NAME = "DB_DATABASE_NAME"
PROVIDER_POSTGRES = "pgsql"
TYPE_POSTGRES = "postgresql"
PROVIDER_MYSQL = "mysql"
TYPE_MYSQL = "mysql"
)

type VCAPService struct {
Credentials map[string]interface{} `json:"credentials"`
Tags []string `json:"tags"`
}

func main() {

fmt.Println("# VCAP_SERVICES Parsing")

// Try and get the services environment variable
services, ok := os.LookupEnv(VCAP_SERVICES)

if ok {
var vcapServices map[string][]VCAPService

// Try and parse it as JSON
err := json.Unmarshal([]byte(services), &vcapServices)
if err == nil {
findDatabaseConfig(vcapServices)
} else {
fmt.Println("#", err)
}
}

fmt.Println("")
}

func findDatabaseConfig(vcapServices map[string][]VCAPService) {
for _, services := range vcapServices {
for _, service := range services {
if stringInSlice(STRATOS_POSTGRES_TAG, service.Tags) {
fmt.Println("# Postgres db config")

exportString(DATABASE_PROVIDER, PROVIDER_POSTGRES)
exportString(DB_TYPE, TYPE_POSTGRES)
exportString(DB_HOST, service.Credentials[HOSTNAME])
exportString(DB_PORT, service.Credentials[PORT])
exportString(DB_USER, service.Credentials[USERNAME])
exportString(DB_PASSWORD, service.Credentials[PASSWORD])
exportString(DB_NAME, service.Credentials[DBNAME])
} else if stringInSlice(STRATOS_MYSQL_TAG, service.Tags) {
fmt.Println("# MySQL db config")

exportString(DATABASE_PROVIDER, PROVIDER_MYSQL)
exportString(DB_TYPE, TYPE_MYSQL)
exportString(DB_HOST, service.Credentials[HOSTNAME])
exportString(DB_PORT, service.Credentials[PORT])
exportString(DB_USER, service.Credentials[USERNAME])
exportString(DB_PASSWORD, service.Credentials[PASSWORD])
exportString(DB_NAME, service.Credentials[NAME])
}
}
}
}

func stringInSlice(a string, list []string) bool {
for _, b := range list {
if b == a {
return true
}
}
return false
}

func exportString(name string, value interface{}) {
fmt.Printf("\nexport %s=\"%s\"", name, value)
}
81 changes: 0 additions & 81 deletions deploy/cloud-foundry/db-migration/parse_db_environment.js

This file was deleted.

Loading

0 comments on commit 00a25cf

Please sign in to comment.