community-script rework

This commit is contained in:
sadnub 2022-01-21 18:11:27 -05:00
parent b8653e6601
commit 39311099df
7 changed files with 45 additions and 12 deletions

View File

@ -93,15 +93,9 @@ class Script(BaseAuditModel):
# load community uploaded scripts into the database
# skip ones that already exist, only updating name / desc in case it changes
# for install script
if not settings.DOCKER_BUILD:
scripts_dir = os.path.join(Path(settings.BASE_DIR).parents[1], "scripts")
# for docker
else:
scripts_dir = settings.SCRIPTS_DIR
scripts_dir = os.path.join(settings.SCRIPTS_DIR, "scripts")
with open(
os.path.join(settings.BASE_DIR, "scripts/community_scripts.json")
) as f:
with open(os.path.join(settings.SCRIPTS_DIR, "community_scripts.json")) as f:
info = json.load(f)
# used to remove scripts from DB that are removed from the json file and file system

View File

@ -4,7 +4,7 @@ from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent
SCRIPTS_DIR = "/srv/salt/scripts"
SCRIPTS_DIR = "/community-scripts"
DOCKER_BUILD = False

View File

@ -16,11 +16,16 @@ COPY api/tacticalrmm/requirements.txt ${TACTICAL_TMP_DIR}/api/requirements.txt
RUN apt-get update && \
apt-get install -y --no-install-recommends gcc libc6-dev && \
rm -rf /var/lib/apt/lists/* && \
pip install --upgrade pip && \
pip install --no-cache-dir setuptools wheel && \
pip install --no-cache-dir -r ${TACTICAL_TMP_DIR}/api/requirements.txt
# pulls community scripts from git repo
FROM python:3.9.9-slim AS GET_SCRIPTS_STAGE
RUN apt-get update && \
apt-get install -y --no-install-recommends git && \
git clone https://github.com/amidaware/community-scripts.git /
# runtime image
FROM python:3.9.9-slim
@ -35,7 +40,7 @@ ENV PATH "${VIRTUAL_ENV}/bin:$PATH"
# copy files from repo
COPY api/tacticalrmm ${TACTICAL_TMP_DIR}/api
COPY scripts ${TACTICAL_TMP_DIR}/scripts
COPY --from=GET_SCRIPTS_STAGE /community-scripts ${TACTICAL_TMP_DIR}/community-scripts
# copy go install from build stage
COPY --from=CREATE_VENV_STAGE ${VIRTUAL_ENV} ${VIRTUAL_ENV}

View File

@ -70,7 +70,7 @@ KEY_FILE = '${CERT_PRIV_PATH}'
EXE_DIR = '/opt/tactical/api/tacticalrmm/private/exe'
LOG_DIR = '/opt/tactical/api/tacticalrmm/private/log'
SCRIPTS_DIR = '/opt/tactical/scripts'
SCRIPTS_DIR = '/opt/tactical/community-scripts'
ALLOWED_HOSTS = ['${API_HOST}', 'tactical-backend']

View File

@ -243,6 +243,13 @@ git config user.email "admin@example.com"
git config user.name "Bob"
git checkout master
sudo mkdir /community-scripts
sudo chown ${USER}:${USER} /community-scripts
git clone https://github.com/wh1te909/tacticalrmm.git /community-scripts/
cd /community-scripts
git config user.email "admin@example.com"
git config user.name "Bob"
print_green 'Downloading NATS'
NATS_SERVER_VER=$(grep "^NATS_SERVER_VER" /rmm/api/tacticalrmm/tacticalrmm/settings.py | awk -F'[= "]' '{print $5}')

View File

@ -218,6 +218,13 @@ git config user.email "admin@example.com"
git config user.name "Bob"
git checkout master
sudo mkdir /community-scripts
sudo chown ${USER}:${USER} /community-scripts
git clone https://github.com/wh1te909/tacticalrmm.git /community-scripts/
cd /community-scripts
git config user.email "admin@example.com"
git config user.name "Bob"
print_green 'Restoring NATS'
NATS_SERVER_VER=$(grep "^NATS_SERVER_VER" /rmm/api/tacticalrmm/tacticalrmm/settings.py | awk -F'[= "]' '{print $5}')

View File

@ -226,6 +226,7 @@ fi
sudo npm install -g npm
# update from main repo
cd /rmm
git config user.email "admin@example.com"
git config user.name "Bob"
@ -235,11 +236,30 @@ git reset --hard FETCH_HEAD
git clean -df
git pull
# update from community-scripts repo
if [[ ! -d /community-scripts ]]; then
sudo mkdir /community-scripts
sudo chown ${USER}:${USER} /community-scripts
git clone https://github.com/wh1te909/tacticalrmm.git /community-scripts/
cd /community-scripts
git config user.email "admin@example.com"
git config user.name "Bob"
else
cd /community-scripts
git config user.email "admin@example.com"
git config user.name "Bob"
git fetch
git reset --hard FETCH_HEAD
git clean -df
git pull
fi
SETUPTOOLS_VER=$(grep "^SETUPTOOLS_VER" "$SETTINGS_FILE" | awk -F'[= "]' '{print $5}')
WHEEL_VER=$(grep "^WHEEL_VER" "$SETTINGS_FILE" | awk -F'[= "]' '{print $5}')
sudo chown ${USER}:${USER} -R /rmm
sudo chown ${USER}:${USER} -R /community-scripts
sudo chown ${USER}:${USER} /var/log/celery
sudo chown ${USER}:${USER} -R /etc/conf.d/
sudo chown -R $USER:$GROUP /home/${USER}/.npm