Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
bonzofenix committed Aug 23, 2024
1 parent ef8ebd0 commit 1e46118
Show file tree
Hide file tree
Showing 14 changed files with 316 additions and 200 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -453,5 +453,7 @@ go-get-u: $(addsuffix .go-get-u,$(go_modules))
go get -u ./...


mta-deploy:
@make --directory='./src/autoscaler' mta-deploy
deploy-apps:
echo " - deploying apps"
DEBUG="${DEBUG}" ${CI_DIR}/autoscaler/scripts/deploy-apps.sh

4 changes: 1 addition & 3 deletions ci/autoscaler/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ resources:
private_key: ((autoscaler-deploy-key-private))
branch: ((branch_name))
fetch_tags: true
paths:
- ci

- name: app-autoscaler-release
type: git
Expand Down Expand Up @@ -338,7 +336,7 @@ jobs:
- in_parallel:
- get: bbl-state
- get: app-autoscaler-release
passed: [unit-tests, integration-tests]
# passed: [unit-tests, integration-tests]
trigger: true
- get: ci
- task: make-prerelease
Expand Down
28 changes: 28 additions & 0 deletions ci/autoscaler/scripts/deploy-apps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,42 @@ script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source "${script_dir}/common.sh"
source "${script_dir}/vars.source.sh"

pushd "${bbl_state_path}" > /dev/null
eval "$(bbl print-env)"
popd > /dev/null

function fetch_certs() {
pushd "${autoscaler_dir}/src/autoscaler" > /dev/null
mkdir -p build/assets/certs/policy_db build/assets/certs/storedprocedure_db build/assets/certs/syslog_client

echo "Pulling policy db certs..."
credhub get -n /bosh-autoscaler/${deployment_name}/postgres_server --key ca --quiet > build/assets/certs/policy_db/ca.crt
credhub get -n /bosh-autoscaler/${deployment_name}/postgres_server --key certificate --quiet > build/assets/certs/policy_db/crt
credhub get -n /bosh-autoscaler/${deployment_name}/postgres_server --key private_key --quiet > build/assets/certs/policy_db/key

echo "Pulling storeprocedure db certs ..."
credhub get -n /bosh-autoscaler/${deployment_name}/postgres_server --key ca --quiet > build/assets/certs/storedprocedure_db/ca.crt
credhub get -n /bosh-autoscaler/${deployment_name}/postgres_server --key certificate --quiet > build/assets/certs/storedprocedure_db/crt
credhub get -n /bosh-autoscaler/${deployment_name}/postgres_server --key private_key --quiet > build/assets/certs/storedprocedure_db/key

echo "Pulling syslog-client certs..."
credhub get -n /bosh-autoscaler/cf/syslog_agent_log_cache_tls --key ca --quiet > build/assets/certs/syslog_client/ca.crt
credhub get -n /bosh-autoscaler/cf/syslog_agent_log_cache_tls --key certificate --quiet > build/assets/certs/syslog_client/client.crt
credhub get -n /bosh-autoscaler/cf/syslog_agent_log_cache_tls --key private_key --quiet > build/assets/certs/syslog_client/client.key
popd > /dev/null
}

function deploy() {
log "Deploying autoscaler apps for bosh deployment '${deployment_name}' "
pushd "${autoscaler_dir}/src/autoscaler" > /dev/null
make mta-deploy
popd > /dev/null
}



bosh_login
cf_login
cf_target "${autoscaler_org}" "${autoscaler_space}"
fetch_certs
deploy
1 change: 0 additions & 1 deletion ci/infrastructure/scripts/deploy-multiapps-controller.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ function deploy_multiapps_controller() {
mv multiapps-controller-web-war/*.war .
pushd multiapps-controller-web-manifest
cf push -f ./*.yml "${app_name}"

popd
}

Expand Down
8 changes: 3 additions & 5 deletions operations/use-cf-services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
host: ((metricsforwarder_host))
mtls_host: ((metricsforwarder_host))

# Set the same port for metricsforwarder and healthenpoint routes
- type: replace
path: /instance_groups/name=metricsforwarder/jobs/name=route_registrar/properties/route_registrar/routes/name=autoscaler_metricsforwarder_health/port
value: 6201

## add router tcp route for postgres
- type: replace
path: /instance_groups/name=postgres/jobs/-
Expand Down Expand Up @@ -53,3 +48,6 @@
- type: replace
path: /variables/name=postgres_client/options/alternative_names/-
value: ((deployment_name))-postgres.tcp.((system_domain))

- type: remove
path: /instance_groups/name=metricsforwarder
10 changes: 3 additions & 7 deletions src/autoscaler/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ PACKAGE_DIRS = $(shell go list './...' | grep --invert-match --regexp='/vendor/'
DB_HOST ?= localhost
DBURL ?= "postgres://postgres:postgres@${DB_HOST}/autoscaler?sslmode=disable"

METRICSFORWARDER_APPNAME ?= "metricsforwarder"
MAKEFILE_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
EXTENSION_FILE := $(shell mktemp)

export GOWORK=off
Expand Down Expand Up @@ -154,14 +154,11 @@ clean:
.PHONY: mta-deploy
mta-deploy: mta-build build-extension-file
$(MAKE) -f metricsforwarder/Makefile set-security-group
$(MAKE) -f metricsforwarder/Makefile stop-metricsforwarder-vm
@echo "Deploying with extension file: $(EXTENSION_FILE)"
@cf deploy mta_archives/*.mtar -f -e $(EXTENSION_FILE)
@cf deploy mta_archives/*.mtar -f --delete-services -e $(EXTENSION_FILE)

build-extension-file:
cp example.mtaext $(EXTENSION_FILE);
sed -i "s/APP_NAME/$(METRICSFORWARDER_APPNAME)/g" $(EXTENSION_FILE);
echo "EXTENSION_FILE: $(EXTENSION_FILE)"
$(MAKEFILE_DIR)/build-extension-file.sh > $(EXTENSION_FILE);

mta-logs:
rm -rf mta-*
Expand All @@ -170,7 +167,6 @@ mta-logs:

.PHONY: mta-build
mta-build: mta-build-clean cf-build
$(MAKE) -f metricsforwarder/Makefile fetch-config
mbt build

mta-build-clean:
Expand Down
59 changes: 59 additions & 0 deletions src/autoscaler/build-extension-file.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash

set -e

if [ -z "${DEPLOYMENT_NAME}" ]; then
echo "DEPLOYMENT_NAME is not set"
exit 1
fi

export SYSTEM_DOMAIN="autoscaler.app-runtime-interfaces.ci.cloudfoundry.org"
export POSTGRES_ADDRESS="${DEPLOYMENT_NAME}-postgres.tcp.${SYSTEM_DOMAIN}"
export POLICY_DB_PASSWORD="$(credhub get -n /bosh-autoscaler/${DEPLOYMENT_NAME}/database_password --quiet)"
export STOREPROCEDURE_DB_PASSWORD="$(credhub get -n /bosh-autoscaler/${DEPLOYMENT_NAME}/database_password --quiet)"
export METRICSFORWARDER_HEALTH_PASSWORD="$(credhub get -n /bosh-autoscaler/${DEPLOYMENT_NAME}/autoscaler_metricsforwarder_health_password --quiet)"
export METRICSFORWARDER_APPNAME="${METRICSFORWARDER_APPNAME:-"${DEPLOYMENT_NAME}-metricsforwarder"}"
export POSTGRES_EXTERNAL_PORT="${PR_NUMBER:-5432}"


if [ -z "${PR_NUMBER}" ]; then
echo "PR_NUMBER is not set"
exit 1
fi


if [ -z "${SYSTEM_DOMAIN}" ]; then
echo "SYSTEM_DOMAIN is not set"
exit 1
fi

if [ -z "${POSTGRES_ADDRESS}" ]; then
echo "POSTGRES_ADDRESS is not set"
exit 1
fi

echo '
ID: development
extends: com.github.cloudfoundry.app-autoscaler-release
version: 1.0.0
_schema-version: 3.3.0
modules:
- name: metricsforwarder
parameters:
routes:
- route: '${METRICSFORWARDER_APPNAME}'.${default-domain}
resources:
- name: config
parameters:
config:
metricsforwarder:
health:
password: "'"${METRICSFORWARDER_HEALTH_PASSWORD}"'"
db:
policy_db:
url: "postgres://postgres:'"${POLICY_DB_PASSWORD}@${POSTGRES_ADDRESS}:${POSTGRES_EXTERNAL_PORT}"'/autoscaler?application_name=metricsforwarder&sslmode=verify-full&sslrootcert=/home/vcap/app/assets/certs/policy_db/ca.crt&sslcert=/home/vcap/app/assets/certs/policy_db/crt&sslkey=/home/vcap/app/assets/certs/policy_db/key"
storedprocedure_db:
url: "postgres://postgres:STOREPROCEDURE_DB_PASSWORD@$POSTGRES_ADDRESS:POSTGRES_EXTERNAL_PORT/autoscaler?application_name=metricsforwarder&sslmode=verify-full&sslrootcert=/home/vcap/app/assets/certs/storedprocedure_db/ca.crt&sslcert=/home/vcap/app/assets/certs/storedprocedure_db/crt&sslkey=/home/vcap/app/assets/certs/storedprocedure_db/key"
'
10 changes: 0 additions & 10 deletions src/autoscaler/example.mtaext

This file was deleted.

25 changes: 0 additions & 25 deletions src/autoscaler/helpers/cf.go

This file was deleted.

52 changes: 0 additions & 52 deletions src/autoscaler/metricsforwarder/Makefile
Original file line number Diff line number Diff line change
@@ -1,46 +1,4 @@
PR_NUMBER ?= $(shell gh pr view --json number --jq '.number')
DEPLOYMENT_NAME ?= autoscaler-$(PR_NUMBER)
SYSTEM_DOMAIN ?=autoscaler.app-runtime-interfaces.ci.cloudfoundry.org
METIRCSFORWARDER_VM := $(shell bosh -d $(DEPLOYMENT_NAME) vms --json | jq '.Tables | .[] | .Rows | .[] | select(.instance|test("metricsforwarder")) | .instance')
POSTGRES_ADDRESS := $(DEPLOYMENT_NAME)-postgres.tcp.$(SYSTEM_DOMAIN)
LOG_CACHE_IP := $(shell bosh -d cf vms --json | jq -r '.Tables | .[] | .Rows | .[] | select(.instance|test("log-cache")) | .ips' )
MAKEFILE_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
POSTGRES_EXTERNAL_PORT := $(or $(PR_NUMBER),5432)


.PHONY: fetch-config
fetch-config: start-metricsforwarder-vm
# how to define variables in deployment name
mkdir -p build/assets/certs/policy_db build/assets/certs/storedprocedure_db build/assets/certs/syslog_client

echo "POSTGRES ADDRESS: $(POSTGRES_ADDRESS)"
echo "LOG_CACHE IP: $(LOG_CACHE_IP)"

@echo "Pulling metricforwarder config from $(METIRCSFORWARDER_VM)..."
bosh -d $(DEPLOYMENT_NAME) scp $(METIRCSFORWARDER_VM):/var/vcap/jobs/metricsforwarder/config/metricsforwarder.yml build/assets/metricsforwarder.yml

@echo "Pulling policy db certs from $(METIRCSFORWARDER_VM)..."
bosh -d $(DEPLOYMENT_NAME) scp $(METIRCSFORWARDER_VM):/var/vcap/jobs/metricsforwarder/config/certs/policy_db/ca.crt build/assets/certs/policy_db/.
bosh -d $(DEPLOYMENT_NAME) scp $(METIRCSFORWARDER_VM):/var/vcap/jobs/metricsforwarder/config/certs/policy_db/crt build/assets/certs/policy_db/.
bosh -d $(DEPLOYMENT_NAME) scp $(METIRCSFORWARDER_VM):/var/vcap/jobs/metricsforwarder/config/certs/policy_db/key build/assets/certs/policy_db/.

@echo "Pulling storeprocedure db certs from $(METIRCSFORWARDER_VM)..."
bosh -d $(DEPLOYMENT_NAME) scp $(METIRCSFORWARDER_VM):/var/vcap/jobs/metricsforwarder/config/certs/storedprocedure_db/ca.crt build/assets/certs/storedprocedure_db/.
bosh -d $(DEPLOYMENT_NAME) scp $(METIRCSFORWARDER_VM):/var/vcap/jobs/metricsforwarder/config/certs/storedprocedure_db/crt build/assets/certs/storedprocedure_db/.
bosh -d $(DEPLOYMENT_NAME) scp $(METIRCSFORWARDER_VM):/var/vcap/jobs/metricsforwarder/config/certs/storedprocedure_db/key build/assets/certs/storedprocedure_db/.

@echo "Pulling syslog-client certs from $(METIRCSFORWARDER_VM)..."
bosh -d $(DEPLOYMENT_NAME) scp $(METIRCSFORWARDER_VM):/var/vcap/jobs/metricsforwarder/config/certs/syslog_client/ca.crt build/assets/certs/syslog_client/.
bosh -d $(DEPLOYMENT_NAME) scp $(METIRCSFORWARDER_VM):/var/vcap/jobs/metricsforwarder/config/certs/syslog_client/client.crt build/assets/certs/syslog_client/.
bosh -d $(DEPLOYMENT_NAME) scp $(METIRCSFORWARDER_VM):/var/vcap/jobs/metricsforwarder/config/certs/syslog_client/client.key build/assets/certs/syslog_client/.

@echo "Build metricsforwarder config yaml"
cp build/assets/metricsforwarder.yml build/metricsforwarder.yml

sed -i'' -e 's|\/var\/vcap\/jobs\/metricsforwarder\/config|\/home\/vcap\/app/assets|g' build/metricsforwarder.yml
sed -i'' -e 's|$(DEPLOYMENT_NAME).autoscalerpostgres.service.cf.internal:5432|$(POSTGRES_ADDRESS):$(POSTGRES_EXTERNAL_PORT)|g' build/metricsforwarder.yml



PHONY: set-security-group
set-security-group:
Expand All @@ -49,13 +7,3 @@ set-security-group:

cf create-security-group metricsforwarder $(MAKEFILE_DIR)/security-group.json
cf bind-security-group metricsforwarder $(ORG)

PHONY: start-metricsforwarder-vm
start-metricsforwarder-vm:
bosh -d $(DEPLOYMENT_NAME) -n start $(METIRCSFORWARDER_VM)

PHONY: stop-metricsforwarder-vm
stop-metricsforwarder-vm:
bosh -d $(DEPLOYMENT_NAME) -n stop $(METIRCSFORWARDER_VM)


Loading

0 comments on commit 1e46118

Please sign in to comment.