From 5b80e13ada40511c28b2c57701c177dbab15d7cb Mon Sep 17 00:00:00 2001 From: Paul Qualls Date: Fri, 30 Apr 2021 13:34:29 -0600 Subject: [PATCH] updating dockerfile and scripts for remote install of plugin --- Dockerfile | 15 +++++++----- call_mm_plugin_installer.sh | 3 +++ install-mattermost-plugin.sh | 47 ++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 6 deletions(-) create mode 100755 call_mm_plugin_installer.sh create mode 100755 install-mattermost-plugin.sh diff --git a/Dockerfile b/Dockerfile index a668a51..d1a3125 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,10 +6,9 @@ FROM ${BASE_REGISTRY}/${BASE_IMAGE}:${BASE_TAG} AS builder WORKDIR /tmp +COPY install-mattermost-plugin.sh . +COPY call_mm_plugin_installer.sh . COPY mattermost-admin-plugin-1.0.2-rc.tar.gz . - -# RUN tar xzvf mattermost-admin-plugin-1.0.2-rc.tar.gz - COPY linux_amd64.tar . RUN tar xvf linux_amd64.tar @@ -17,6 +16,8 @@ RUN tar xvf linux_amd64.tar FROM registry1.dso.mil/ironbank/google/golang/golang-1.16:1.16 # FROM registry1.dso.mil/ironbank/docker/scratch:ironbank +ENV TARGET_URL="URL IS UNDEFINED" +ENV TARGET_TOKEN="TARGET TOKEN IS UNDEFINED" WORKDIR /bin @@ -25,12 +26,14 @@ COPY --from=builder /tmp/mmctl . WORKDIR /plugin COPY --from=builder /tmp/mattermost-admin-plugin-1.0.2-rc.tar.gz . +COPY --from=builder /tmp/install-mattermost-plugin.sh . +COPY --from=builder /tmp/call_mm_plugin_installer.sh . USER 1001 -# ENTRYPOINT [ "/bin/mmctl" ] -ENTRYPOINT ["tail", "-f", "/dev/null"] -# CMD ["version"] +# the entrypoint script calls the main installer which uses ENV vars for token and url to contact the target and install the plugin +ENTRYPOINT [ "./call_mm_plugin_installer.sh" ] +# ENTRYPOINT ["tail", "-f", "/dev/null"] HEALTHCHECK NONE diff --git a/call_mm_plugin_installer.sh b/call_mm_plugin_installer.sh new file mode 100755 index 0000000..2af8a55 --- /dev/null +++ b/call_mm_plugin_installer.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +./install-mattermost-plugin.sh -u $TARGET_URL -t $TARGET_TOKEN \ No newline at end of file diff --git a/install-mattermost-plugin.sh b/install-mattermost-plugin.sh new file mode 100755 index 0000000..e15e99a --- /dev/null +++ b/install-mattermost-plugin.sh @@ -0,0 +1,47 @@ +#!/bin/sh + +# params [token, url] + +# obtain the plugin name and plugin ID from the pipeline (hardcoded for now) + +# need 2 params [username, password] + +# call mmctl auth +# mmctl plugin add +# mmctl plugin enable +# + +while getopts u:t: flag +do + let opts++ + case "${flag}" in + u) url=${OPTARG};; + t) token=${OPTARG};; + esac +done + +[[ $opts -lt 2 ]] && echo "Please provide 2 args" && exit 1 + +echo " using URL: $url"; +echo " using Token: $token"; + +# mmctl auth login http://localhost:8065 -n paul -a cenneh38ifd9tfqy7trwra918r + result=$(mmctl auth login $url -n plugininstall -a $token) + + echo "result: $result" + +# look for th word "stored" for success, "Invalid" as failure + +# if creds successfully stored, then delete the plugin by ID (we don't care if it fails or not) +result=$(mmctl plugin delete com.mattermost.p1-admin-mattermost-plugin) + +# install the plugin with the tar.gz file +result=$(mmctl plugin add mattermost-admin-plugin-1.0.2-rc.tar.gz --format json) + +# if the install was successful, then enable it +result=$(mmctl plugin enable com.mattermost.p1-admin-mattermost-plugin --format json) + + +echo $result + + -- GitLab