This repository has been archived by the owner on Jan 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use custom buildpack to build Stratos UI (#1283)
* 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
Showing
12 changed files
with
449 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.