Skip to content

Commit

Permalink
adding dockerfile
Browse files Browse the repository at this point in the history
Signed-off-by: Rajpal Chauhan <[email protected]>
  • Loading branch information
rajpalc7 committed Dec 20, 2023
1 parent 58be5cb commit 7be4865
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 0 deletions.
32 changes: 32 additions & 0 deletions docker/Dockerfile
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
2 changes: 2 additions & 0 deletions docker/audit.config
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
84 changes: 84 additions & 0 deletions docker/run.sh
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

0 comments on commit 7be4865

Please sign in to comment.