Skip to content

Commit

Permalink
Support for Customizing the HAProxy Feature Version
Browse files Browse the repository at this point in the history
  • Loading branch information
kinjelom committed Jun 7, 2024
1 parent 8569997 commit 5f03189
Show file tree
Hide file tree
Showing 16 changed files with 315 additions and 105 deletions.
40 changes: 40 additions & 0 deletions add-blobs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

set -eux

source ./src/meta-info/blobs-versions.env
BLOBS_TMP_DIR=".blobs"

mkdir -p "$BLOBS_TMP_DIR"

function down_add_blob {
BLOBS_GROUP=$1
FILE=$2
URL=$3
if [ ! -f "blobs/${BLOBS_GROUP}/${FILE}" ];then
echo "Downloads resource from the Internet ($URL -> $BLOBS_TMP_DIR/$FILE)"
curl -L "$URL" --output "$BLOBS_TMP_DIR/$FILE"
echo "Adds blob ($BLOBS_TMP_DIR/$FILE -> $BLOBS_GROUP/$FILE), starts tracking blob in config/blobs.yml for inclusion in packages"
bosh add-blob "$BLOBS_TMP_DIR/$FILE" "$BLOBS_GROUP/$FILE"
fi
}

# down_add_blob "haproxy" "haproxy-${HAPROXY_1_8_VERSION}.tar.gz" "$HAPROXY_1_8_URL"
# down_add_blob "haproxy" "haproxy-${HAPROXY_1_9_VERSION}.tar.gz" "$HAPROXY_1_9_URL"

down_add_blob "haproxy" "haproxy-${HAPROXY_2_8_VERSION}.tar.gz" "$HAPROXY_2_8_URL"
down_add_blob "haproxy" "haproxy-${HAPROXY_2_9_VERSION}.tar.gz" "$HAPROXY_2_9_URL"

down_add_blob "haproxy" "haproxy-${HAPROXY_3_0_VERSION}.tar.gz" "$HAPROXY_3_0_URL"

down_add_blob "haproxy" "hatop-${HATOP_VERSION}" "$HATOP_URL"
down_add_blob "haproxy" "lua-${LUA_VERSION}.tar.gz" "$LUA_URL"
down_add_blob "haproxy" "pcre2-${PCRE2_VERSION}.tar.gz" "$PCRE2_URL"
down_add_blob "haproxy" "socat-${SOCAT_VERSION}.tar.gz" "$SOCAT_URL"
down_add_blob "keepalived" "keepalived-${KEEPALIVED_VERSION}.tar.gz" "$KEEPALIVED_URL"

echo "Download blobs into blobs/ based on config/blobs.yml"
bosh sync-blobs

echo "Upload previously added blobs that were not yet uploaded to the blobstore. Updates config/blobs.yml with returned blobstore IDs."
bosh upload-blobs
24 changes: 12 additions & 12 deletions config/blobs.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
haproxy/haproxy-2.8.9.tar.gz:
size: 4383096
object_id: 95357784-6a57-4112-47a2-9590af64135d
sha: sha256:7a821478f36f847607f51a51e80f4f890c37af4811d60438e7f63783f67592ff
haproxy/haproxy-2.9.7.tar.gz:
size: 4516225
sha: sha256:d1a0a56f008a8d2f007bc0c37df6b2952520d1f4dde33b8d3802710e5158c131
haproxy/haproxy-3.0.0.tar.gz:
size: 4677659
sha: sha256:5aad97416216d2cd9dd212eb674839c40cd387f60fbc4b13d7ea3f1e5664a814
haproxy/hatop-0.8.2:
size: 74157
object_id: 00125e3f-bdaa-4da3-583f-b680b0b30df4
sha: sha256:6ba2136e98b9a436488be67a54a5295f55f38090157d09df0154dda493ac5815
haproxy/lua-5.4.6.tar.gz:
size: 363329
object_id: 7b7ffa11-ae22-4fec-5f45-fcef34d8291f
sha: sha256:7d5ea1b9cb6aa0b59ca3dde1c6adcb57ef83a1ba8e5432c0ecd06bf439b3ad88
haproxy/pcre2-10.43.tar.gz:
size: 2522928
object_id: b712245c-72ec-43bb-462c-b15e2fbe7f07
sha: sha256:889d16be5abb8d05400b33c25e151638b8d4bac0e2d9c76e9d6923118ae8a34e
haproxy/socat-1.7.4.4.tar.gz:
size: 662968
object_id: 674c1075-b8d9-4b29-5af3-d0d0ed1cbb09
sha: sha256:0f8f4b9d5c60b8c53d17b60d79ababc4a0f51b3bb6d2bd3ae8a6a4b9d68f195e
keepalived/keepalived-2.2.8.tar.gz:
size: 1202602
object_id: ce994b90-fe7b-4563-71f2-a93a515eb5b0
sha: sha256:85882eb62974f395d4c631be990a41a839594a7e62fbfebcb5649a937a7a1bb6
haproxy/socat-1.8.0.0.tar.gz:
size: 712469
sha: sha256:6010f4f311e5ebe0e63c77f78613d264253680006ac8979f52b0711a9a231e82
keepalived/keepalived-2.3.1.tar.gz:
size: 1210697
sha: sha256:92f4b69bfd998e2306d1995ad16fdad1b59e70be694c883385c5f55e02c62aa3
14 changes: 13 additions & 1 deletion jobs/haproxy/spec
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ name: haproxy

description: "The HAProxy server can be used to terminate SSL in front of the Routers. Each HAProxy instance should point to multiple Routers."

# LTS - Long Term Support
# STS - Short Term Support
packages:
- haproxy
# - haproxy-1.8 # LTS
# - haproxy-1.9 # STS
- haproxy-2.8 # LTS
- haproxy-2.9 # STS
- haproxy-3.0 # LTS
- ttar

templates:
Expand Down Expand Up @@ -39,6 +45,12 @@ consumes:
optional: true

properties:
ha_proxy.haproxy_feature_version:
description: |
You can select an HAProxy feature version by specifying the 'major.minor' version number, one of several HAProxy packages included in this release.
This release has been tested only with the default HAProxy feature version.
Use other version lines with raw configurations at your own risk.
default: '2.8' # LTS
ha_proxy.pre_start_script:
description: |
This script will be appended to the pre-start script and run before the job starts.
Expand Down
8 changes: 3 additions & 5 deletions jobs/haproxy/templates/haproxy_wrapper.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/bin/bash
#
#!/bin/bash -e

set -e

export PATH=$PATH:/var/vcap/packages/haproxy/bin:/var/vcap/packages/ttar/bin
export HAPROXY_FEATURE_VERSION='<%= p("ha_proxy.haproxy_feature_version") -%>'
export PATH="$PATH:/var/vcap/packages/haproxy-$HAPROXY_FEATURE_VERSION/bin:/var/vcap/packages/ttar/bin"
CONFIG=/var/vcap/jobs/haproxy/config/haproxy.config
PID_FILE=/var/vcap/sys/run/haproxy/haproxy.pid
DRAIN_LOCK=/var/vcap/sys/run/haproxy/drain.lock
Expand Down
36 changes: 25 additions & 11 deletions jobs/haproxy/templates/pre-start.erb
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
#!/bin/bash -e

export HAPROXY_FEATURE_VERSION='<%= p("ha_proxy.haproxy_feature_version") -%>'
mkdir -p /var/vcap/jobs/haproxy/errorfiles

create_or_update_link() {
local target="$1"
local link="$2"

if [ -L "$link" ]; then
if [ "$(readlink "$link")" != "$target" ]; then
echo "Updating symbolic link..."
sudo ln -sf "$target" "$link"
fi
else
if [ -e "$link" ]; then
echo "Removing existing file and creating a new symbolic link..."
sudo rm "$link"
else
echo "Creating new symbolic link..."
sudo ln -s "$target" "$link"
fi
fi
}


<% p('ha_proxy.custom_http_error_files', {}).each do |status_code, http_content| -%>

cat > <%= "/var/vcap/jobs/haproxy/errorfiles/custom#{status_code}.http" %> << EOF
<%= http_content %>
EOF
<% end -%>

if [ ! -e /usr/bin/python ] && [ -e /usr/bin/python3 ]; then
sudo ln -s /usr/bin/python3 /usr/bin/python
fi

if [ ! -e /usr/local/bin/hatop ]; then
sudo ln -s /var/vcap/packages/haproxy/hatop-wrapper /usr/local/bin/hatop
fi

if [ ! -e /usr/local/bin/socat ]; then
sudo ln -s /var/vcap/packages/haproxy/bin/socat /usr/local/bin/socat
fi
create_or_update_link /usr/bin/python3 /usr/bin/python
create_or_update_link "/var/vcap/packages/haproxy-$HAPROXY_FEATURE_VERSION/hatop-wrapper" /usr/local/bin/hatop
create_or_update_link "/var/vcap/packages/haproxy-$HAPROXY_FEATURE_VERSION/bin/socat" /usr/local/bin/socat

<%- if_p("ha_proxy.pre_start_script") do |script| -%>
# ha_proxy.pre_start_script {{{
Expand Down
15 changes: 15 additions & 0 deletions packages/haproxy-2.8/packaging
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
# abort script on failures
set -euxo pipefail

source meta-info/blobs-versions.env
mkdir "${BOSH_INSTALL_TARGET}/bin"

source packaging-tools/installation.sh

install_hatop "$BOSH_INSTALL_TARGET" "$HATOP_VERSION"
install_lua "$BOSH_INSTALL_TARGET" "$LUA_VERSION"
install_pcre2 "$BOSH_INSTALL_TARGET" "$PCRE2_VERSION"
install_socat "$BOSH_INSTALL_TARGET" "$SOCAT_VERSION"

install_haproxy "$BOSH_INSTALL_TARGET" "$HAPROXY_2_8_VERSION"
4 changes: 3 additions & 1 deletion packages/haproxy/spec → packages/haproxy-2.8/spec
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---
name: haproxy
name: haproxy-2.8
files:
- meta-info/blobs-versions.env
- packaging-tools/installation.sh
- haproxy/haproxy-*.tar.gz
- haproxy/pcre2-*.tar.gz
- haproxy/socat-*.tar.gz
Expand Down
15 changes: 15 additions & 0 deletions packages/haproxy-2.9/packaging
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
# abort script on failures
set -euxo pipefail

source meta-info/blobs-versions.env
mkdir "${BOSH_INSTALL_TARGET}/bin"

source packaging-tools/installation.sh

install_hatop "$BOSH_INSTALL_TARGET" "$HATOP_VERSION"
install_lua "$BOSH_INSTALL_TARGET" "$LUA_VERSION"
install_pcre2 "$BOSH_INSTALL_TARGET" "$PCRE2_VERSION"
install_socat "$BOSH_INSTALL_TARGET" "$SOCAT_VERSION"

install_haproxy "$BOSH_INSTALL_TARGET" "$HAPROXY_2_9_VERSION"
11 changes: 11 additions & 0 deletions packages/haproxy-2.9/spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: haproxy-2.9
files:
- meta-info/blobs-versions.env
- packaging-tools/installation.sh
- haproxy/haproxy-*.tar.gz
- haproxy/pcre2-*.tar.gz
- haproxy/socat-*.tar.gz
- haproxy/lua-*.tar.gz
- haproxy/hatop-*
- hatop-wrapper
15 changes: 15 additions & 0 deletions packages/haproxy-3.0/packaging
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
# abort script on failures
set -euxo pipefail

source meta-info/blobs-versions.env
mkdir "${BOSH_INSTALL_TARGET}/bin"

source packaging-tools/installation.sh

install_hatop "$BOSH_INSTALL_TARGET" "$HATOP_VERSION"
install_lua "$BOSH_INSTALL_TARGET" "$LUA_VERSION"
install_pcre2 "$BOSH_INSTALL_TARGET" "$PCRE2_VERSION"
install_socat "$BOSH_INSTALL_TARGET" "$SOCAT_VERSION"

install_haproxy "$BOSH_INSTALL_TARGET" "$HAPROXY_3_0_VERSION"
11 changes: 11 additions & 0 deletions packages/haproxy-3.0/spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: haproxy-3.0
files:
- meta-info/blobs-versions.env
- packaging-tools/installation.sh
- haproxy/haproxy-*.tar.gz
- haproxy/pcre2-*.tar.gz
- haproxy/socat-*.tar.gz
- haproxy/lua-*.tar.gz
- haproxy/hatop-*
- hatop-wrapper
72 changes: 0 additions & 72 deletions packages/haproxy/packaging

This file was deleted.

7 changes: 4 additions & 3 deletions packages/keepalived/packaging
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# abort script on any command that exits with a non zero value
set -e -x

source meta-info/blobs-versions.env

# Copy common utils
mkdir -p ${BOSH_INSTALL_TARGET}/common
cp -a ${BOSH_COMPILE_TARGET}/common/* ${BOSH_INSTALL_TARGET}/common

KEEPALIVED_VERSION=2.2.8 # https://keepalived.org/software/keepalived-2.2.8.tar.gz
tar xzvf keepalived/keepalived-${KEEPALIVED_VERSION}.tar.gz
cd keepalived-${KEEPALIVED_VERSION}/
tar xzvf keepalived/keepalived-${KEEPALIVED_VER}.tar.gz
cd keepalived-${KEEPALIVED_VER}/

#compile keepalive
./configure --prefix=${BOSH_INSTALL_TARGET}
Expand Down
1 change: 1 addition & 0 deletions packages/keepalived/spec
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ name: keepalived
dependencies: []

files:
- meta-info/blobs-versions.env
- common/utils.sh
- keepalived/keepalived-*.tar.gz
42 changes: 42 additions & 0 deletions src/meta-info/blobs-versions.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# http://www.haproxy.org/download/

# haproxy-1.8.31.tar.gz 09-Dec-2022 15:44
# HAPROXY_1_8_VERSION="1.8.31"
# HAPROXY_1_8_URL="http://www.haproxy.org/download/1.8/src/haproxy-${HAPROXY_1_8_VERSION}.tar.gz"

# haproxy-1.9.16.tar.gz 31-Jul-2020 12:07
# HAPROXY_1_9_VERSION="1.9.16"
# HAPROXY_1_9_URL="http://www.haproxy.org/download/1.9/src/haproxy-${HAPROXY_1_9_VERSION}.tar.gz"

# haproxy-2.8.9.tar.gz 05-Apr-2024 18:54
HAPROXY_2_8_VERSION="2.8.9"
HAPROXY_2_8_URL="http://www.haproxy.org/download/2.8/src/haproxy-${HAPROXY_2_8_VERSION}.tar.gz"

# haproxy-2.9.7.tar.gz 05-Apr-2024 18:23
HAPROXY_2_9_VERSION="2.9.7"
HAPROXY_2_9_URL="http://www.haproxy.org/download/2.9/src/haproxy-${HAPROXY_2_9_VERSION}.tar.gz"

# haproxy-3.0.0.tar.gz 29-May-2024 13:11
HAPROXY_3_0_VERSION="3.0.0"
HAPROXY_3_0_URL="http://www.haproxy.org/download/3.0/src/haproxy-${HAPROXY_3_0_VERSION}.tar.gz"


# https://github.com/jhunt/hatop/releases
HATOP_VERSION="0.8.2"
HATOP_URL="https://github.com/jhunt/hatop/releases/download/v${HATOP_VERSION}/hatop"

# https://www.lua.org/ftp/
LUA_VERSION="5.4.6"
LUA_URL="https://www.lua.org/ftp/lua-${LUA_VERSION}.tar.gz"

# https://github.com/PCRE2Project/pcre2/releases
PCRE2_VERSION="10.43"
PCRE2_URL="https://github.com/PCRE2Project/pcre2/releases/download/pcre2-${PCRE2_VERSION}/pcre2-${PCRE2_VERSION}.tar.gz"

# http://www.dest-unreach.org/socat/download/
SOCAT_VERSION="1.8.0.0"
SOCAT_URL="http://www.dest-unreach.org/socat/download/socat-${SOCAT_VERSION}.tar.gz"

# https://keepalived.org/download.html
KEEPALIVED_VERSION="2.3.1"
KEEPALIVED_URL="https://keepalived.org/software/keepalived-${KEEPALIVED_VERSION}.tar.gz"
Loading

0 comments on commit 5f03189

Please sign in to comment.