Skip to content

Commit

Permalink
flatten bundled files for GH release
Browse files Browse the repository at this point in the history
  • Loading branch information
pinkeen committed Jun 17, 2020
1 parent 2090b1f commit dbe9a1e
Show file tree
Hide file tree
Showing 17 changed files with 239 additions and 28 deletions.
12 changes: 8 additions & 4 deletions .ci/bundle.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ lib::import ui


LIB="$MAGEOPS_BASH_LIB_DIR"
OUT="bin"
OUT="__bundle__"

bundle-library() {
cat > "$OUT/lib.bundle.bash" <<ENDBANNER
Expand All @@ -28,8 +28,9 @@ ENDBANNER
}

bundle-script() {
SCRIPT="$1"
OUTFILE="$2"
NAME="${SCRIPT%.bash}"
OUTFILE="$OUT/$NAME.bundle.bash"

cat > "$OUTFILE" <<ENDBANNER
#!/usr/bin/env bash
Expand Down Expand Up @@ -58,8 +59,11 @@ ui::step "Clean $(ui::em $OUT)" \
ui::step "Bundle library files to $(ui::em $OUT/lib.bundle.bash)" \
bundle-library

find . -maxdepth 1 -type f -iname '*.bash' | while read SCRIPT ; do
find bin -type f -iname '*.bash' | while read SCRIPT ; do
OUTFILE="$OUT/$(echo "$SCRIPT" | tr '/' '.')"
mkdir -p "$(dirname "$OUTFILE")"

ui::step "Bundle $(ui::em $SCRIPT) with lib" \
bundle-script "$SCRIPT" "$OUT/$SCRIPT"
bundle-script "$SCRIPT" "$OUTFILE"
done

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/bin/
/__bundle__/
*tmp
.tmp*
*.gz
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ deploy:
- provider: releases
token: $GITHUB_OAUTH_TOKEN
file_glob: true
file: "bin/*.bash"
file: "__bundle__/*.bash"
skip_cleanup: true
cleanup: false
on:
Expand Down
4 changes: 2 additions & 2 deletions raccoon-migrate.bash → bin/raccoon/host/migrate.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e

source "${MAGEOPS_BASH_LIB_DIR:-.}/lib/_lib.bash"

lib::import raccoon::migrate
lib::import raccoon::host

raccoon::migrate::script "$@"
raccoon::host::migrate::script "$@"

4 changes: 0 additions & 4 deletions lib/core.bash

This file was deleted.

5 changes: 5 additions & 0 deletions lib/mageops.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mageops::__module__() {
lib::import mageops::core
lib::import mageops::bootstrap
lib::import mageops::ansible
}
30 changes: 30 additions & 0 deletions lib/mageops/ansible.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
mageops::ansible::__module__() {
lib::import mageops::core

export ANSIBLE_FORCE_COLOR="yes"

mageops::ansible::virtualenv::install() {
}

mageops::ansible::virtualenv::activate() {
}

mageops::ansible::virtualenv::update() {
}

mageops::ansible::playbook() {
local PLAYBOOK="$1"; shift

mageops::ansible::virtualenv::activate

pushd "$MAGEOPS_ANSIBLE_DIR"

ansible-playbook \
-i inventory/raccoon.yml \
--limit raccoon_local \
"$@" \
"${PLAYBOOK}.yml"

popd
}
}
57 changes: 57 additions & 0 deletions lib/mageops/bootstrap.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
mageops::bootstrap::__module__()
lib::import ui
lib::import mageops::core
lib::import mageops::ansible

mageops::bootstrap::project-vars-install() {

}

mageops::bootstrap::install() {
chmod +x $MAGEOPS_ROOT/bin/*

ln -snvf \
$MAGEOPS_ROOT/bin/* \
/usr/local/bin/

mkdir -pv \
$MAGEOPS_ROOT/ansible

git clone \
--depth 5 \
--single-branch \
--branch "${MAGEOPS_ANSIBLE_BRANCH}" \
https://github.com/mageops/ansible-infrastructure.git \
$MAGEOPS_ROOT/ansible/infrastructure

git clone \
https://github.com/mageops/ansible-infrastructure-vars.git \
$MAGEOPS_ROOT/ansible/infrastructure-vars

mkdir -pv \
$MAGEOPS_ROOT/ansible/infrastructure/vars/global \
$MAGEOPS_ROOT/ansible/infrastructure/vars/local \
$MAGEOPS_ROOT/ansible/infrastructure/vars/project \
$MAGEOPS_ROOT/ansible/infrastructure/tmp

rm -rf \
$MAGEOPS_ROOT/ansible/infrastructure/vars/project/

ln -snvf \
$MAGEOPS_ROOT/ansible/infrastructure-vars/project-raccoon/ \
$MAGEOPS_ROOT/ansible/infrastructure/vars/project

virtualenv-3 $MAGEOPS_ROOT/ansible/virtualenv

source $MAGEOPS_ROOT/ansible/virtualenv/bin/activate

pip install \
-r $MAGEOPS_ROOT/ansible/infrastructure/requirements-python.txt

ansible-galaxy install \
-r $MAGEOPS_ROOT/ansible/infrastructure/requirements-galaxy.yml \
-p $MAGEOPS_ROOT/ansible/infrastructure/roles

mkdir -p $MAGEOPS_ROOT/ansible/bin
}
}
16 changes: 16 additions & 0 deletions lib/mageops/core.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
mageops::core::__module__() {
export MAGEOPS_PREFIX="${MAGEOPS_PREFIX:-/opt/mageops}"

export MAGEOPS_ANSIBLE_ROOT_DIR="${MAGEOPS_PREFIX}/ansible"
export MAGEOPS_ANSIBLE_VENV_DIR="${MAGEOPS_ANSIBLE_ROOT_DIR}/virtualenv"

export MAGEOPS_ANSIBLE_REPO="https://github.com/mageops/ansible-infrastructure.git"
export MAGEOPS_ANSIBLE_BRANCH="${MAGEOPS_ANSIBLE_BRANCH:-master}"
export MAGEOPS_ANSIBLE_INVENTORY="${MAGEOPS_ANSIBLE_INVENTORY:-inventory/raccoon.yml}"

export MAGEOPS_ANSIBLE_DIR="${MAGEOPS_ANSIBLE_ROOT_DIR}/infrastructure"
export MAGEOPS_ANSIBLE_TMP_DIR="${MAGEOPS_ANSIBLE_DIR}/tmp"
export MAGEOPS_ANSIBLE_VARS_DIR="${MAGEOPS_ANSIBLE_DIR}/vars"
export MAGEOPS_ANSIBLE_VARS_PROJECT_DIR="${MAGEOPS_ANSIBLE_VARS_DIR}/project"
export MAGEOPS_ANSIBLE_VARS_GLOBAL_DIR="${MAGEOPS_ANSIBLE_VARS_DIR}/global"
}
4 changes: 4 additions & 0 deletions lib/mageops/mageops-install
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

set -ex

8 changes: 8 additions & 0 deletions lib/mageops/mageops-playbook
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

set -e

MAGEOPS_ROOT="${MAGEOPS_ROOT:-/opt/mageops}"

. $MAGEOPS_ROOT/ansible/virtualenv/bin/activate

23 changes: 23 additions & 0 deletions lib/mageops/mageops-raccoon
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

set -e

MAGEOPS_ROOT="${MAGEOPS_ROOT:-/opt/mageops}"

parse_vars() {
for var in "$@" ; do
echo "--extra-vars '$var'"
done
}

if [ $# -lt 1 ] ; then
echo "Usage: $0 cmd,cmd2,... extra_var=value extra_var2=value2 ..." >&2
exit 1
fi

CMD="$1"; shift

$MAGEOPS_ROOT/bin/mageops-playbook \
raccoon.cmd \
--extra-vars "raccoon_cmd=$CMD" \
`parse_vars "$@"`
30 changes: 30 additions & 0 deletions lib/mageops/mageops-trim
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

set -e



yum -y clean all || true
dnf -y clean all || true

systemctl stop php-fpm
systemctl stop varnish
systemctl stop elasticsearch
systemctl stop nginx
systemctl stop mysql
systemctl stop redis
systemctl stop redis-sessions
systemctl stop elasticsearch

rm -rvf \
/{root,home/magento}/{.cache/*,.opcache/*,.*history,.composer,.yarn/*,.npm/*} \
/var/lib/mysql/ib_logfile* \
/var/lib/mysql/ib_tmp* \
/var/lib/varnish/* \
/var/lib/redis/* \
/var/lib/redis-sessions/*

echo '' | find /var/log -type f -exec tee {} \;
echo '' | find /var/www/magento/ -mindepth 3 -type f -path '*/var/log/*' -exec tee {} \;


31 changes: 31 additions & 0 deletions lib/mageops/mageops-update
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

set -ex

git-update() {
git fetch
git pull \
|| ( git stash && git pull && git stash pop ) \
|| git reset --hard "$(git rev-parse --abbrev-ref --symbolic-full-name @{u})"
git -c color.ui=always --no-pager log -1
}

MAGEOPS_ROOT="${MAGEOPS_ROOT:-/opt/mageops}"

cd $MAGEOPS_ROOT/ansible/infrastructure && git-update
cd $MAGEOPS_ROOT/ansible/infrastructure/vars/project && git-update

source $MAGEOPS_ROOT/ansible/virtualenv/bin/activate

pip install \
-r $MAGEOPS_ROOT/ansible/infrastructure/requirements-python.txt

ansible-galaxy install \
-r $MAGEOPS_ROOT/ansible/infrastructure/requirements-galaxy.yml \
-p $MAGEOPS_ROOT/ansible/infrastructure/roles






3 changes: 3 additions & 0 deletions lib/raccoon/core.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
raccoon::core::__module__() {

}
4 changes: 4 additions & 0 deletions lib/raccoon/host.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
raccoon::host::__module__() {
lib::import raccoon::core
lib::import raccoon::host::migrate
}
32 changes: 16 additions & 16 deletions lib/raccoon/migrate.bash → lib/raccoon/host/migrate.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
raccoon::migrate::__module__() {
raccoon::host::migrate::__module__() {
lib::import ui
lib::import fs
lib::import remote
Expand All @@ -10,56 +10,56 @@ raccoon::migrate::__module__() {
RACCOON_MIGRATE_REMOTE_ROOT_DIR="${RACCOON_MIGRATE_RACCOON_MIGRATE_REMOTE_ROOT_DIR_DIR:-/var/www/magento}"
RACCOON_MIGRATE_TIMESTAMP="$(timestamp::day)"

raccoon::migrate::export-db() {
raccoon::host::migrate::export-db() {
ui::info "Exporting project $(ui::em $PROJECT) db"
magento::db::export "$PROJECT" "$LOCAL_PROJECT_DIR/db.sql.gz"
}

raccoon::migrate::export-code() {
raccoon::host::migrate::export-code() {
ui::info "Exporting project $(ui::em $PROJECT) code"
magento::code::export "$REMOTE_PROJECT_DIR" "$LOCAL_PROJECT_DIR/code.tar.gz"
}

raccoon::migrate::export-media() {
raccoon::host::migrate::export-media() {
ui::info "Exporting project $(ui::em $PROJECT) media"
magento::media::export "$REMOTE_PROJECT_DIR" "$LOCAL_PROJECT_DIR/media.tar.gz"
}

raccoon::migrate::export-all() {
raccoon::migrate::export-db && raccoon::migrate::export-media && raccoon::migrate::export-code
raccoon::host::migrate::export-all() {
raccoon::host::migrate::export-db && raccoon::host::migrate::export-media && raccoon::host::migrate::export-code
}

raccoon::migrate::import-db() {
raccoon::host::migrate::import-db() {
ui::info "Importing project $(ui::em $PROJECT) db"
magento::db::import "$PROJECT" "$RACCOON_PROJECT_DB_USER" "$RACCOON_PROJECT_DB_PASS" "$LOCAL_PROJECT_DIR/db.sql.gz"
}

raccoon::migrate::import-code() {
raccoon::host::migrate::import-code() {
ui::info "Importing project $(ui::em $PROJECT) code"
fs::unarchive "$REMOTE_PROJECT_DIR" "$LOCAL_PROJECT_DIR/code.tar.gz"
}

raccoon::migrate::import-media() {
raccoon::host::migrate::import-media() {
ui::info "Importing project $(ui::em $PROJECT) media"
fs::unarchive "$REMOTE_PROJECT_DIR" "$LOCAL_PROJECT_DIR/media.tar.gz"
}

raccoon::migrate::import-all() {
raccoon::migrate::import-db && raccoon::migrate::import-media && raccoon::migrate::import-code
raccoon::host::migrate::import-all() {
raccoon::host::migrate::import-db && raccoon::host::migrate::import-media && raccoon::host::migrate::import-code
}

raccoon::migrate::list-export() {
raccoon::host::migrate::list-export() {
ui::step "List remote projects" \
`remote::cmd \
find "$RACCOON_MIGRATE_REMOTE_ROOT_DIR" -mindepth 1 -maxdepth 1 -type d -printf "%P\n"`
}

raccoon::migrate::list-import() {
raccoon::host::migrate::list-import() {
ui::step "List local projects" \
find "$RACCOON_MIGRATE_LOCAL_ARCHIVE_DIR" -mindepth 1 -maxdepth 1 -type d -printf '%P\n'
}

raccoon::migrate::script() {
raccoon::host::migrate::script() {
if [ ! $# -eq 3 ] ; then
echo "Usage: $0 <export|import> <all|{project}> <all|db|code|media>"
lib::leave 1
Expand All @@ -71,7 +71,7 @@ raccoon::migrate::__module__() {


if [ "$PROJECTS" == "all" ] ; then
PROJECTS="$("raccoon::migrate::list-$MODE")"
PROJECTS="$("raccoon::host::migrate::list-$MODE")"
fi

for PROJECT in $PROJECTS ; do
Expand All @@ -83,7 +83,7 @@ raccoon::migrate::__module__() {

ui::info "Processing project $(ui::em $PROJECT)"

if ! "raccoon::migrate::$MODE-$WHAT" ; then
if ! "raccoon::host::migrate::$MODE-$WHAT" ; then
ui::warn "Failed to process project $(ui::em $PROJECT) but continuing"
fi
done
Expand Down

0 comments on commit dbe9a1e

Please # to comment.