Skip to content

Instantly share code, notes, and snippets.

@tmuth
Last active December 4, 2017 16:02
Show Gist options
  • Save tmuth/7ce0077a7aa587c153b16e8a0bc37000 to your computer and use it in GitHub Desktop.
Save tmuth/7ce0077a7aa587c153b16e8a0bc37000 to your computer and use it in GitHub Desktop.
Export splunk apps out of docker containers
function get_container_id {
name="${1?needs one argument}"
containerId=$(docker ps | awk -v app="$name" '$2 ~ app{print $1}')
if [[ -n "$containerId" ]]; then
echo ${containerId}
else
echo "No docker container with name: $name is running"
fi
}
function package_app {
containerName="${1?needs one argument}"
appName="${2?needs one argument}"
containerId=$(get_container_id ${containerName})
SPLUNK_USERNAME=admin
SPLUNK_PASS=changeme
docker exec -it ${containerId} /bin/bash -c "/opt/splunk/bin/splunk package app ${appName} -auth ${SPLUNK_USERNAME}:${SPLUNK_PASS} "
}
function docker_copy_out {
containerName="${1?needs one argument}"
sourcePath="${2?needs one argument}"
destPath="${3?needs one argument}"
containerId=$(get_container_id ${containerName})
echo "About to copy: ${containerId}:${sourcePath} ${destPath} "
docker cp ${containerId}:${sourcePath} "${destPath}"
}
export SPLK_PKG=/opt/splunk/etc/system/static/app-packages
export GIT_APPS="/Users/tmuth/Box Sync/Git/demo-dbconnect/dbconnect/apps/"
alias get-orcl-mon-app='docker_copy_out dbx ${SPLK_PKG}/oracle_monitoring.spl "${GIT_APPS}"'
alias get-dbx-demo-app='docker_copy_out dbx ${SPLK_PKG}/dbx_demo.spl "${GIT_APPS}"'
alias package-apps='package_app dbx oracle_monitoring;package_app dbx dbx_demo;get-orcl-mon-app;get-dbx-demo-app'
@tmuth
Copy link
Author

tmuth commented Dec 4, 2017

For anyone working on demos or apps in docker that wants to export them regularly, here are my helper functions from my bash_profile to package 2 apps running inside a docker container, then copy them out to the host file system (so I can commit to git).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment