From 16e5ea504aebc0afbd90b2276df8b93e0e57edd4 Mon Sep 17 00:00:00 2001 From: Nemo Date: Sun, 26 Apr 2020 06:14:36 +0530 Subject: [PATCH] [sync] Adds proper sync support --- .gitignore | 1 + Dockerfile | 2 +- LICENSE | 4 ++-- entrypoint.sh | 28 +++++++++++++++++++++------- env.sample | 4 ++++ outliner.gemspec | 2 +- 6 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 env.sample diff --git a/.gitignore b/.gitignore index 78356df..2784239 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ /vendor/ Gemfile.lock *.gem +.env diff --git a/Dockerfile b/Dockerfile index d9113aa..b922cc3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ COPY . /outliner/ RUN gem install bundler && \ bundle install && \ - apk add --no-cache git openssh-client && \ + apk add --no-cache git openssh-client rsync && \ echo -e "StrictHostKeyChecking no" >> /etc/ssh/ssh_config && \ mkdir /root/.ssh diff --git a/LICENSE b/LICENSE index b21898b..1615a9b 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,7 @@ -Copyright 2019 Abhay Rana +Copyright 2020 Abhay Rana Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/entrypoint.sh b/entrypoint.sh index 4ac69cb..f6ad9b5 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -41,22 +41,36 @@ case $1 in bundle exec outliner-import "$@" ;; sync) - tmp_dir=$(mktemp -d) + BRANCH=${GIT_BRANCH:-master} + old_git_dir=$(mktemp -d) + fresh_export_dir=$(mktemp -d) if [ -z "$GIT_REMOTE_URL" ]; then echo "[E] GIT_REMOTE_URL not set" exit 1 else + git clone --branch "$BRANCH" "$GIT_REMOTE_URL" "$old_git_dir" setup_git - bundle exec outliner-export "$tmp_dir" - cd "$tmp_dir" - git init update_git_config + echo "[+] Exporting data from Outline" + bundle exec outliner-export "$fresh_export_dir" + echo "[+] Resetting git repository" + cd "$old_git_dir" + # We update so that git forgets all files + git ls-files -z |xargs -n1 -0 git rm + # Then we copy across the files from the new export + cd "$fresh_export_dir" + echo "[+] Updating git repository" + rsync -av . "$old_git_dir" + cd "$old_git_dir" + echo "[+] Committing to git" git add . git commit --message "Backup: $(date)" > /dev/null - BRANCH=${GIT_BRANCH:-master} - git checkout -b "$BRANCH" git status - git push origin --force "HEAD:$BRANCH" + echo "[+] Pushing to git remote" + git push origin "HEAD:$BRANCH" + echo "[+] Cleaning up" + rm -rf "$old_git_dir" + rm -rf "$fresh_export_dir" fi ;; *) diff --git a/env.sample b/env.sample new file mode 100644 index 0000000..6d221eb --- /dev/null +++ b/env.sample @@ -0,0 +1,4 @@ +OUTLINE_BASE_URI=https://outline.example.com +GIT_BRANCH=master +GIT_REMOTE_URL=git@example.com:org/outline.backup.git +OUTLINE_TOKEN= diff --git a/outliner.gemspec b/outliner.gemspec index 9aeda22..06d2ec0 100644 --- a/outliner.gemspec +++ b/outliner.gemspec @@ -7,7 +7,7 @@ Gem::Specification.new do |spec| spec.name = "outliner" spec.version = Outliner::VERSION spec.authors = ["Nemo"] - spec.email = ["rubygem.outliner@captnemo.in"] + spec.email = ["outliner@captnemo.in"] spec.licenses = ["MIT"] spec.summary = "A simple HTTParty based client for outline knowledge base."