docker-ckan/rootfs/Dockerfile

168 lines
4.7 KiB
Docker
Raw Normal View History

2017-10-18 21:21:29 +02:00
##################
### Build CKAN ###
##################
FROM alpine:3.12 as ckanbuild
2017-10-18 21:21:29 +02:00
# Set CKAN version to build
ENV GIT_URL=https://github.com/ckan/ckan.git
ENV GIT_BRANCH=ckan-2.8.4
2017-10-18 21:21:29 +02:00
# Set src dirs
ENV SRC_DIR=/srv/app/src
ENV PIP_SRC=${SRC_DIR}
WORKDIR ${SRC_DIR}
# Packages to build CKAN requirements and plugins
RUN apk add --no-cache \
git \
curl \
python2 \
2017-10-18 21:21:29 +02:00
postgresql-dev \
linux-headers \
gcc \
make \
g++ \
autoconf \
automake \
libtool \
musl-dev \
pcre-dev \
pcre \
python2-dev \
libffi-dev \
libxml2-dev \
libxslt-dev
2017-10-18 21:21:29 +02:00
# Create the src directory
RUN mkdir -p ${SRC_DIR}
# Install pip
RUN curl -o ${SRC_DIR}/get-pip.py https://bootstrap.pypa.io/get-pip.py && \
python ${SRC_DIR}/get-pip.py
# Fetch and build CKAN and requirements
RUN pip install -e git+${GIT_URL}@${GIT_BRANCH}#egg=ckan
RUN rm -rf /srv/app/src/ckan/.git
RUN pip wheel --wheel-dir=/wheels -r ckan/requirements.txt
RUN pip wheel --wheel-dir=/wheels uwsgi gevent
###########################
### Default-Extensions ####
###########################
FROM alpine:3.12 as extbuild
# Set src dirs
ENV SRC_DIR=/srv/app/src
ENV PIP_SRC=${SRC_DIR}
# List of default extensions
ENV DEFAULT_EXTENSIONS envvars s3filestore
# Locations and tags, please use specific tags or revisions
ENV ENVVARS_GIT_URL=https://github.com/okfn/ckanext-envvars
ENV ENVVARS_GIT_BRANCH=0.0.1
ENV S3FILESTORE_GIT_URL=https://github.com/keitaroinc/ckanext-s3filestore
ENV S3FILESTORE_GIT_BRANCH=efd5711
RUN apk add --no-cache \
git \
curl \
python2 \
python2-dev
# Create the src directory
RUN mkdir -p ${SRC_DIR}
# Install pip
RUN curl -o ${SRC_DIR}/get-pip.py https://bootstrap.pypa.io/get-pip.py && \
python ${SRC_DIR}/get-pip.py
# Fetch and build the default CKAN extensions
RUN pip wheel --wheel-dir=/wheels git+${ENVVARS_GIT_URL}@${ENVVARS_GIT_BRANCH}#egg=ckanext-envvars
RUN pip wheel --wheel-dir=/wheels git+${S3FILESTORE_GIT_URL}@${S3FILESTORE_GIT_BRANCH}#egg=ckanext-s3filestore
RUN pip wheel --wheel-dir=/wheels -r https://raw.githubusercontent.com/keitaroinc/ckanext-s3filestore/${S3FILESTORE_GIT_BRANCH}/requirements.txt
RUN curl -o /wheels/s3filestore.txt https://raw.githubusercontent.com/keitaroinc/ckanext-s3filestore/${S3FILESTORE_GIT_BRANCH}/requirements.txt
2017-10-18 21:21:29 +02:00
############
### MAIN ###
############
FROM alpine:3.12
2016-08-25 17:40:05 +02:00
MAINTAINER Keitaro Inc <info@keitaro.com>
2016-08-25 17:40:05 +02:00
ENV APP_DIR=/srv/app
2016-10-26 09:28:54 +02:00
ENV SRC_DIR=/srv/app/src
ENV PIP_SRC=${SRC_DIR}
2016-08-25 23:04:32 +02:00
ENV CKAN_SITE_URL=http://localhost:5000
ENV CKAN__PLUGINS envvars s3filestore image_view text_view recline_view datastore datapusher
2016-08-25 17:40:05 +02:00
WORKDIR ${APP_DIR}
# Install necessary packages to run CKAN
RUN apk add --no-cache git \
bash \
2016-10-26 09:28:54 +02:00
gettext \
2017-10-18 21:21:29 +02:00
curl \
2016-10-26 09:28:54 +02:00
postgresql-client \
python2 \
libmagic \
pcre \
libxslt \
libxml2 \
tzdata \
apache2-utils && \
# Create SRC_DIR
mkdir -p ${SRC_DIR}
2017-10-18 21:21:29 +02:00
# Install pip
RUN curl -o ${SRC_DIR}/get-pip.py https://bootstrap.pypa.io/get-pip.py && \
python ${SRC_DIR}/get-pip.py
# Get artifacts from build stages
COPY --from=ckanbuild /wheels /srv/app/wheels
COPY --from=extbuild /wheels /srv/app/ext_wheels
2017-10-18 21:21:29 +02:00
COPY --from=ckanbuild /srv/app/src/ckan /srv/app/src/ckan
# Additional install steps for build stages artifacts
RUN pip install --no-index --find-links=/srv/app/wheels uwsgi gevent
# Create a local user and group to run the app
RUN addgroup -g 92 -S ckan && \
adduser -u 92 -h /srv/app -H -D -S -G ckan ckan
# Install CKAN
2017-10-18 21:21:29 +02:00
RUN pip install -e /srv/app/src/ckan && \
2016-10-26 09:28:54 +02:00
cd ${SRC_DIR}/ckan && \
2016-08-25 17:40:05 +02:00
cp who.ini ${APP_DIR} && \
2017-10-18 21:21:29 +02:00
pip install --no-index --find-links=/srv/app/wheels -r requirements.txt && \
# Install default CKAN extensions
pip install --no-index --find-links=/srv/app/ext_wheels ckanext-envvars ckanext-s3filestore && \
pip install --no-index --find-links=/srv/app/ext_wheels -r /srv/app/ext_wheels/s3filestore.txt && \
2016-08-25 22:05:30 +02:00
# Create and update CKAN config
# Set timezone
echo "UTC" > /etc/timezone && \
# Generate CKAN config
paster --plugin=ckan make-config ckan ${APP_DIR}/production.ini && \
paster --plugin=ckan config-tool ${APP_DIR}/production.ini "ckan.plugins = ${CKAN__PLUGINS}" && \
# Change ownership to app user
2018-07-30 14:20:13 +02:00
chown -R ckan:ckan /srv/app
# Remove wheels
RUN rm -rf /srv/app/wheels /srv/app/ext_wheels
2016-08-25 17:40:05 +02:00
# Copy necessary scripts
COPY setup/app ${APP_DIR}
# Create entrypoint directory for children image scripts
2019-02-19 11:02:17 +01:00
ONBUILD RUN mkdir docker-entrypoint.d
2016-08-25 22:13:02 +02:00
EXPOSE 5000
2016-08-25 17:40:05 +02:00
2017-04-07 09:34:40 +02:00
HEALTHCHECK --interval=10s --timeout=5s --retries=5 CMD curl --fail http://localhost:5000/api/3/action/status_show || exit 1
USER ckan
2016-08-25 22:05:30 +02:00
CMD ["/srv/app/start_ckan.sh"]