Skip to content

Commit

Permalink
Rebuild for updated docker-template
Browse files Browse the repository at this point in the history
  • Loading branch information
MickMake committed Mar 15, 2020
1 parent 72bbbfc commit b42806a
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 97 deletions.
21 changes: 17 additions & 4 deletions TEMPLATE/build/build/JSON_NAME.sh.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,25 @@ test -f /etc/gearbox/bin/colors.sh && . /etc/gearbox/bin/colors.sh
c_ok "Started."

c_ok "Installing packages."
if [ -f /etc/gearbox/build/{{ .Json.name }}.apks ]
then
APKS="$(cat /etc/gearbox/build/{{ .Json.name }}.apks)"
apk update && apk add --no-cache ${APKS}; checkExit
APKBIN="$(which apk)"
if [ "${APKBIN}" != "" ]
if [ -f /etc/gearbox/build/{{ .Json.name }}.apks ]
then
APKS="$(cat /etc/gearbox/build/{{ .Json.name }}.apks)"
${APKBIN} update && ${APKBIN} add --no-cache ${APKS}; checkExit
fi
fi

APTBIN="$(which apt-get)"
if [ "${APTBIN}" != "" ]
if [ -f /etc/gearbox/build/{{ .Json.name }}.apt ]
then
DEBS="$(cat /etc/gearbox/build/{{ .Json.name }}.apt)"
${APTBIN} update && ${APTBIN} install ${DEBS}; checkExit
fi
fi


if [ -f /etc/gearbox/build/{{ .Json.name }}.env ]
then
. /etc/gearbox/build/{{ .Json.name }}.env
Expand Down
2 changes: 2 additions & 0 deletions TEMPLATE/build/services/JSON_NAME/run.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

c_ok "Starting."

cd /home/gearbox/projects/default

GBEP="$(which ${GEARBOX_ENTRYPOINT})"
if [ "${GBEP}" != "" ]
then
Expand Down
170 changes: 115 additions & 55 deletions bin/TemplateRelease.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,86 @@ DIR="$(dirname $0)"
CMD="$1"
VERSION="$2"

shift
shift
DESCRIPTION="$@"


help() {
cat<<EOF
$(basename $0)
Updates the docker-template GitHub repository with either a new or updated release.
$(basename $0) create [version] - Creates a new release on GitHub.
$(basename $0) update [version] - Updates an existing release on GitHub.
$(basename $0) create [version] [description] - Creates a new release on GitHub.
$(basename $0) update [version] [description] - Updates an existing release on GitHub.
if [version] isn't specified, then...
- Prompt the user for a new version.
- Do nothing.
EOF
}

check() {
echo "# Gearbox[${GB_GITREPO}]: Checking if release v${VERSION} exists."
${DIR}/github-release info \
-u gearboxworks \
-r "${GB_GITREPO}" \
-t "${VERSION}" >& /dev/null
RETURN="$?"
# 0 - Exists.
# 1 - Doesn't exist.
}

create() {
echo "# Gearbox[${GB_GITREPO}]: Creating release v${VERSION} on GitHub."
${DIR}/github-release release \
--user "gearboxworks" \
--repo "${GB_GITREPO}" \
--tag "${VERSION}" \
--name "Release ${VERSION}" \
--description "${DESCRIPTION}"
}

update() {
echo "# Gearbox[${GB_GITREPO}]: Updating release v${VERSION} on GitHub."
${DIR}/github-release edit \
--user "gearboxworks" \
--repo "${GB_GITREPO}" \
--tag "${VERSION}" \
--name "Release ${VERSION}" \
--description "${DESCRIPTION}"
}

upload() {
FILES="Makefile TEMPLATE bin"
echo "# Gearbox[${GB_GITREPO}]: Creating tarball release from files: ${FILES}"
tar zcf docker-template.tgz ${FILES}

echo "# Gearbox[${GB_GITREPO}]: Uploading tarball release v${VERSION} to GitHub."
${DIR}/github-release upload \
--user "gearboxworks" \
--repo "${GB_GITREPO}" \
--tag "${VERSION}" \
--name "docker-template.tgz" \
--label "docker-template.tgz" \
-R \
-f docker-template.tgz

rm -f docker-template.tgz
}

find_last_version() {
${DIR}/github-release info -u gearboxworks -r "${GB_GITREPO}" -j > /tmp/z
LAST_VERSION="$(${DIR}/JsonToConfig -json /tmp/z -template-string '{{ with index .Json.Releases 0 }}{{ .tag_name }}{{ end }}')"
}

get_description() {
GET_VERSION="$1"; export GET_VERSION
${DIR}/github-release info -u gearboxworks -r "${GB_GITREPO}" -j > /tmp/z
LAST_DESCRIPTION="$(${DIR}/JsonToConfig -json /tmp/z -template-string '{{ range $k,$v := .Json.Releases }}{{ if eq .tag_name $.Env.GET_VERSION }}{{ .body }}{{ end }}{{ end }}')"
}


################################################################################
GB_GITURL="$(git config --get remote.origin.url)"; export GB_GITURL
Expand All @@ -30,27 +94,38 @@ else
GB_GITREPO="$(basename -s .git ${GB_GITURL})"; export GB_GITREPO
fi

if [ "${GB_GITREPO}" != "docker-template" ]
then
echo "################################### WARNING ###################################"
echo "# This command can only be run from the docker-template GitHub repository."
echo "# Only gearboxworks staff use this command to update the docker-template repo."
echo "# Check out the README file on how to use this repo."
echo "################################### WARNING ###################################"
exit 1
fi
#if [ "${GB_GITREPO}" != "docker-template" ]
#then
# echo "################################### WARNING ###################################"
# echo "# This command can only be run from the docker-template GitHub repository."
# echo "# Only gearboxworks staff use this command to update the docker-template repo."
# echo "# Check out the README file on how to use this repo."
# echo "################################### WARNING ###################################"
# exit 1
#fi


################################################################################
if [ "${CMD}" == "" ]
then
echo "# Gearbox[${GB_GITREPO}]: Doing nothing."
help

find_last_version
echo "# Gearbox[${GB_GITREPO}]: Last version: ${LAST_VERSION}"

get_description ${LAST_VERSION}
echo "# Gearbox[${GB_GITREPO}]: Last description: \"${LAST_DESCRIPTION}\""

exit 1
fi

if [ "${VERSION}" == "" ]
then
echo "# Gearbox[${GB_GITREPO}]: No release version specified."

find_last_version
echo "# Gearbox[${GB_GITREPO}]: Last version in repo is ${LAST_VERSION}"
echo -n "Enter a release version: "
read VERSION

Expand All @@ -59,15 +134,24 @@ then
echo "# Gearbox[${GB_GITREPO}]: No version entered? OK doing nothing."
exit 1
fi
fi

# if [ "${VERSION}" == "${LAST_VERSION}" ]
# then
# fi
fi

echo "################################################################################"
echo "# Gearbox[${GB_GITREPO}]: Pushing repo to GitHub."
git commit -a -m "Latest push" && git push
if [ "${DESCRIPTION}" == "" ]
then
get_description ${VERSION}
if [ "${LAST_DESCRIPTION}" == "" ]
then
DESCRIPTION="Release ${VERSION}"
else
DESCRIPTION="${LAST_DESCRIPTION}"
fi
fi


echo "# Gearbox[${GB_GITREPO}]: Creating release on GitHub."
if [ "${GB_GITREPO}" == "" ]
then
echo "# Gearbox[${GB_GITREPO}]: GB_GITREPO isn't set... Strange..."
Expand All @@ -90,44 +174,12 @@ then
fi


check() {
echo "# Gearbox[${GB_GITREPO}]: Checking if release v${VERSION} exists."
${DIR}/github-release info \
-u gearboxworks \
-r "${GB_GITREPO}" \
-t "${VERSION}" >& /dev/null
RETURN="$?"
# 0 - Exists.
# 1 - Doesn't exist.
}

create() {
echo "# Gearbox[${GB_GITREPO}]: Creating release v${VERSION} on GitHub."
${DIR}/github-release release \
--user "gearboxworks" \
--repo "${GB_GITREPO}" \
--tag "${VERSION}" \
--name "Release ${VERSION}"
}

upload() {
FILES="Makefile TEMPLATE bin"
echo "# Gearbox[${GB_GITREPO}]: Creating tarball release from files: ${FILES}"
tar zcf docker-template.tgz ${FILES}

echo "# Gearbox[${GB_GITREPO}]: Uploading tarball release v${VERSION} to GitHub."
${DIR}/github-release upload \
--user "gearboxworks" \
--repo "${GB_GITREPO}" \
--tag "${VERSION}" \
--name "docker-template.tgz" \
--label "docker-template.tgz" \
-R \
-f docker-template.tgz

rm -f docker-template.tgz
}
echo "################################################################################"
echo "# Gearbox[${GB_GITREPO}]: Creating release ${VERSION} on GitHub."
echo "# Gearbox[${GB_GITREPO}]: Description: \"${DESCRIPTION}.\""

echo "# Gearbox[${GB_GITREPO}]: Pushing repo to GitHub."
git commit -a -m "${DESCRIPTION}" && git push

export RETURN
case "${CMD}" in
Expand All @@ -141,7 +193,10 @@ case "${CMD}" in

create

upload
if [ "${GB_GITREPO}" == "docker-template" ]
then
upload
fi

echo "# Gearbox[${GB_GITREPO}]: Release v${VERSION} OK."
;;
Expand All @@ -154,7 +209,12 @@ case "${CMD}" in
exit 1
fi

upload
if [ "${GB_GITREPO}" == "docker-template" ]
then
upload
fi

update

echo "# Gearbox[${GB_GITREPO}]: Release v${VERSION} OK."
;;
Expand Down
4 changes: 2 additions & 2 deletions bin/_Colors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ blinkon() { ${GB_TERM_CMD} "{{ .Json.blink.slow }}"; }
blinkoff() { ${GB_TERM_CMD} "{{ .Json.blink.off }}"; }


p_err() { local _name="$1"; shift; blinkon; bp_echo "${_name}" red white $@; }
p_err() { local _name="$1"; shift; blinkon; bp_echo "${_name}" red white $@; blinkoff; }
p_warn() { local _name="$1"; shift; p_echo "${_name}" yellow $@; }
p_info() { local _name="$1"; shift; p_echo "${_name}" white $@; }
p_ok() { local _name="$1"; shift; p_echo "${_name}" green $@; }
Expand All @@ -67,7 +67,7 @@ p_cyan() { local _name="$1"; shift; p_echo "${_name}" cyan $@; }
p_white() { local _name="$1"; shift; p_echo "${_name}" white $@; }


c_err() { blinkon; bp_echo "" red white "$@"; }
c_err() { blinkon; bp_echo "" red white "$@"; blinkoff; }
c_warn() { p_echo "" yellow "$@"; }
c_info() { p_echo "" white "$@"; }
c_ok() { p_echo "" green "$@"; }
Expand Down
Loading

0 comments on commit b42806a

Please sign in to comment.