This is a common challenge with foreman and I found that a monthly schedule would fit my needs. The promotion will have to go through different environments such as lab + nightly, development, test, production + management. I've added a schema of how this should look like down below.
Now keep in mind, that this is the solution that best fits my needs and might not cover all your requirements. However, here's the short script I've created which will be executed by cron daily:
Now keep in mind, that this is the solution that best fits my needs and might not cover all your requirements. However, here's the short script I've created which will be executed by cron daily:
#!/usr/bin/env bash
ORGANIZATION_LABEL='YOUR_ORGANIZATION'
LIFECYCLE_ENVIRONMENT=''
DATE_DAY=$(date +%d)
WEEK_DAY=$(date +%u)
if [[ $DATE_DAY == '01' ]]; then
LIFECYCLE_ENVIRONMENT='nightly'
for content_view_id in $(hammer content-view list --organization-label $ORGANIZATION_LABEL | egrep -vi 'default' | awk '{print $1}' | egrep '^[1-9]' | egrep -v '14' | awk NF); do
hammer content-view publish --id $content_view_id --organization-label $ORGANIZATION_LABEL
for environment in $(echo $LIFECYCLE_ENVIRONMENT); do
hammer content-view version promote --content-view-id $content_view_id --version $(hammer content-view info --id $content_view_id --organization-label $ORGANIZATION_LABEL | egrep -i 'version' | awk '{print $2}' | tail -n 1) --organization-label $ORGANIZATION_LABEL --to-lifecycle-environment $environment
done
done
else
echo 'Not publishing since it is not 1st of the month.'
fi
# If week day is friday
if [ $WEEK_DAY -eq '5' ]; then
# friday in the first week of the month
if [[ $DATE_DAY == '01' || $DATE_DAY == '02' || $DATE_DAY == '03' || $DATE_DAY == '04' || $DATE_DAY == '05' || $DATE_DAY == '06' || $DATE_DAY == '07' ]]; then
LIFECYCLE_ENVIRONMENT='development'
# friday in the second week of the month
elif [[ $DATE_DAY == '08' || $DATE_DAY == '09' || $DATE_DAY == '10' || $DATE_DAY == '11' || $DATE_DAY == '12' || $DATE_DAY == '13' || $DATE_DAY == '14' ]]; then
LIFECYCLE_ENVIRONMENT='test'
# friday in the third week of the month
elif [[ $DATE_DAY == '15' || $DATE_DAY == '16' || $DATE_DAY == '17' || $DATE_DAY == '18' || $DATE_DAY == '19' || $DATE_DAY == '20' || $DATE_DAY == '21' ]]; then
LIFECYCLE_ENVIRONMENT='production'
else
echo 'Nothing to promote.'
fi
for environment in $(echo $LIFECYCLE_ENVIRONMENT); do
for content_view_id in $(hammer content-view list --organization-label $ORGANIZATION_LABEL | egrep -vi 'default' | awk '{print $1}' | egrep '^[1-9]' | awk NF); do
hammer content-view version promote --content-view-id $content_view_id --version $(hammer content-view info --id $content_view_id --organization-label $ORGANIZATION_LABEL | egrep -i 'version' | awk '{print $2}' | tail -n 1) --organization-label $ORGANIZATION_LABEL --to-lifecycle-environment $environment
done
done
else
echo 'Not promoting anything since today is not friday.'
fi
Feel free to comment and / or suggest a topic.
Comments
Post a Comment