Newer
Older

Aliaksandr Lubouski (EPAM)
committed
#!/usr/bin/env bash
#
# The following script renders and archives bundles of policies for instance and partition level
# After that archives are uploaded to GCS bucket or MinIO bucket

Aliaksandr Lubouski (EPAM)
committed
set -ex
create_instance_bundles() {
# Renders and archives intance level policies
echo "Archiving bundle of instance policies..."
tar -czf bundle.tar.gz --directory='/opt/deployment/default-policies' --exclude='./bootstrap_sequence.json' . --verbose
mkdir --parents /opt/policies ; mv bundle.tar.gz "$_"
echo "Instance policies archive is ready"
}
create_partition_bundle() {
# Renders and archives policies for data_partition
# Creates archive named bundle-<data_partition>.tar.gz in /opt/policies
# Args: $1 - data_partition_id
DATA_PARTITION=$1
echo "Archiving bundle of policies for parition: ${DATA_PARTITION}..."
python3 /opt/devops/gc/bootstrap-osdu-module/DataPartitionBundles.py --partition "${DATA_PARTITION}"
mv /opt/bundle-"${DATA_PARTITION}".tar.gz /opt/policies
echo "${DATA_PARTITION} partition archive is ready"
}
bootstrap_gcs() {
echo "Push archives to GCS bucket"
gsutil cp -n /opt/policies/* gs://"${POLICY_BUCKET}"/
echo "Bootstrap finished successfully"
}
bootstrap_minio() {
echo "Configuring mc tool"
mc alias set minio "${MINIO_HOST}":"${MINIO_PORT}" "${MINIO_ACCESS_KEY}" "${MINIO_SECRET_KEY}"
echo "Pushing archives to Minio bucket"
for file in /opt/policies/*;
do
echo "Processing $file:"
file_name=${file##*/}
# Check if file already exists
if mc stat minio/"${POLICY_BUCKET}"/"$file_name" > /dev/null 2>&1; then
echo "Skipping $file: already exists in bucket"
else
mc cp "$file" minio/"${POLICY_BUCKET}"/"$file_name"
fi
done
echo "Bootstrap finished successfully"
# Main part
source ./validate-env.sh "DATA_PARTITION"
source ./validate-env.sh "POLICY_BUCKET"
## Creating instance bundles
create_instance_bundles
## Creating partition bundles
IFS=',' read -ra PARTITIONS <<< "${DATA_PARTITION_ID_LIST}"
PARTITIONS=("${PARTITIONS[@]}")
for PARTITION in "${PARTITIONS[@]}"; do
create_partition_bundle "${PARTITION}"
## Uploading bundles to gcs/minio bucket
if [ "${ONPREM_ENABLED}" == "true" ]
then
source ./validate-env.sh "MINIO_HOST"
source ./validate-env.sh "MINIO_ACCESS_KEY"
source ./validate-env.sh "MINIO_SECRET_KEY"
source ./validate-env.sh "MINIO_PORT"
bootstrap_minio
else
bootstrap_gcs
fi
touch /tmp/bootstrap_ready