Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(infrastructure): Bring multiapps-controller to CF #2988

Merged
merged 54 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
f35639c
Initial commit
bonzofenix Jun 5, 2024
36e2072
WIP: Adds postgres deployment
bonzofenix Jun 7, 2024
830492a
Fix lints
bonzofenix Jun 7, 2024
4e9189e
Fix lint
bonzofenix Jun 7, 2024
bd0acb2
Applies lint fixes
bonzofenix Jun 7, 2024
b46a635
Fix deploy script
bonzofenix Jun 7, 2024
6855636
Adds missing function
bonzofenix Jun 7, 2024
7f51548
Fix wrong path
bonzofenix Jun 7, 2024
4e76a32
Fix ops name for postgres
bonzofenix Jun 7, 2024
7a54702
Adds intercept helper
bonzofenix Jun 7, 2024
6e4d3b9
Sets static ip for postgres instance
bonzofenix Jun 7, 2024
ea0bdb2
Sets postgres disk size
bonzofenix Jun 7, 2024
813b07c
Adds trigger job helper
bonzofenix Jun 7, 2024
efde921
Sets debug on on postgres deploy
bonzofenix Jun 7, 2024
11dc50a
Change postgres ip
bonzofenix Jun 7, 2024
416e099
Remove debug mode from deploy postgres
bonzofenix Jun 7, 2024
5771253
WIP: Deploy multiapps controller
bonzofenix Jun 7, 2024
c2964f9
Adds execution permissions
bonzofenix Jun 7, 2024
618bdd2
Print multiapps controller manifest
bonzofenix Jun 7, 2024
3ee6cc0
Update branch
bonzofenix Jun 10, 2024
c031d27
Deploy postgres db
bonzofenix Jun 10, 2024
455f5ad
WIP: Deploy multiapps controller
bonzofenix Jun 10, 2024
93d1437
Update ci/infrastructure/scripts/deploy-multiapps-controller.sh
bonzofenix Jun 10, 2024
119bb67
Sets security group
bonzofenix Jun 10, 2024
a8fa2d7
Remove postgres ssl
bonzofenix Jun 11, 2024
48e0519
Disable ssl for postgres db connection
bonzofenix Jun 11, 2024
e924088
Skip ssl for multiapps ssl client
bonzofenix Jun 11, 2024
506934c
Adds cf api configuration
bonzofenix Jun 12, 2024
ee9a852
Build multiapps controller from fork repo
bonzofenix Jun 12, 2024
357aa99
Merge branch 'main' into feature/739-setup-mtar-controller
bonzofenix Jun 19, 2024
3de71cb
point to the right branch
bonzofenix Jun 19, 2024
8d14d2b
Fix to build from modify cf jar
bonzofenix Jun 26, 2024
6f70420
Add custom Cloud Foundry client reactor JAR to Maven install in depl…
bonzofenix Jul 29, 2024
0680b08
Remove custom Cloud Foundry client reactor JAR installation from dep…
bonzofenix Aug 1, 2024
4768046
Does not build mtar
bonzofenix Aug 8, 2024
aaeabc9
Adds trusted certs when deploying to cf
bonzofenix Aug 8, 2024
a8fec59
Refactor pipeline and resources for multiapps-controller deployment
bonzofenix Aug 8, 2024
5d6527b
Downloads war and manifest directly with http resource
bonzofenix Aug 8, 2024
5f3addf
Remove intercept and trigger-job targets from ci Makefile
bonzofenix Aug 8, 2024
3d1d7dd
Update description in Postgres security group to reflect dynamic IP h…
bonzofenix Aug 8, 2024
3f7fcde
Remove maven and gcs resources, update deploy-postgres task params in…
bonzofenix Aug 8, 2024
dcfc291
Remove multiapps-controller-repo resource from pipeline
bonzofenix Aug 8, 2024
a290242
Remove Slack integration from deploy-postgres and deploy-multiapps-co…
bonzofenix Aug 8, 2024
b09dacf
Fix lints
bonzofenix Aug 8, 2024
3145d06
Change branch
bonzofenix Aug 8, 2024
06211c4
Merge branch 'main' into feature/739-setup-mtar-controller
bonzofenix Aug 8, 2024
6bc4b40
change branch for testing
geigerj0 Aug 9, 2024
1203a65
restrict egress traffic exclusively to the internal PostgreSQL IP, in…
geigerj0 Aug 9, 2024
e76d828
fix phony name
geigerj0 Aug 9, 2024
3658215
remove useless makefile
geigerj0 Aug 9, 2024
0478156
😵 dont run script in debug mode 😵
geigerj0 Aug 9, 2024
043abf4
add info comment which explains why the trusted certs of the containe…
geigerj0 Aug 9, 2024
7475436
Revert "change branch for testing"
geigerj0 Aug 9, 2024
bb44594
delete some newlines
geigerj0 Aug 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ci/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
set-autoscaler-pipeline:
@./autoscaler/set-pipeline.sh

.PHONY: set-infrastructure-pipeline
set-infrastructure-pipeline:
@./infrastructure/set-pipeline.sh

.PHONY: unpause-pipeline
unpause-pipeline:
@./scripts/unpause-pipeline.sh


.PHONY: delete-pipeline
delete-pipeline:
@./scripts/delete-pipeline.sh
Expand Down
1 change: 1 addition & 0 deletions ci/autoscaler/scripts/deploy-autoscaler.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#! /usr/bin/env bash
# shellcheck disable=SC2086,SC2034,SC2155
set -euo pipefail

script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source "${script_dir}/vars.source.sh"

Expand Down
57 changes: 52 additions & 5 deletions ci/infrastructure/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,32 @@ groups:
- bosh-cleanup
- fetch-latest-stemcell
- deploy-prometheus
- deploy-multiapps-controller

- name: others
jobs:
- set-pipeline

resource_types:
- name: gcs-resource
type: registry-image
- name: file-url
type: docker-image
source:
repository: frodenas/gcs-resource
repository: pivotalservices/concourse-curl-resource
tag: latest

resources:
- name: multiapps-controller-web-war
type: file-url
source:
url: https://repo.maven.apache.org/maven2/org/cloudfoundry/multiapps/multiapps-controller-web/1.174.0/multiapps-controller-web-1.174.0.war
filename: multiapps-controller-web-1.174.0.war

- name: multiapps-controller-web-manifest
type: file-url
source:
url: https://repo.maven.apache.org/maven2/org/cloudfoundry/multiapps/multiapps-controller-web/1.174.0/multiapps-controller-web-1.174.0-manifest.yml
filename: multiapps-controller-web-1.174.0-manifest.yml

- name: ci
type: git
icon: github
Expand All @@ -44,6 +58,19 @@ resources:
uri: https://github.com/bosh-prometheus/prometheus-boshrelease.git
branch: master

- name: postgres-repo
type: git
icon: github
source:
uri: https://github.com/cloudfoundry/postgres-release.git
branch: v52

- name: postgres-release
type: bosh-io-release
source:
repository: cloudfoundry/postgres-release
version: v52

- name: bbl-state
type: git
icon: github
Expand Down Expand Up @@ -240,7 +267,7 @@ jobs:
vars-files: autoscaler-env-vars-store
params:
SYSTEM_DOMAIN: autoscaler.app-runtime-interfaces.ci.cloudfoundry.org
OPS_FILES: "operations/cf/scale-to-one-az.yml operations/cf/experimental/add-cflinuxfs4.yml operations/autoscaler/scale_out_cf_for_app-autoscaler.yaml operations/autoscaler/set-cpu-entitlement-per-share.yaml operations/cf/use-compiled-releases.yml operations/autoscaler/enable_mtls.yml operations/prometheus/operators/cf/add-prometheus-uaa-clients.yml operations/prometheus/operators/cf/add-grafana-uaa-clients.yml"
OPS_FILES: "operations/cf/scale-to-one-az.yml operations/cf/experimental/add-cflinuxfs4.yml operations/autoscaler/scale_out_cf_for_app-autoscaler.yaml operations/autoscaler/set-cpu-entitlement-per-share.yaml operations/autoscaler/add-trusted-certs.yaml operations/cf/use-compiled-releases.yml operations/autoscaler/enable_mtls.yml operations/prometheus/operators/cf/add-prometheus-uaa-clients.yml operations/prometheus/operators/cf/add-grafana-uaa-clients.yml"
BOSH_DEPLOY_ARGS: "-v diego_cell_instances=3 -v grafana_redirect_uri=https://grafana.autoscaler.app-runtime-interfaces.ci.cloudfoundry.org/login/generic_oauth"
ensure:
put: autoscaler-env-vars-store
Expand All @@ -254,4 +281,24 @@ jobs:
params:
ERRAND_NAME: smoke-tests


- name: deploy-multiapps-controller
serial_groups: [infra]
public: true
build_logs_to_retain: 100
plan:
- in_parallel:
- get: bbl-state
trigger: true
passed: [setup-infrastructure]
- get: ci
- get: postgres-repo
- get: postgres-release
- get: multiapps-controller-web-war
- get: multiapps-controller-web-manifest
- task: deploy-postgres
file: ci/ci/infrastructure/tasks/deploy-postgres.yml
params:
BBL_GCP_REGION: europe-west3
BBL_GCP_ZONE: europe-west3-a
- task: deploy-multiapps-controller
file: ci/ci/infrastructure/tasks/deploy-multiapps-controller.yml
61 changes: 61 additions & 0 deletions ci/infrastructure/scripts/deploy-multiapps-controller.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash
# shellcheck disable=SC2086
set -euo pipefail

script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source "${script_dir}/vars.source.sh"
source "${script_dir}/utils.source.sh"

function create_postgres_service() {
postgres_username="pgadmin"
postgres_database_name="multiapps_controller"
postgres_hostname="$(credhub get -n /bosh-autoscaler/postgres/postgres_host_or_ip -q)"
postgres_password="$(credhub get -n /bosh-autoscaler/postgres/pgadmin_database_password -q)"

# delete existing service
cf cups deploy-service-database -p "{ \"uri\": \"postgres://${postgres_username}:${postgres_password}@${postgres_hostname}:5524/${postgres_database_name}?ssl=false\", \"username\": \"${postgres_username}\", \"password\": \"${postgres_password}\" }" -t postgres
}


function deploy_multiapps_controller() {
app_name=deploy-service

mv multiapps-controller-web-war/*.war .
pushd multiapps-controller-web-manifest
cf push -f ./*.yml "${app_name}"

popd
}

function add_postrgres_security_group() {
postgres_ip="$(credhub get -n /bosh-autoscaler/postgres/postgres_host_or_ip --quiet)"

security_group_json_path="$(mktemp)"
cat <<EOF > "${security_group_json_path}"
[
{
"protocol": "tcp",
"destination": "${postgres_ip}/32",
"ports": "5524",
"description": "allow egress to the internal postgres IP"
}
]
EOF

cf create-security-group multiapps-postgres-security-group "${security_group_json_path}"
cf update-security-group multiapps-postgres-security-group "${security_group_json_path}"
cf unbind-security-group multiapps-postgres-security-group ${cf_org} ${cf_space}
cf bind-security-group multiapps-postgres-security-group ${cf_org} --space ${cf_space}
}

function cleanup_multiapps_controller() {
cf delete -f multiapps-controller
cf delete-service -f deploy-service-database
}

load_bbl_vars
cf_login "${system_domain}"
cleanup_multiapps_controller
create_postgres_service
add_postrgres_security_group
deploy_multiapps_controller
47 changes: 47 additions & 0 deletions ci/infrastructure/scripts/deploy-postgres.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash
# shellcheck disable=SC2086
set -euo pipefail

script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source "${script_dir}/vars.source.sh"
source "${script_dir}/utils.source.sh"

bosh_deploy_opts=${BOSH_DEPLOY_OPTS:-}
deployment_name="${DEPLOYMENT_NAME:-postgres}"

release_dir="${POSTGRES_DIR:-$(realpath -e ${root_dir}/../postgres-release)}"
repo_dir="${REPO_DIR:-$(realpath -e ${root_dir}/../postgres-repo)}"
deployment_manifest=${DEPLOYMENT_MANIFEST:-"${repo_dir}/templates/postgres.yml"}

release_ops="${repo_dir}/templates/operations"
ops_files=${OPS_FILES:-"${release_ops}/add_static_ips.yml\
${ci_dir}/operations/set-postgres-disk.yml\
${ci_dir}/operations/add-multiapps-databases-to-postgres.yml \
"}



function deploy () {
bonzofenix marked this conversation as resolved.
Show resolved Hide resolved
bonzofenix marked this conversation as resolved.
Show resolved Hide resolved
local ops_files_to_use=""
validate_ops_files "${ops_files}"

for OPS_FILE in ${ops_files}; do
ops_files_to_use="${ops_files_to_use} -o ${OPS_FILE}"
done

credhub set -n /bosh-autoscaler/postgres/postgres_host_or_ip -t value -v "10.0.255.2"

step "Deploying release with name '${deployment_name}' "
log "using Ops files: '${ops_files_to_use}'"
bosh -n -d "${deployment_name}" \
deploy "${deployment_manifest}" \
${ops_files_to_use} \
${bosh_deploy_opts}
}
bonzofenix marked this conversation as resolved.
Show resolved Hide resolved

load_bbl_vars
find_or_upload_stemcell_from "${deployment_manifest}"

upload_release "${release_dir}"
deploy

2 changes: 1 addition & 1 deletion ci/infrastructure/scripts/deploy-prometheus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ uaa_ssl_ca_file="${UAA_SSL_CA_FILE:-$(mktemp)}"
uaa_ssl_cert_file="${UAA_SSL_CERT_FILE:-$(mktemp)}"
uaa_ssl_key_file="${UAA_SSL_KEY_FILE:-$(mktemp)}"
slack_channel="${SLACK_CHANNEL:-cf-dev-autoscaler-alerts}"
slack_webhook="${SLACK_WEBHOOK}"
slack_webhook="${SLACK_WEBHOOK:-}"
prometheus_dir="${PROMETHEUS_DIR:-$(realpath -e ${root_dir}/../prometheus-boshrelease)}"
deployment_manifest=${DEPLOYMENT_MANIFEST:-"${prometheus_dir}/manifests/prometheus.yml"}
prometheus_ops="${prometheus_dir}/manifests/operators"
Expand Down
87 changes: 87 additions & 0 deletions ci/infrastructure/scripts/utils.source.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@

# shellcheck disable=SC2086
bosh_upload_stemcell_opts="${BOSH_UPLOAD_STEMCELL_OPTS:-""}"

function find_or_upload_stemcell_from(){
deployment_manifest=$1
# Determine if we need to upload a stemcell at this point.
stemcell_os=$(yq eval '.stemcells[] | select(.alias == "default").os' "${deployment_manifest}")
stemcell_version=$(yq eval '.stemcells[] | select(.alias == "default").version' "${deployment_manifest}")
stemcell_name="bosh-google-kvm-${stemcell_os}-go_agent"

if ! bosh stemcells | grep "${stemcell_name}" >/dev/null; then
URL="https://bosh.io/d/stemcells/${stemcell_name}"
if [ "${stemcell_version}" != "latest" ]; then
URL="${URL}?v=${stemcell_version}"
fi
wget "$URL" -O stemcell.tgz
bosh -n upload-stemcell $bosh_upload_stemcell_opts stemcell.tgz
bonzofenix marked this conversation as resolved.
Show resolved Hide resolved
bonzofenix marked this conversation as resolved.
Show resolved Hide resolved
bonzofenix marked this conversation as resolved.
Show resolved Hide resolved
bonzofenix marked this conversation as resolved.
Show resolved Hide resolved
fi
}

# upload release from a bosh.io resource
function upload_release(){
release_dir=$1

pushd "${release_dir}" > /dev/null || exit
echo "Uploading release from ${release_dir}"
echo "Listing files in ${release_dir}:"
log "$(ls -1 ./*.tgz)"
bosh -n upload-release release.tgz
popd > /dev/null || exit
}

function load_bbl_vars() {
if [ -z "${bbl_state_path}" ]; then
echo "ERROR: bbl_state_path is not set"
exit 1
fi

director_store="${bbl_state_path}/vars/director-vars-store.yml"
log "director_store = '${director_store}'"
if [[ ! -d ${bbl_state_path} ]]; then
echo "FAILED: Did not find bbl-state folder at ${bbl_state_path}"
echo "Make sure you have checked out the app-autoscaler-env-bbl-state repository next to the app-autoscaler-release repository to run this target or indicate its location via BBL_STATE_PATH";
exit 1;
fi

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

function validate_ops_files() {
local ops_files=$1

for ops_file in ${ops_files}; do
bonzofenix marked this conversation as resolved.
Show resolved Hide resolved
bonzofenix marked this conversation as resolved.
Show resolved Hide resolved
bonzofenix marked this conversation as resolved.
Show resolved Hide resolved
bonzofenix marked this conversation as resolved.
Show resolved Hide resolved
if [ ! -f "${ops_file}" ]; then
echo "ERROR: could not find ops file ${ops_file} in ${PWD}"
exit 1
fi
done
}

function add_var_to_bosh_deploy_opts() {
local var_name=$1
local var_value=$2
bosh_deploy_opts="${bosh_deploy_opts} -v ${var_name}=${var_value}"
}

function cf_login(){
local system_domain=$1

cf api "https://api.${system_domain}" --skip-ssl-validation
bonzofenix marked this conversation as resolved.
Show resolved Hide resolved
CF_ADMIN_PASSWORD=$(credhub get -n /bosh-autoscaler/cf/cf_admin_password -q)
cf auth admin "$CF_ADMIN_PASSWORD"

if [ -n "${CF_ORG}" ]; then
cf create-org "${CF_ORG}"
cf target -o "${CF_ORG}"
fi

if [ -n "${CF_SPACE}" ]; then
cf create-space "${CF_SPACE}"
cf target -s "${CF_SPACE}"
fi
}

8 changes: 8 additions & 0 deletions ci/infrastructure/scripts/vars.source.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ export BBL_GCP_ZONE="europe-west3-a"
export bbl_gcp_zone="${BBL_GCP_ZONE}"
debug "BBL_GCP_ZONE: ${BBL_GCP_ZONE}"

export CF_ORG="system"
export cf_org="${CF_ORG}"
debug "CF_ORG: ${CF_ORG}"

export CF_SPACE="production"
export cf_space="${CF_SPACE}"
debug "CF_SPACE: ${CF_SPACE}"

function unset_vars() {
unset BOSH_USERNAME
unset CI_DIR
Expand Down
17 changes: 17 additions & 0 deletions ci/infrastructure/tasks/deploy-multiapps-controller.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
platform: linux

image_resource:
type: registry-image
source:
repository: ghcr.io/cloudfoundry/app-autoscaler-release-tools
tag: main

inputs:
- name: bbl-state
- name: ci
- name: multiapps-controller-web-war
- name: multiapps-controller-web-manifest

run:
path: ci/ci/infrastructure/scripts/deploy-multiapps-controller.sh
20 changes: 20 additions & 0 deletions ci/infrastructure/tasks/deploy-postgres.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
platform: linux

image_resource:
type: registry-image
source:
repository: ghcr.io/cloudfoundry/app-autoscaler-release-tools
tag: main

params:
SLACK_WEBHOOK:

inputs:
- name: bbl-state
- name: ci
- name: postgres-release
- name: postgres-repo

run:
path: ci/ci/infrastructure/scripts/deploy-postgres.sh
19 changes: 19 additions & 0 deletions ci/operations/add-multiapps-databases-to-postgres.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- type: replace
path: /instance_groups/name=postgres/jobs/name=postgres/properties?/databases/databases/name=sandbox?
value:
name: multiapps_controller
citext: true

- type: replace
path: /instance_groups/name=postgres/jobs/name=postgres/properties?/databases/roles/name=pgadmin?
value:
name: pgadmin
password: ((pgadmin_database_password))
permissions:
- "CONNECTION LIMIT 50"

- type: replace
path: /variables?/name=pgadmin_database_password?
value:
name: pgadmin_database_password
type: password
Loading
Loading