From 3b6c8471febb8674c2d918d374a96be6351c326d Mon Sep 17 00:00:00 2001 From: Disassembler Date: Tue, 19 Dec 2017 22:17:12 +0100 Subject: [PATCH] Alpinize CKAN --- ckan.sh | 48 +++++++++---------- ckan/etc/init.d/ckan | 16 +++++++ ckan/etc/nginx/apps/ckan | 9 ++++ ckan/etc/nginx/conf.d/ckan.conf | 11 +++++ ckan/etc/nginx/sites-available/ckan | 29 ----------- .../uwsgi/apps-available/ckan-datapusher.ini | 11 ----- ckan/lib/systemd/system/ckan.service | 11 ----- 7 files changed, 60 insertions(+), 75 deletions(-) create mode 100644 ckan/etc/init.d/ckan create mode 100644 ckan/etc/nginx/apps/ckan create mode 100644 ckan/etc/nginx/conf.d/ckan.conf delete mode 100644 ckan/etc/nginx/sites-available/ckan delete mode 100644 ckan/etc/uwsgi/apps-available/ckan-datapusher.ini delete mode 100644 ckan/lib/systemd/system/ckan.service diff --git a/ckan.sh b/ckan.sh index 93152a6..ad2ee66 100755 --- a/ckan.sh +++ b/ckan.sh @@ -1,7 +1,14 @@ #!/bin/bash -SOURCE_DIR=$(realpath $(dirname "${0}"))/ckan -# Requires: Postgres, Redis, Solr, CKAN-Datapusher +SOURCE_DIR=$(realpath $(dirname "${0}")) + +# Check and install linked Docker containers +docker images | grep -q postgres || ${SOURCE_DIR}/postgres.sh +docker images | grep -q redis || ${SOURCE_DIR}/redis.sh +docker images | grep -q solr || ${SOURCE_DIR}/solr.sh +docker images | grep -q ckan-datastore || ${SOURCE_DIR}/ckan-datastore.sh + +SOURCE_DIR=${SOURCE_DIR}/ckan # Build Docker container docker build -t ckan ${SOURCE_DIR} @@ -12,16 +19,17 @@ export CKAN_DS_PWD=$(head -c 18 /dev/urandom | base64) envsubst <${SOURCE_DIR}/createdb.sql | docker exec -i postgres psql # Configure CKAN Solr core -docker exec solr solr create -c ckan +docker exec solr solr create -p 8983 -c ckan cp ${SOURCE_DIR}/srv/solr/data/ckan/conf/schema.xml /srv/solr/data/ckan/conf/schema.xml cp ${SOURCE_DIR}/srv/solr/data/ckan/conf/solrconfig.xml /srv/solr/data/ckan/conf/solrconfig.xml chown 8983:8983 /srv/solr/data/ckan/conf/schema.xml -systemctl restart solr +service solr restart # Configure CKAN export CKAN_SECRET=$(head -c 18 /dev/urandom | base64) export CKAN_UUID=$(cat /proc/sys/kernel/random/uuid) -mkdir -p /srv/ckan/{conf,data} +mkdir -p /srv/ckan/conf +mkdir /srv/ckan/data envsubst <${SOURCE_DIR}/srv/ckan/conf/ckan.ini >/srv/ckan/conf/ckan.ini cp ${SOURCE_DIR}/srv/ckan/conf/who.ini /srv/ckan/conf/who.ini chown -R 8003:8003 /srv/ckan/data @@ -43,28 +51,20 @@ export CKAN_ADMIN_EMAIL="admin@example.com" envsubst <${SOURCE_DIR}/adminpwd.sql | docker exec -i postgres psql ckan # Configure CKAN service -cp ${SOURCE_DIR}/lib/systemd/system/ckan.service /lib/systemd/system/ckan.service -systemctl daemon-reload -systemctl enable ckan -systemctl start ckan +cp ${SOURCE_DIR}/etc/init.d/ckan /etc/init.d/ckan +rc-update add ckan boot +service ckan start +# Create nginx app definition +cp ${SOURCE_DIR}/etc/nginx/apps/ckan /etc/nginx/apps/ckan +cp ${SOURCE_DIR}/etc/nginx/conf.d/ckan.conf /etc/nginx/conf.d/ckan.conf - -# Create uwsgi and nginx app definition -cp ${SOURCE_DIR}/etc/uwsgi/apps-available/ckan.ini /etc/uwsgi/apps-available/ckan.ini -cp ${SOURCE_DIR}/etc/uwsgi/apps-available/ckan-datapusher.ini /etc/uwsgi/apps-available/ckan-datapusher.ini -ln -s /etc/uwsgi/apps-available/ckan.ini /etc/uwsgi/apps-enabled/ckan.ini -ln -s /etc/uwsgi/apps-available/ckan-datapusher.ini /etc/uwsgi/apps-enabled/ckan-datapusher.ini -cp ${SOURCE_DIR}/etc/nginx/sites-available/ckan /etc/nginx/sites-available/ckan -ln -s /etc/nginx/sites-available/ckan /etc/nginx/sites-enabled/ckan - -# Restart services -systemctl restart uwsgi -systemctl restart nginx +# Reload nginx configuration +service nginx reload # Install cron job -cp ${SOURCE_DIR}/srv/ckan/cron-pageviews.sh /srv/ckan/cron-pageviews.sh -cp ${SOURCE_DIR}/etc/cron.d/ckan /etc/cron.d/ckan +#cp ${SOURCE_DIR}/srv/ckan/cron-pageviews.sh /srv/ckan/cron-pageviews.sh +#cp ${SOURCE_DIR}/etc/cron.d/ckan /etc/cron.d/ckan # Add portal application definition -portal-app-manager ckan "https://{host}:8003/" "${CKAN_ADMIN_USER}" "${CKAN_ADMIN_PWD}" +portal-app-manager ckan "https://{host}:8403/" "${CKAN_ADMIN_USER}" "${CKAN_ADMIN_PWD}" diff --git a/ckan/etc/init.d/ckan b/ckan/etc/init.d/ckan new file mode 100644 index 0000000..8d94797 --- /dev/null +++ b/ckan/etc/init.d/ckan @@ -0,0 +1,16 @@ +#!/sbin/openrc-run + +description="CKAN docker container" + +depend() { + need docker net postgres redis solr + use dns logger netmount +} + +start() { + /usr/bin/docker run -d --rm --name ckan --link=postgres --link=redis --link=solr -p 127.0.0.1:9003:8003 -v /srv/ckan/conf:/etc/ckan -v /srv/ckan/data:/srv/ckan/storage ckan +} + +stop() { + /usr/bin/docker stop ckan +} diff --git a/ckan/etc/nginx/apps/ckan b/ckan/etc/nginx/apps/ckan new file mode 100644 index 0000000..020ee92 --- /dev/null +++ b/ckan/etc/nginx/apps/ckan @@ -0,0 +1,9 @@ +access_log /var/log/nginx/ckan.access.log; +error_log /var/log/nginx/ckan.error.log; + +location / { + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Forwarded-Host $host:$server_port; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_pass http://127.0.0.1:9003; +} diff --git a/ckan/etc/nginx/conf.d/ckan.conf b/ckan/etc/nginx/conf.d/ckan.conf new file mode 100644 index 0000000..2aaf6dc --- /dev/null +++ b/ckan/etc/nginx/conf.d/ckan.conf @@ -0,0 +1,11 @@ +server { + listen 8003; + listen [::]:8003; + include apps/ckan; +} + +server { + listen 8403 ssl http2; + listen [::]:8403 ssl http2; + include apps/ckan; +} diff --git a/ckan/etc/nginx/sites-available/ckan b/ckan/etc/nginx/sites-available/ckan deleted file mode 100644 index 5563040..0000000 --- a/ckan/etc/nginx/sites-available/ckan +++ /dev/null @@ -1,29 +0,0 @@ -server { - listen 8003 ssl http2; - listen [::]:8003 ssl http2; - - access_log /var/log/nginx/ckan.access.log; - error_log /var/log/nginx/ckan.error.log; - - location / { - uwsgi_pass unix:///run/uwsgi/app/ckan/socket; - include uwsgi_params; - uwsgi_param SCRIPT_NAME ''; - uwsgi_param UWSGI_SCHEME $scheme; - } -} - -server { - listen 127.0.0.1:8098; - listen [::1]:8098; - - access_log /var/log/nginx/ckan-datapusher.access.log; - error_log /var/log/nginx/ckan-datapusher.error.log; - - location / { - uwsgi_pass unix:///run/uwsgi/app/ckan-datapusher/socket; - include uwsgi_params; - uwsgi_param SCRIPT_NAME ''; - uwsgi_param UWSGI_SCHEME $scheme; - } -} diff --git a/ckan/etc/uwsgi/apps-available/ckan-datapusher.ini b/ckan/etc/uwsgi/apps-available/ckan-datapusher.ini deleted file mode 100644 index 47ec146..0000000 --- a/ckan/etc/uwsgi/apps-available/ckan-datapusher.ini +++ /dev/null @@ -1,11 +0,0 @@ -[uwsgi] -uid = ckan -gid = ckan -chown-socket = www-data:www-data -chdir = /srv/ckan-datapusher -home = /srv/ckan-datapusher -master = false -workers = 1 -disable-logging = true -file = /etc/ckan/datapusher.wsgi -enable-threads = true diff --git a/ckan/lib/systemd/system/ckan.service b/ckan/lib/systemd/system/ckan.service deleted file mode 100644 index 35a1b3d..0000000 --- a/ckan/lib/systemd/system/ckan.service +++ /dev/null @@ -1,11 +0,0 @@ -[Unit] -Description=CKAN Docker container -After=network.target - -[Service] -Type=simple -ExecStart=/usr/bin/docker run --rm --name ckan --link=postgres --link=redis --link=solr -p 127.0.0.1:9003:8003 -v /srv/ckan/conf:/etc/ckan -v /srv/ckan/data:/srv/ckan/storage ckan -ExecStop=/usr/bin/docker stop ckan - -[Install] -WantedBy=multi-user.target