From 0eff53c136696372b2baa87dfc44089467537eda Mon Sep 17 00:00:00 2001
From: Paul J Stevens
Date: Sun, 13 Aug 2023 22:23:40 +0200
Subject: [PATCH] wip: improving docker/downloader
---
.gitignore | 3 ++
Dockerfile | 14 ++------
Makefile | 14 +++++++-
{bin => scripts}/download.sh | 63 +++++++++++++++++++++++-------------
{bin => scripts}/install.sh | 0
{bin => scripts}/reset_db.sh | 0
6 files changed, 58 insertions(+), 36 deletions(-)
rename {bin => scripts}/download.sh (68%)
mode change 100644 => 100755
rename {bin => scripts}/install.sh (100%)
rename {bin => scripts}/reset_db.sh (100%)
diff --git a/.gitignore b/.gitignore
index 61f2c67..2e0abd0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,6 @@
*.tar.gz
wordpress/
deploy/staging/env
+scripts/cv
+scripts/wp
+scripts/civix
diff --git a/Dockerfile b/Dockerfile
index 2dc6f41..144a4a4 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -12,19 +12,9 @@ RUN apt-get update \
USER root
RUN docker-php-ext-install intl pdo_mysql
-ADD https://download.civicrm.org/cv/cv.phar /usr/local/bin/cv
-ADD https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar /usr/local/bin/wp
-RUN chmod a+rx /usr/local/bin/cv /usr/local/bin/wp
+COPY --chmod=750 --chown=root:www-data --link scripts/* /usr/local/bin/
+ADD --link wordpress/wp-content/* /var/www/civi/wp-content/
WORKDIR /var/www/civi/
-COPY bin/*.sh /usr/local/bin/
-RUN chmod a+rx /usr/local/bin/*.sh
-
-RUN download.sh
-
-
-RUN chown www-data /var/www/civi/ /var/www/civi/wp-content/uploads/
-RUN find /var/www/ -type d |xargs chmod 755
-
USER www-data
diff --git a/Makefile b/Makefile
index 177faa6..0f60d5e 100644
--- a/Makefile
+++ b/Makefile
@@ -12,9 +12,21 @@ clean:
start:
${COMPOSE} up -d
-build:
+build: downloads
bash ./image.sh build
+downloads: scripts/cv scripts/civix scripts/wp
+ scripts/download.sh
+
+scripts/cv:
+ curl -LsS --output scripts/cv https://download.civicrm.org/cv/cv.phar
+
+scripts/wp:
+ curl -LsS --output scripts/wp https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
+
+scripts/civix:
+ curl -LsS --output scripts/civix https://download.civicrm.org/civix/civix.phar
+
build-dev: build
reset-db:
diff --git a/bin/download.sh b/scripts/download.sh
old mode 100644
new mode 100755
similarity index 68%
rename from bin/download.sh
rename to scripts/download.sh
index 41af209..f1c1274
--- a/bin/download.sh
+++ b/scripts/download.sh
@@ -1,45 +1,62 @@
#!/bin/bash
-set -xe
+set -e
version=5.48.0
+TMP_DIR=${TMP_DIR:-$PWD/tmp/}
+WP_BASE=${1:-$PWD/wordpress/}
+
function download_ext {
# work-around for timeout issues on lab.civicrm.org during download
- echo "download_ext $@"
name="$1"
url="$2"
- filename=$(mktemp)
+ if [ -d "$name" ]; then
+ echo "skip $name"
+ return
+ fi
- curl -L --output $filename $url
- unzip -q $filename
+ filename=${TMP_DIR}$(basename $url)
+
+ if [ ! -e $filename ]; then
+ echo "download_ext $filename $@"
+ curl -L --output $filename $url
+ fi
+
+ filetype=$(file --brief --mime $filename|cut -f1 -d';'|cut -f2 -d/)
+ case $filetype in
+ zip)
+ unzip -q $filename
+ ;;
+ gzip)
+ tar xf $filename
+ ;;
+ esac
dirname=$(find -maxdepth 1 -name "${name}*" -type d)
+ [ -z "$dirname" ] && return
dirname=$(basename $dirname)
[ "$dirname" = "$name" ] || mv -v $dirname $name
}
+mkdir -p $TMP_DIR
+mkdir -p ${WP_BASE}/wp-content/plugins
+mkdir -p ${WP_BASE}/wp-content/uploads/civicrm/ext
-mkdir -p /var/www/civi/wp-content/plugins && cd /var/www/civi/wp-content/plugins
-curl -L -o /tmp/civi.zip https://download.civicrm.org/civicrm-$version-wordpress.zip
-unzip /tmp/civi.zip -d .
-
-curl -L -o /tmp/l10n.tar.gz https://download.civicrm.org/civicrm-$version-l10n.tar.gz
-tar -xf /tmp/l10n.tar.gz -C ./civicrm
-
-curl -LsS https://download.civicrm.org/civix/civix.phar -o /usr/local/bin/civix
-chmod +x /usr/local/bin/civix
-
-mkdir -p /var/www/civi/wp-content/uploads/civicrm/ext && cd /var/www/civi/wp-content/uploads/civicrm/ext
-
+# clone BIJ1 specific extensions
git config --global pull.ff only
-# git clone --depth 1 https://code.bij1.org/bij1/crm-bij1migratie.git
-# git clone --depth 1 https://code.bij1.org/bij1/crm-bij1rules.git
-# git clone --depth 1 https://code.bij1.org/bij1/crm-bij1algemeen.git
-git clone --depth 1 https://lab.civicrm.org/partners/civicoop/bij1/bij1migratie.git
-git clone --depth 1 https://lab.civicrm.org/partners/civicoop/bij1/bij1rules.git
-git clone --depth 1 https://lab.civicrm.org/partners/civicoop/bij1/bij1algemeen.git
+# download all extensions
+cd $WP_BASE/wp-content/plugins
+download_ext civicrm https://download.civicrm.org/civicrm-$version-wordpress.zip
+
+cd $WP_BASE/wp-content/plugins/civicrm
+download_ext l10n https://download.civicrm.org/civicrm-$version-l10n.tar.gz
+
+cd ${WP_BASE}/wp-content/uploads/civicrm/ext
+for repo in bij1migratie bij1rules bij1algemeen; do
+ [ -e crm-${repo} ] || git clone --depth 1 https://code.bij1.org/bij1/crm-${repo}.git
+done
download_ext de.systopia.identitytracker https://github.com/systopia/de.systopia.identitytracker/releases/download/1.3/de.systopia.identitytracker-1.3.zip
download_ext org.project60.banking https://github.com/Project60/org.project60.banking/releases/download/0.7/org.project60.banking-0.7.zip
diff --git a/bin/install.sh b/scripts/install.sh
similarity index 100%
rename from bin/install.sh
rename to scripts/install.sh
diff --git a/bin/reset_db.sh b/scripts/reset_db.sh
similarity index 100%
rename from bin/reset_db.sh
rename to scripts/reset_db.sh