Merge pull request #55 from luccioman/docker
Improve Docker image security, size and reliabilitypull/62/head
commit
c9ec0d0311
@ -1,46 +1,49 @@
|
|||||||
# Build a docker image from latest YaCy sources
|
# Build a docker image from latest YaCy sources
|
||||||
|
|
||||||
# Base image : latest stable Debian
|
# Base image : latest stable official jdk image from Docker (Debian based)
|
||||||
FROM debian:latest
|
FROM java:latest
|
||||||
|
|
||||||
# Install needed packages
|
# Install needed packages not in base image
|
||||||
RUN apt-get update && apt-get install -yq \
|
RUN apt-get update && apt-get install -yq curl
|
||||||
default-jdk \
|
|
||||||
default-jre-headless \
|
# trace java version
|
||||||
ant \
|
RUN java -version
|
||||||
git
|
|
||||||
|
|
||||||
# set current working dir
|
# set current working dir
|
||||||
WORKDIR /opt
|
WORKDIR /opt
|
||||||
|
|
||||||
# clone main YaCy git repository (we need to clone git repository to generate correct version when building from source)
|
# All in one step to reduce image size growth :
|
||||||
RUN git clone https://github.com/yacy/yacy_search_server.git
|
# - install ant and git packages
|
||||||
|
# - clone main YaCy git repository (we need to clone git repository to generate correct version when building from source)
|
||||||
|
# - Compile with ant
|
||||||
|
# - remove unnecessary and size consuming .git directory
|
||||||
|
# - remove ant and git packages
|
||||||
|
RUN apt-get update && \
|
||||||
|
apt-get install -yq ant git && \
|
||||||
|
git clone https://github.com/yacy/yacy_search_server.git && \
|
||||||
|
ant compile -f /opt/yacy_search_server/build.xml && \
|
||||||
|
rm -rf /opt/yacy_search_server/.git && \
|
||||||
|
apt-get purge -yq --auto-remove ant git && \
|
||||||
|
apt-get clean
|
||||||
|
|
||||||
# trace content of source directory
|
|
||||||
RUN ls -la /opt/yacy_search_server
|
|
||||||
|
|
||||||
# set current working dir
|
|
||||||
WORKDIR /opt/yacy_search_server
|
|
||||||
|
|
||||||
# Compile with ant
|
|
||||||
RUN ant compile
|
|
||||||
|
|
||||||
# Set initial admin password : "docker" (encoded with custom yacy md5 function net.yacy.cora.order.Digest.encodeMD5Hex())
|
# Set initial admin password : "docker" (encoded with custom yacy md5 function net.yacy.cora.order.Digest.encodeMD5Hex())
|
||||||
RUN sed -i "/adminAccountBase64MD5=/c\adminAccountBase64MD5=MD5:e672161ffdce91be4678605f4f4e6786" /opt/yacy_search_server/defaults/yacy.init
|
RUN sed -i "/adminAccountBase64MD5=/c\adminAccountBase64MD5=MD5:e672161ffdce91be4678605f4f4e6786" /opt/yacy_search_server/defaults/yacy.init
|
||||||
|
|
||||||
# make some cleaning to reduce image size
|
# Create user and group yacy : this user will be used to run YaCy main process
|
||||||
RUN rm -rf .git \
|
RUN adduser --system --group --no-create-home --disabled-password yacy
|
||||||
&& apt-get purge -yq --auto-remove \
|
|
||||||
default-jdk \
|
# Set ownership of yacy install directory to yacy user/group
|
||||||
ant \
|
RUN chown yacy:yacy -R /opt/yacy_search_server
|
||||||
git \
|
|
||||||
&& apt-get clean
|
|
||||||
|
|
||||||
# Expose port 8090
|
# Expose port 8090
|
||||||
EXPOSE 8090
|
EXPOSE 8090
|
||||||
|
|
||||||
# Set data volume : can be used to persist yacy data and configuration
|
# Set data volume : yacy data and configuration will persist aven after container stop or destruction
|
||||||
VOLUME ["/opt/yacy_search_server/DATA"]
|
VOLUME ["/opt/yacy_search_server/DATA"]
|
||||||
|
|
||||||
# Start yacy ind debug mode (-d) to display console logs and to wait for yacy process
|
# Next commands run as yacy as non-root user for improved security
|
||||||
|
USER yacy
|
||||||
|
|
||||||
|
# Start yacy in debug mode (-d) to display console logs and to wait for yacy process
|
||||||
CMD sh /opt/yacy_search_server/startYACY.sh -d
|
CMD sh /opt/yacy_search_server/startYACY.sh -d
|
||||||
|
@ -0,0 +1,81 @@
|
|||||||
|
# Build a docker image from latest YaCy sources on Alpine Linux
|
||||||
|
|
||||||
|
# Base image : latest stable official jdk image from Docker based on Alpine Linux
|
||||||
|
FROM java:alpine
|
||||||
|
|
||||||
|
# trace java version
|
||||||
|
RUN java -version
|
||||||
|
|
||||||
|
# Install needed packages not in base image
|
||||||
|
RUN apk update && \
|
||||||
|
apk add --no-cache curl
|
||||||
|
|
||||||
|
# set current working dir
|
||||||
|
WORKDIR /tmp
|
||||||
|
|
||||||
|
# --- Begin of apache ant install : from binary distribution because ant is not in alpine packages
|
||||||
|
|
||||||
|
# set ant version once in a environment variable
|
||||||
|
ENV ANT_VERSION 1.9.7
|
||||||
|
|
||||||
|
# All in one step to reduce image size growth :
|
||||||
|
# - add gnupg package
|
||||||
|
# - get ant binary file from a mirror and PGP file signature from main repository
|
||||||
|
# - import gpg keys from main repository and verify binary file signature
|
||||||
|
# - extract binary, make /opt directory, move extracted ant to /opt/ant
|
||||||
|
# - remove archive and gnupg package
|
||||||
|
RUN apk update && \
|
||||||
|
apk add --no-cache gnupg && \
|
||||||
|
curl -fSL http://www.eu.apache.org/dist//ant/binaries/apache-ant-${ANT_VERSION}-bin.tar.gz -o apache-ant-${ANT_VERSION}-bin.tar.gz && \
|
||||||
|
curl -fSL https://www.apache.org/dist/ant/binaries/apache-ant-${ANT_VERSION}-bin.tar.gz.asc -o apache-ant-${ANT_VERSION}-bin.tar.gz.asc && \
|
||||||
|
curl -fSL https://www.apache.org/dist/ant/KEYS | gpg --import && \
|
||||||
|
gpg --verify apache-ant-${ANT_VERSION}-bin.tar.gz.asc && \
|
||||||
|
tar xzf apache-ant-${ANT_VERSION}-bin.tar.gz && \
|
||||||
|
mkdir /opt && \
|
||||||
|
mv apache-ant-${ANT_VERSION} /opt/ant && \
|
||||||
|
rm -f apache-ant-${ANT_VERSION}-bin.tar.gz && \
|
||||||
|
apk del gnupg
|
||||||
|
|
||||||
|
# set ant required environment variables
|
||||||
|
ENV ANT_HOME /opt/ant
|
||||||
|
ENV PATH ${PATH}:/opt/ant/bin
|
||||||
|
|
||||||
|
# --- End of apache ant install
|
||||||
|
|
||||||
|
# set current working dir
|
||||||
|
WORKDIR /opt
|
||||||
|
|
||||||
|
# All in one step to reduce image size growth :
|
||||||
|
# - add git package
|
||||||
|
# - clone main YaCy git repository (we need to clone git repository to generate correct version when building from source)
|
||||||
|
# - compile with apache ant
|
||||||
|
# - remove unnecessary and size consuming .git directory
|
||||||
|
# - delete git package and ant binary install
|
||||||
|
RUN apk update && \
|
||||||
|
apk add --no-cache git && \
|
||||||
|
git clone https://github.com/yacy/yacy_search_server.git && \
|
||||||
|
ant compile -f /opt/yacy_search_server/build.xml && \
|
||||||
|
rm -rf /opt/yacy_search_server/.git && \
|
||||||
|
rm -rf /opt/ant && \
|
||||||
|
apk del git
|
||||||
|
|
||||||
|
# Set initial admin password : "docker" (encoded with custom yacy md5 function net.yacy.cora.order.Digest.encodeMD5Hex())
|
||||||
|
RUN sed -i "/adminAccountBase64MD5=/c\adminAccountBase64MD5=MD5:e672161ffdce91be4678605f4f4e6786" /opt/yacy_search_server/defaults/yacy.init
|
||||||
|
|
||||||
|
# Create user and group yacy : this user will be used to run YaCy main process
|
||||||
|
RUN addgroup yacy && adduser -S -G yacy -H -D yacy
|
||||||
|
|
||||||
|
# Set ownership of yacy install directory to yacy user/group
|
||||||
|
RUN chown yacy:yacy -R /opt/yacy_search_server
|
||||||
|
|
||||||
|
# Expose port 8090
|
||||||
|
EXPOSE 8090
|
||||||
|
|
||||||
|
# Set data volume : yacy data and configuration will persist aven after container stop or destruction
|
||||||
|
VOLUME ["/opt/yacy_search_server/DATA"]
|
||||||
|
|
||||||
|
# Next commands run as yacy as non-root user for improved security
|
||||||
|
USER yacy
|
||||||
|
|
||||||
|
# Start yacy in debug mode (-d) to display console logs and to wait for yacy process
|
||||||
|
CMD sh /opt/yacy_search_server/startYACY.sh -d
|
Loading…
Reference in new issue