forked from bcgov/dts-endorser-service
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Rajpal Chauhan <[email protected]>
- Loading branch information
Showing
3 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
FROM registry.access.redhat.com/ubi8/python-39:latest | ||
|
||
# Change timezone to PST for convenience | ||
ENV TZ=PST8PDT | ||
|
||
# ======================================================================================================== | ||
# Install go-crond (from https://github.com/webdevops/go-crond) | ||
# | ||
# | ||
# CRON Jobs in OpenShift: | ||
# - https://blog.danman.eu/cron-jobs-in-openshift/ | ||
# -------------------------------------------------------------------------------------------------------- | ||
ARG SOURCE_REPO=webdevops | ||
ARG GOCROND_VERSION=22.9.1 | ||
ADD https://github.com/$SOURCE_REPO/go-crond/releases/download/$GOCROND_VERSION/go-crond.linux.amd64 /usr/bin/go-crond | ||
|
||
COPY ./docker/run.sh . | ||
COPY ./docker/audit.conf . | ||
COPY ./scripts ./scripts | ||
RUN cd $HOME/scripts && pip install -r requirements.txt | ||
|
||
USER root | ||
# ======================================================================================================== | ||
# Perform operations that require root privilages here ... | ||
# -------------------------------------------------------------------------------------------------------- | ||
RUN mkdir -p $HOME/scripts/export | ||
RUN echo $TZ > /etc/timezone | ||
RUN chmod +x /usr/bin/go-crond | ||
RUN chmod +x ./run.sh | ||
RUN chown default:root $HOME/scripts/export && chmod g+w $HOME/scripts/export | ||
# ======================================================================================================== | ||
USER 1001 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
15 1 * * * default cd scripts && USE_LEAR=false python ./detail_audit_report.py | ||
15 2 * * * default cd scripts && USE_LEAR=true python ./detail_audit_report.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/bin/bash | ||
|
||
AUDIT_CONF=${AUDIT_CONF:-./audit.conf} | ||
|
||
function echoBlue (){ | ||
_msg="${@}" | ||
_blue='\e[34m' | ||
_nc='\e[0m' # No Color | ||
echo -e "${_blue}${_msg}${_nc}" | ||
} | ||
|
||
function logInfo(){ | ||
( | ||
infoMsg="${1}" | ||
echo -e "${infoMsg}" | ||
postMsgToWebhook "${ENVIRONMENT_FRIENDLY_NAME}" \ | ||
"${ENVIRONMENT_NAME}" \ | ||
"INFO" \ | ||
"${infoMsg}" | ||
) | ||
} | ||
|
||
function logWarn(){ | ||
( | ||
warnMsg="${1}" | ||
echoYellow "${warnMsg}" | ||
postMsgToWebhook "${ENVIRONMENT_FRIENDLY_NAME}" \ | ||
"${ENVIRONMENT_NAME}" \ | ||
"WARN" \ | ||
"${warnMsg}" | ||
) | ||
} | ||
|
||
function logError(){ | ||
( | ||
errorMsg="${1}" | ||
echoRed "[!!ERROR!!] - ${errorMsg}" >&2 | ||
postMsgToWebhook "${ENVIRONMENT_FRIENDLY_NAME}" \ | ||
"${ENVIRONMENT_NAME}" \ | ||
"ERROR" \ | ||
"${errorMsg}" | ||
) | ||
} | ||
|
||
function postMsgToWebhook(){ | ||
( | ||
if [ -z "${WEBHOOK_URL}" ] && [ -f ${WEBHOOK_TEMPLATE} ]; then | ||
return 0 | ||
fi | ||
|
||
projectFriendlyName=${1} | ||
projectName=${2} | ||
statusCode=${3} | ||
message=$(formatWebhookMsg "${4}") | ||
curl -s -X POST -H 'Content-Type: application/json' --data "$(getWebhookPayload)" "${WEBHOOK_URL}" > /dev/null | ||
) | ||
} | ||
|
||
function shutDown(){ | ||
jobIds=$(jobs | awk -F '[][]' '{print $2}' ) | ||
for jobId in ${jobIds} ; do | ||
echo "Shutting down background job '${jobId}' ..." | ||
kill %${jobId} | ||
done | ||
|
||
if [ ! -z "${jobIds}" ]; then | ||
echo "Waiting for any background jobs to complete ..." | ||
fi | ||
wait | ||
|
||
exit 0 | ||
} | ||
|
||
function startCron(){ | ||
logInfo "Starting audit server in cron mode ..." | ||
echoBlue "Starting go-crond as a background task ...\n" | ||
CRON_CMD="go-crond -v --default-user=${UID} --working-directory=$(pwd) --allow-unprivileged ${AUDIT_CONF}" | ||
exec ${CRON_CMD} & | ||
wait | ||
} | ||
|
||
trap shutDown EXIT TERM | ||
|
||
startCron |