197 lines
5.6 KiB
Docker
197 lines
5.6 KiB
Docker
##################
|
|
### Build CKAN ###
|
|
##################
|
|
FROM alpine:3.14.2 as ckanbuild
|
|
|
|
# Used by Github Actions to tag the image with
|
|
ENV IMAGE_TAG=2.7.12
|
|
|
|
# Set CKAN version to build
|
|
ENV GIT_URL=https://github.com/ckan/ckan.git
|
|
ENV GIT_BRANCH=ckan-2.7.12
|
|
|
|
# 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 \
|
|
postgresql-dev \
|
|
linux-headers \
|
|
gcc \
|
|
make \
|
|
g++ \
|
|
autoconf \
|
|
automake \
|
|
libtool \
|
|
patch \
|
|
musl-dev \
|
|
pcre-dev \
|
|
pcre \
|
|
python2-dev \
|
|
libffi-dev \
|
|
libxml2-dev \
|
|
libxslt-dev
|
|
|
|
# Install version 9.x of postgresql-dev so that CKAN requirements can be built
|
|
RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.6/main \
|
|
postgresql-dev~=9.6
|
|
|
|
# Create the src directory
|
|
RUN mkdir -p ${SRC_DIR}
|
|
|
|
# Install pip
|
|
RUN curl -o ${SRC_DIR}/get-pip.py https://bootstrap.pypa.io/pip/2.7/get-pip.py && \
|
|
python ${SRC_DIR}/get-pip.py 'pip==20.3.3'
|
|
|
|
# Fetch and build CKAN and requirements
|
|
RUN pip install -e git+${GIT_URL}@${GIT_BRANCH}#egg=ckan
|
|
# Copy patches and apply patches script
|
|
COPY ./patches ${SRC_DIR}/patches
|
|
COPY ./scripts/apply_ckan_patches.sh ${SRC_DIR}/apply_ckan_patches.sh
|
|
# Apply patches
|
|
RUN ${SRC_DIR}/apply_ckan_patches.sh
|
|
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==2.0.19.1 gevent==21.12.0 greenlet==1.1.3
|
|
|
|
|
|
###########################
|
|
### Default-Extensions ####
|
|
###########################
|
|
FROM alpine:3.14.2 as extbuild
|
|
|
|
# Set src dirs
|
|
ENV SRC_DIR=/srv/app/src
|
|
ENV PIP_SRC=${SRC_DIR}
|
|
|
|
# List of default extensions
|
|
ENV DEFAULT_EXTENSIONS envvars
|
|
|
|
# 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
|
|
|
|
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/pip/2.7/get-pip.py && \
|
|
python ${SRC_DIR}/get-pip.py 'pip==20.3.3'
|
|
|
|
# Fetch and build the default CKAN extensions
|
|
RUN pip wheel --wheel-dir=/wheels git+${ENVVARS_GIT_URL}@${ENVVARS_GIT_BRANCH}#egg=ckanext-envvars
|
|
|
|
############
|
|
### MAIN ###
|
|
############
|
|
FROM alpine:3.14.2
|
|
|
|
LABEL maintainer="Keitaro Inc <info@keitaro.com>"
|
|
LABEL org.opencontainers.image.source https://github.com/keitaroinc/docker-ckan
|
|
|
|
ENV APP_DIR=/srv/app
|
|
ENV SRC_DIR=/srv/app/src
|
|
ENV CKAN_DIR=${SRC_DIR}/ckan
|
|
ENV DATA_DIR=/srv/app/data
|
|
ENV PIP_SRC=${SRC_DIR}
|
|
ENV CKAN_SITE_URL=http://localhost:5000
|
|
ENV CKAN__PLUGINS envvars image_view text_view recline_view datastore datapusher
|
|
|
|
# Install necessary packages to run CKAN
|
|
RUN apk add --no-cache \
|
|
git \
|
|
bash \
|
|
git \
|
|
gettext \
|
|
curl \
|
|
python2 \
|
|
libmagic \
|
|
pcre \
|
|
libxslt \
|
|
libxml2 \
|
|
tzdata \
|
|
apache2-utils && \
|
|
# Install version 9.x of postgresql-client so that CKAN can run
|
|
apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.6/main \
|
|
postgresql-client~=9.6 && \
|
|
# Create SRC_DIR
|
|
mkdir -p ${SRC_DIR}
|
|
|
|
# Install pip
|
|
RUN curl -o ${SRC_DIR}/get-pip.py https://bootstrap.pypa.io/pip/2.7/get-pip.py && \
|
|
python ${SRC_DIR}/get-pip.py 'pip==20.3.3'
|
|
|
|
# Get artifacts from build stages
|
|
COPY --from=ckanbuild /wheels /srv/app/wheels
|
|
COPY --from=extbuild /wheels /srv/app/ext_wheels
|
|
COPY --from=ckanbuild /srv/app/src/ckan ${CKAN_DIR}
|
|
|
|
# Additional install steps for build stages artifacts
|
|
RUN pip install --no-index --find-links=/srv/app/wheels uwsgi==2.0.19.1 gevent==21.12.0
|
|
|
|
# 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
|
|
|
|
WORKDIR ${CKAN_DIR}
|
|
|
|
# Install CKAN
|
|
RUN pip install -e /srv/app/src/ckan && \
|
|
cp who.ini ${APP_DIR} && \
|
|
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 && \
|
|
# 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 "beaker.session.secret = " && \
|
|
paster --plugin=ckan config-tool ${APP_DIR}/production.ini "ckan.plugins = ${CKAN__PLUGINS}" && \
|
|
# Set the default level for extensions to INFO
|
|
paster --plugin=ckan config-tool ${APP_DIR}/production.ini -s logger_ckanext -e level=INFO && \
|
|
# Create the data directory
|
|
mkdir ${DATA_DIR} && \
|
|
# Change ownership to app user
|
|
chown -R ckan:ckan /srv/app
|
|
|
|
# Remove wheels
|
|
RUN rm -rf /srv/app/wheels /srv/app/ext_wheels
|
|
|
|
# Install python2 secrets for generating sessions
|
|
RUN pip install python2-secrets
|
|
|
|
# Copy necessary scripts
|
|
COPY setup/app ${APP_DIR}
|
|
|
|
WORKDIR ${APP_DIR}
|
|
|
|
# Copy the alias script for paster to be ckan so it's compatible with 2.9
|
|
COPY setup/bin/ckan /usr/bin/ckan
|
|
|
|
# Create entrypoint directory for children image scripts
|
|
ONBUILD RUN mkdir docker-entrypoint.d
|
|
|
|
# Create afterinit directory for children image scripts
|
|
ONBUILD RUN mkdir docker-afterinit.d
|
|
|
|
EXPOSE 5000
|
|
|
|
HEALTHCHECK --interval=10s --timeout=5s --retries=5 CMD curl --fail http://localhost:5000/api/3/action/status_show || exit 1
|
|
|
|
USER ckan
|
|
|
|
CMD ["/srv/app/start_ckan.sh"]
|