docker-ckan/images/ckan/2.9/Dockerfile

204 lines
5.6 KiB
Docker
Raw Normal View History

2017-10-18 21:21:29 +02:00
##################
### Build CKAN ###
##################
2023-08-07 09:45:08 +02:00
FROM alpine:3.13.7 as ckanbuild
2017-10-18 21:21:29 +02:00
# Used by Github Actions to tag the image with
2023-12-21 11:11:39 +01:00
ENV IMAGE_TAG=2.9.10
2017-10-18 21:21:29 +02:00
# Set CKAN version to build
ENV GIT_URL=https://github.com/ckan/ckan.git
2023-12-21 11:11:39 +01:00
ENV GIT_BRANCH=ckan-2.9.10
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 \
2023-06-13 13:13:40 +02:00
python3 \
python3-dev \
git \
curl \
postgresql-dev \
linux-headers \
gcc \
make \
g++ \
autoconf \
automake \
libtool \
patch \
musl-dev \
pcre-dev \
pcre \
libffi-dev \
libxml2-dev \
libxslt-dev
# Link python to python3
RUN ln -s /usr/bin/python3 /usr/bin/python
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
# Downgrade setuptools so that CKAN requirements can be built
RUN pip install setuptools==44.1.0
2017-10-18 21:21:29 +02:00
# 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 cd ${SRC_DIR} && ls -lah ${SRC_DIR} && ash ${SRC_DIR}/apply_ckan_patches.sh
2017-10-18 21:21:29 +02:00
RUN rm -rf /srv/app/src/ckan/.git
2023-07-20 13:32:42 +02:00
# Create a constraint file that limits the Cython version to a compatible one, see https://github.com/yaml/pyyaml/issues/736
RUN echo 'Cython < 3.0' > /tmp/constraint.txt
RUN PIP_CONSTRAINT=/tmp/constraint.txt pip wheel --wheel-dir=/wheels PyYAML==5.4.1
2023-07-20 13:32:42 +02:00
# RUN pip-compile ckan/requirements.in
2017-10-18 21:21:29 +02:00
RUN pip wheel --wheel-dir=/wheels -r ckan/requirements.txt
RUN pip wheel --wheel-dir=/wheels uWSGI==2.0.20 gevent==21.12.0 greenlet==1.1.3
2017-10-18 21:21:29 +02:00
###########################
### Default-Extensions ####
###########################
2023-08-07 09:45:08 +02:00
FROM alpine:3.13.7 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 \
2023-06-13 13:13:40 +02:00
python3 \
python3-dev \
git \
curl
# Link python to python3
RUN ln -s /usr/bin/python3 /usr/bin/python
# 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
2017-10-18 21:21:29 +02:00
############
### MAIN ###
############
2023-08-07 09:45:08 +02:00
FROM alpine:3.13.7
2016-08-25 17:40:05 +02:00
2021-01-15 22:24:16 +01:00
LABEL maintainer="Keitaro Inc <info@keitaro.com>"
LABEL org.opencontainers.image.source https://github.com/keitaroinc/docker-ckan
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
2021-01-15 22:24:16 +01:00
ENV CKAN_DIR=${SRC_DIR}/ckan
ENV DATA_DIR=/srv/app/data
ENV PIP_SRC=${SRC_DIR}
2016-08-25 23:04:32 +02:00
ENV CKAN_SITE_URL=http://localhost:5000
ENV CKAN__PLUGINS envvars image_view text_view recline_view datastore datapusher
2016-08-25 17:40:05 +02:00
# Install necessary packages to run CKAN
RUN apk add --no-cache \
2023-06-13 13:13:40 +02:00
python3 \
bash \
git \
gettext \
curl \
postgresql-client \
libmagic \
pcre \
libxslt \
libxml2 \
tzdata \
apache2-utils && \
# Create SRC_DIR
mkdir -p ${SRC_DIR} && \
# Link python to python3
ln -s /usr/bin/python3 /usr/bin/python
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
2021-01-15 22:24:16 +01:00
COPY --from=ckanbuild /srv/app/src/ckan ${CKAN_DIR}
2017-10-18 21:21:29 +02:00
# Additional install steps for build stages artifacts
RUN pip install --no-index --find-links=/srv/app/wheels uWSGI==2.0.20 gevent==21.12.0
2017-10-18 21:21:29 +02:00
# 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
2021-01-15 22:24:16 +01:00
WORKDIR ${CKAN_DIR}
# Install CKAN
2017-10-18 21:21:29 +02:00
RUN pip install -e /srv/app/src/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 && \
2016-08-25 22:05:30 +02:00
# Create and update CKAN config
# Set timezone
echo "UTC" > /etc/timezone && \
# Generate CKAN config
ckan generate config ${APP_DIR}/production.ini && \
ckan config-tool ${APP_DIR}/production.ini "beaker.session.secret = " && \
# Configure plugins
ckan config-tool ${APP_DIR}/production.ini "ckan.plugins = ${CKAN__PLUGINS}" && \
# Create the data directory
mkdir ${DATA_DIR} && \
# Webassets can't be loaded from env variables at runtime, it needs to be in the config so that it is created
ckan config-tool ${APP_DIR}/production.ini "ckan.webassets.path = ${DATA_DIR}/webassets" && \
# Set the default level for extensions to INFO
ckan config-tool ${APP_DIR}/production.ini -s logger_ckanext -e level=INFO && \
# Change ownership to app user
2018-07-30 14:20:13 +02:00
chown -R ckan:ckan /srv/app
2023-10-16 14:14:31 +02:00
RUN pip install sqlalchemy==1.3.19
2018-07-30 14:20:13 +02:00
# 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}
2021-01-15 22:24:16 +01:00
WORKDIR ${APP_DIR}
# Create entrypoint directory for children image scripts
2019-02-19 11:02:17 +01:00
ONBUILD RUN mkdir docker-entrypoint.d
2020-09-20 00:45:46 +02:00
# Create afterinit directory for children image scripts
ONBUILD RUN mkdir docker-afterinit.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"]