-
-
Notifications
You must be signed in to change notification settings - Fork 177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple Repositories for Addons #539
base: develop
Are you sure you want to change the base?
Conversation
Started development for multiple repositories that can be used for addons. Additionally, added ability to run updates between addons. Rather then running the risk of the addons being out of sync
@sean-e-dietrich can you please rebase it on the develop branch that now has your commit to fix tests for external PRs? |
@achekulaev I already merged the changes in and am rerunning the tests. |
bin/fin
Outdated
@@ -167,6 +167,7 @@ URL_ADDONS_HOSTING="https://raw.githubusercontent.com" | |||
URL_ADDONS_REPO="$URL_ADDONS_HOSTING/docksal/addons" | |||
# Remove URL_REPO_ADDONS in Nov 2018 | |||
URL_REPO_ADDONS="https://raw.githubusercontent.com/docksal/addons" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable is unused now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can remove it, I was leaving it there because I know you said remove in Nov '18
bin/fin
Outdated
@@ -1728,11 +1729,13 @@ show_help_addon () | |||
echo | |||
echo-green "Commands:" | |||
printh "install <name>" "Install addon" | |||
printh "update <name>" "Update addon" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should use tab for indentation
bin/fin
Outdated
config="${config}|master" | ||
local REPO_URL=$(echo $config | cut -d'|' -f1) | ||
local REPO_BRANCH=$(echo $config | cut -d'|' -f2) | ||
local uuid=$(uuidgen) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use tabs everywhere for indentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't use uuidgen. I'd like to avoid relying on additional binaries when possible. Use $RANDOM
bash variable. Search for /tmp/etc.exports.$RANDOM
in fin to see usage example
bin/fin
Outdated
local uuid=$(uuidgen) | ||
|
||
# Check to make sure the provided Repo URL is valid and the Branch Exists | ||
local valid=$(git ls-remote -h $REPO_URL --refs $REPO_BRANCH | wc -l) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- git's stderr should be redirected to dev/null
- since it's non-fatal I would avoid echo-error
- it's better to use
grep -q $REPO_BRANCH
to avoid counting some random output as a valid output
# Check that provided repo URL is valid and the branch exists
git ls-remote -h "$REPO_URL" --refs "$REPO_BRANCH" 2>/dev/null | grep -q "$REPO_BRANCH"
if [[ "$?" != "0" ]]; then
echo "$key defines an invalid repository/branch reference. Skipping..."
continue
else
...
bin/fin
Outdated
git remote add origin $repo_url > /dev/null | ||
git fetch -q origin $repo_branch > /dev/null | ||
git checkout origin/${repo_branch} ${addon_name} 2> /dev/null | ||
git checkout origin/${repo_branch} ${addon_name}.pre-install 2> /dev/null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not every addon has pre-install hook. We should only check the main file
bin/fin
Outdated
git init > /dev/null | ||
git remote add origin $repo_url > /dev/null | ||
git fetch -q origin $repo_branch > /dev/null | ||
git checkout origin/${repo_branch} ${addon_name} 2> /dev/null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this command should actually be the last. If main addon file did check out then everything is in order. If it did not then it is an error.
Styling hint. Please don't put a space here 2>/dev/null
bin/fin
Outdated
if_failed_error "Could not create $addon_path" "Check file permissions and try again" | ||
fi | ||
|
||
local tmp_addon="/tmp/${ADDON_UUID}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's refactor var name to addons_repo_copy
bin/fin
Outdated
if_failed_error "Download has failed" "Check log above for messages" | ||
fi | ||
echo-red "Addon already exists in $addon_path. Run ${NC}fin addon update ${addon_name}" | ||
exit 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return 1
bin/fin
Outdated
git pull --depth=1 origin/${URL_ADDONS_BRANCH} | ||
# Remove Git Repo that was cloned from. | ||
rm -rf $tmp_addon/.git 2>/dev/null | ||
mv -R $tmp_addon $addon_path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mv -R
is an anti-pattern because of inability to properly handle errors (what failed, copy or delete?) and because it will leave leftovers if copying errors happen.
cp -R
followed by rm -rf
should be used instead.
bin/fin
Outdated
local URL_ADDONS_REPO | ||
local URL_ADDONS_BRANCH | ||
local ADDON_UUID | ||
_addon_search_repo $addon_name URL_ADDONS_REPO URL_ADDONS_BRANCH ADDON_UUID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block should be moved down, below the check for addon existence
bin/fin
Outdated
else | ||
echo-red "Unknown error" | ||
rm -rf $tmp_addon | ||
exit 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo-error "Addon main file does not exist, is a symlink or is not set to be executable"
rm -rf "$tmp_addon" >/dev/null 2>&1
return 1
bin/fin
Outdated
# If repo contains multiple addon let's only download the repo we need. | ||
elif [[ -d $tmp_addon/$addon_name ]] && [[ -f $tmp_addon/$addon_name/$addon_name ]] && [[ -x $tmp_addon/$addon_name/$addon_name ]]; then | ||
# Remove Git Repo that was cloned from. | ||
rm -rf $tmp_addon/.git 2>/dev/null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both outputs should be redirected
rm -rf "$tmp_addon/.git" >/dev/null 2>&1
bin/fin
Outdated
# Update addon | ||
# $1 - addon name | ||
# $2 - optional flag to install globally | ||
addon_update () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this function different from addon_install?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@achekulaev addon_update
only handles the updating piece. I believe the goal would be to eventually make it so that there were pre-update
and post-update
hooks for addons. Eventually also there could be the capability of versioning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get that in future there might be difference, but is there any real code difference with addon_install
right now? Because in PR review they look identical to me. And if they are identical right now I would just call addon_install
for fin addon update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the only difference would be the hooks. So seeing as the same code is ran for them both maybe refactoring the code and putting it in a function of it's own so it isn't duplicate coding.
bin/fin
Outdated
git ls-remote -h "$REPO_URL" --refs "$REPO_BRANCH" 2>/dev/null | grep -q "$REPO_BRANCH" | ||
if [[ "$?" != "0" ]]; then | ||
echo "$key defines an invalid repository/branch reference. Skipping..." | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be no continue
here or rm -rf "/tmp/${uuid}"
will not clean up.
Actually you might want to revisit this whole thing and move rm -rf
into inside if-clauses.
bin/fin
Outdated
local repo_uuid=$4 | ||
|
||
echo-green "Searching for ${addon} in predefined repositories..." | ||
for key in "${repos[@]}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for config in "${repos[@]}"
bin/fin
Outdated
echo-green "Searching for ${addon} in predefined repositories..." | ||
for key in "${repos[@]}" | ||
do | ||
local config=${!key} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for this, it should be for config in "${repos[@]}"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
repos
is an array of variable names
When looping through those variables, key
refers to the variable name that is being used.
config
is referring to the value for the variable that is stored.
Example:
DOCKSAL_ADDONS_REPO="https://github.com/docksal/addons"
DOCKSAL_ADDONS_REPO_X="https://github.com/kanopi/docksal-toolkit.git|sample"
eval 'repos=(${!'"DOCKSAL_ADDONS_REPO"'@})'
# should produce something like the following array
# repos=(DOCKSAL_ADDONS_REPO DOCKSAL_ADDONS_REPO_X)
for key in "${repos[@]}"
do
local config=${!key} #when looped will now grab the value for that variable
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Then let's refactor to
for repo in "${repos[@]}"
key is just too generic.
bin/fin
Outdated
done | ||
|
||
if [[ -z "${REPO_URL}" ]]; then | ||
echo-red "Addon not found to install." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo-error "Could not find addon ${addon_name} in any of the pre-defined repositories." \
"Check repositories and branches spelling"
return 1
@@ -5167,47 +5238,94 @@ addon_install () | |||
echo-red "Pre-install hook has failed and aborted the installation." | |||
# Delete downloaded files if pre-install hook fails | |||
[[ -d "$addon_path" ]] && [[ "$addon_path" =~ ".docksal" ]] && | |||
rm -r "$addon_path" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that indentation was intentional
@sean-e-dietrich could you give me write access to your repo fork? I'd like to download and test first and I think I will have more fixes afterwards. |
@achekulaev I couldn't give you access to the Kanopi's org but I cloned the repo into a personal account and made it private. Also added you on the repo as a collaborator |
Thanks. I don't need access to Kanopi.org, the access you've given to https://github.com/sean-e-dietrich/docksal which you have raised the PR from is enough. |
d7566be
to
215a590
Compare
Needs to be rebased into develop. |
This PR has been open for 2.5 years. @sean-e-dietrich do you still intend finalizing it? If not, please close. |
Started development for multiple repositories that can be used for addons.
Additionally, added ability to run updates between addons. Rather then
running the risk of the addons being out of sync
This is a rewrite of the PR #535 and I believe this solves #368 and solves #405
This takes information that was written through back channels and allows for GIT repos to be used when checking out addons instead of downloading raw files with only support for github.
Additionally, support for multiple repositories is added. The repositories must be prefixed with
DOCKSAL_ADDONS_REPO_
in order to have them searched. TheDOCKSAL_ADDONS_REPO
which is the same repo at https://github.com/docksal/addons is searched first but can be overridden within the.docksal/docksal.env
file.Syntax:
Because a repository can have multiple branches there is an additional options for the variable to designate which branch is selected.
[NAME]
Should be replaced with a unique machine name for that repo[Repo URL]
Should be the GIT repo url that will be used to clone the repo.[BRANCH]
Is optional but designates what branch of the repo to use, if not includedmaster
branch will be used.NOTE A pipe
(|)
is used to separate the[REPO URL]
and[BRANCH]
. If[BRANCH]
is omitted then the pipe is not necessaryExamples:
This also adds in a
fin addon update
command which will allow for the addon to run a similar process as thefin addon install
. The update process will look forpre-update
andpost-update
hooks as well.The purpose for this is that if an addon has a single repo it can be tracked and to a certain extent versioned appropriately, but more so then that, if there is a need for developer to use their own personal addons in projects, but they also have a repo which is shared amongst a team then they can use both of the repositories.