Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker BugFix #3346

Merged
merged 24 commits into from Jan 6, 2017
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
67 changes: 24 additions & 43 deletions Dockerfile
@@ -1,63 +1,44 @@
FROM phusion/baseimage:0.9.15
MAINTAINER Open Knowledge
# docker build . -t ckan && docker run -d -p 80:5000 --link db:db --link redis:redis --link solr:solr ckan

# Disable SSH
RUN rm -rf /etc/service/sshd /etc/my_init.d/00_regen_ssh_host_keys.sh
FROM debian:jessie
MAINTAINER Open Knowledge

ENV HOME /root
ENV CKAN_HOME /usr/lib/ckan/default
ENV CKAN_CONFIG /etc/ckan/default
ENV CKAN_DATA /var/lib/ckan

# Install required packages
RUN apt-get -q -y update && \
DEBIAN_FRONTEND=noninteractive apt-get -q -y install \
python-minimal \
python-dev \
RUN apt-get -q -y update && apt-get -q -y upgrade && DEBIAN_FRONTEND=noninteractive apt-get -q -y install \
python-dev \
python-pip \
python-virtualenv \
libevent-dev \
libpq-dev \
nginx-light \
apache2 \
libapache2-mod-wsgi \
postfix \
build-essential && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Install CKAN
RUN virtualenv $CKAN_HOME
git-core \
&& apt-get -q clean

# SetUp Virtual Environment CKAN
RUN mkdir -p $CKAN_HOME $CKAN_CONFIG $CKAN_DATA
RUN chown www-data:www-data $CKAN_DATA
RUN virtualenv $CKAN_HOME
RUN ln -s $CKAN_HOME/bin/pip /usr/local/bin/ckan-pip
RUN ln -s $CKAN_HOME/bin/paster /usr/local/bin/ckan-paster

# SetUp Requirements
ADD ./requirements.txt $CKAN_HOME/src/ckan/requirements.txt
RUN $CKAN_HOME/bin/pip install -r $CKAN_HOME/src/ckan/requirements.txt
RUN ckan-pip install --upgrade -r $CKAN_HOME/src/ckan/requirements.txt

# SetUp CKAN
ADD . $CKAN_HOME/src/ckan/
RUN $CKAN_HOME/bin/pip install -e $CKAN_HOME/src/ckan/
RUN ckan-pip install -e $CKAN_HOME/src/ckan/
RUN ln -s $CKAN_HOME/src/ckan/ckan/config/who.ini $CKAN_CONFIG/who.ini
ADD ./contrib/docker/apache.wsgi $CKAN_CONFIG/apache.wsgi

# Configure apache
ADD ./contrib/docker/apache.conf /etc/apache2/sites-available/ckan_default.conf
RUN echo "Listen 8080" > /etc/apache2/ports.conf
RUN a2ensite ckan_default
RUN a2dissite 000-default

# Configure nginx
ADD ./contrib/docker/nginx.conf /etc/nginx/nginx.conf
RUN mkdir /var/cache/nginx

# Configure postfix
ADD ./contrib/docker/main.cf /etc/postfix/main.cf

# Configure runit
ADD ./contrib/docker/my_init.d /etc/my_init.d
ADD ./contrib/docker/svc /etc/service
CMD ["/sbin/my_init"]
# SetUp EntryPoint
COPY ./contrib/docker/ckan-entrypoint.sh /
RUN chmod +x /ckan-entrypoint.sh
ENTRYPOINT ["/ckan-entrypoint.sh"]

# Volumes
VOLUME ["/etc/ckan/default"]
VOLUME ["/var/lib/ckan"]
EXPOSE 80
EXPOSE 5000

RUN rm -rf /tmp/* /var/tmp/*
CMD ["ckan-paster","serve","/etc/ckan/default/ckan.ini"]
26 changes: 26 additions & 0 deletions circle.yml
Expand Up @@ -14,6 +14,9 @@ machine:
node:
version: 0.10.33

services:
- docker

dependencies:

pre:
Expand All @@ -27,6 +30,19 @@ dependencies:
- pip install -r dev-requirements.txt
- python setup.py develop

# Docker
- if [[ -e ~/docker/postgresql.tar ]]; then docker load -i ~/docker/postgresql.tar; fi
- if [[ -e ~/docker/solr.tar ]]; then docker load -i ~/docker/solr.tar; fi
- if [[ -e ~/docker/ckan.tar ]]; then docker load -i ~/docker/ckan.tar; fi
- docker build --rm=false -t postgresql ./contrib/docker/postgresql/
- docker build --rm=false -t solr ./contrib/docker/solr/
- docker pull redis:latest
- docker build --rm=false -t ckan .
- mkdir -p ~/docker; docker save postgresql > ~/docker/postgresql.tar
- mkdir -p ~/docker; docker save solr > ~/docker/solr.tar
- mkdir -p ~/docker; docker save redis:latest > ~/docker/redis.tar
- mkdir -p ~/docker; docker save ckan > ~/docker/ckan.tar

post:
- "[ -e ~/nvm/v0.10.33/lib/node_modules/mocha-phantomjs ]
|| npm install -g mocha-phantomjs@3.5.0 phantomjs@~1.9.1"
Expand All @@ -37,6 +53,7 @@ dependencies:
- ~/nvm/v0.10.33/lib/node_modules/phantomjs
- ~/nvm/v0.10.33/bin/mocha-phantomjs
- ~/nvm/v0.10.33/bin/phantomjs
- "~/docker"

database:

Expand Down Expand Up @@ -65,3 +82,12 @@ test:
background: true
- sleep 5
- mocha-phantomjs http://localhost:5000/base/test/index.html

# Docker
- docker run -d --name db postgresql
- docker run -d --name solr solr
- docker run -d --name redis redis:latest
- docker run -d --name ckan -p 5001:5000 --link db:db --link redis:redis --link solr:solr ckan
- sleep 10
- curl --retry 10 --retry-delay 5 -v http://localhost:5001

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've added about 2 minutes to the all CI containers. Would you add your docker build and test code to https://github.com/ckan/ckan/blob/master/.circleci-matrix.yml so that it only runs in one container instead of all 4?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The circlce-matrix docs are more than a little lacking, let me know if you'd like more direction here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, i will try to make it ;)
But im not sure if i can cache the images in the matrix :(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe @amercader's suggestion of running the docker tests under travis is the best, then

86 changes: 86 additions & 0 deletions contrib/docker/ckan-entrypoint.sh
@@ -0,0 +1,86 @@
#!/bin/sh
set -eu

# URL for the primary database, in the format expected by sqlalchemy (required
# unless linked to a container called 'db')
: ${DATABASE_URL:=}
# URL for solr (required unless linked to a container called 'solr')
: ${SOLR_URL:=}
# URL for redis (required unless linked to a container called 'redis')
: ${REDIS_URL:=}
# Email to which errors should be sent (optional, default: none)
: ${ERROR_EMAIL:=}

CONFIG="${CKAN_CONFIG}/ckan.ini"

abort () {
echo "$@" >&2
exit 1
}

write_config () {
ckan-paster make-config ckan "$CONFIG"

ckan-paster --plugin=ckan config-tool "$CONFIG" -e \
"sqlalchemy.url = ${DATABASE_URL}" \
"solr_url = ${SOLR_URL}" \
"ckan.redis.url = ${REDIS_URL}" \
"ckan.storage_path = /var/lib/ckan" \
"email_to = disabled@example.com" \
"error_email_from = ckan@$(hostname -f)" \
"ckan.site_url = http://localhost:5000"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be easier to use the environment variables for these config options instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, i miss the ckan.storage_path. Thanks @wardi

Should I add also the other params as environment variables?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please just add the ones you need, making arbitrary config options override-able from environment vars makes me nervous.


if [ -n "$ERROR_EMAIL" ]; then
sed -i -e "s&^#email_to.*&email_to = ${ERROR_EMAIL}&" "$CONFIG"
fi
}

link_postgres_url () {
local user=$DB_ENV_POSTGRES_USER
local pass=$DB_ENV_POSTGRES_PASSWORD
local db=$DB_ENV_POSTGRES_DB
local host=$DB_PORT_5432_TCP_ADDR
local port=$DB_PORT_5432_TCP_PORT
echo "postgresql://${user}:${pass}@${host}:${port}/${db}"
}

link_solr_url () {
local host=$SOLR_PORT_8983_TCP_ADDR
local port=$SOLR_PORT_8983_TCP_PORT
echo "http://${host}:${port}/solr/ckan"
}

link_redis_url () {
local host=$REDIS_PORT_6379_TCP_ADDR
local port=$REDIS_PORT_6379_TCP_PORT
echo "redis://${host}:${port}/1"
}

# If we don't already have a config file, bootstrap
if [ ! -e "$CONFIG" ]; then

if [ -z "$DATABASE_URL" ]; then
if ! DATABASE_URL=$(link_postgres_url); then
abort "ERROR: no DATABASE_URL specified and linked container called 'db' was not found"
fi
fi

if [ -z "$SOLR_URL" ]; then
if ! SOLR_URL=$(link_solr_url); then
abort "ERROR: no SOLR_URL specified and linked container called 'solr' was not found"
fi
fi

if [ -z "$REDIS_URL" ]; then
if ! REDIS_URL=$(link_redis_url); then
abort "ERROR: no REDIS_URL specified and linked container called 'redis' was not found"
fi
fi

write_config

fi

ckan-paster --plugin=ckan db init -c "${CKAN_CONFIG}/ckan.ini"

exec "$@"
5 changes: 4 additions & 1 deletion contrib/docker/docker-cloud.yml
Expand Up @@ -3,9 +3,12 @@ ckan:
links:
- db
- solr
- redis
ports:
- "80:80"
- "80:5000"
db:
image: ckan/postgresql:latest
solr:
image: ckan/solr:latest
redis:
image: redis:latest
43 changes: 26 additions & 17 deletions contrib/docker/docker-compose.yml
@@ -1,19 +1,28 @@
version: '2'
services:
ckan:
container_name: ckan
image: ckan/ckan:latest
depends_on:
# docker-compose build && docker-compose up
ckan:
container_name: ckan
image: ckan/ckan:latest
links:
- db
- solr
links:
- db
- solr
ports:
- "80:80"
db:
container_name: db
image: ckan/postgresql:latest
solr:
container_name: solr
image: ckan/solr:latest
- redis
ports:
- "80:5000"

db:
container_name: db
image: ckan/postgresql:latest
ports:
- "5432:5432"

solr:
container_name: solr
image: ckan/solr:latest
ports:
- "8983:8983"

redis:
container_name: redis
image: redis:latest
ports:
- "6379:6379"
2 changes: 1 addition & 1 deletion contrib/docker/solr/Dockerfile
Expand Up @@ -13,7 +13,7 @@ RUN mkdir -p /opt/solr/server/solr/$SOLR_CORE/data

# Adding Files
ADD ./solrconfig.xml \
https://raw.githubusercontent.com/ckan/ckan/dev-v2.6/ckan/config/solr/schema.xml \
https://raw.githubusercontent.com/ckan/ckan/master/ckan/config/solr/schema.xml \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this will be need to be changed to the relevant tag as part of the release process? Also more generically I guess the release process will need to include a Docker step to build and tag the images and upload them to Docker Hub.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amercader For now i don't know how to make the diference between the schemas.
The best aproach is to set a managed schema. I will work on it ;)

https://raw.githubusercontent.com/apache/lucene-solr/releases/lucene-solr/6.0.0/solr/server/solr/configsets/basic_configs/conf/currency.xml \
https://raw.githubusercontent.com/apache/lucene-solr/releases/lucene-solr/6.0.0/solr/server/solr/configsets/basic_configs/conf/synonyms.txt \
https://raw.githubusercontent.com/apache/lucene-solr/releases/lucene-solr/6.0.0/solr/server/solr/configsets/basic_configs/conf/stopwords.txt \
Expand Down