<commit_before>#
# CLIFF annotator service
#

FROM dockermediacloud/java-base:latest

# Download and extract CLAVIN's geonames index
RUN \
    mkdir -p /etc/cliff2/IndexDirectory/ && \
    curl -L "https://github.com/berkmancenter/mediacloud-clavin-build-geonames-index/releases/download/2019-09-06/IndexDirectory.tar.gz" \
        > /var/tmp/clavin-geonames-index.tar.gz && \
    tar -zxf /var/tmp/clavin-geonames-index.tar.gz -C /etc/cliff2/IndexDirectory/ --strip 1 && \
    rm /var/tmp/clavin-geonames-index.tar.gz && \
    true

# Install Maven for building CLIFF
# (can't use APT because we didn't install Java through it)
RUN \
    mkdir -p /usr/lib/maven/ && \
    curl -L "http://mirror.cogentco.com/pub/apache/maven/maven-3/3.6.2/binaries/apache-maven-3.6.2-bin.tar.gz" \
        > /var/tmp/maven.tar.gz && \
    tar -zxf /var/tmp/maven.tar.gz -C /usr/lib/maven/ --strip 1 && \
    rm /var/tmp/maven.tar.gz && \
    true
ENV PATH="/usr/lib/maven/bin:${PATH}"

# Install Tomcat 7
RUN \
    mkdir -p /usr/lib/tomcat7/ && \
    curl -L "http://mirror.cogentco.com/pub/apache/tomcat/tomcat-7/v7.0.96/bin/apache-tomcat-7.0.96.tar.gz" \
        > /var/tmp/tomcat7.tar.gz && \
    tar -zxf /var/tmp/tomcat7.tar.gz -C /usr/lib/tomcat7/ --strip 1 && \
    rm /var/tmp/tomcat7.tar.gz && \
    true
ENV PATH="/usr/lib/tomcat7/bin:${PATH}"

# Copy source
RUN mkdir -p /usr/src/
COPY src/ /usr/src/

# Build CLIFF
RUN \
    #
    # Test if submodules were checked out
    if [ ! -f /usr/src/CLIFF/LICENSE ]; then \
        echo && \
        echo "Git submodules haven't been checked out, please run:" && \
        echo && \
        echo "    git submodule update --init --recursive" && \
        echo && \
        echo "and then rebuild this container." && \
        echo && \
        exit 1; \
    fi && \
    #
    # Test if the builder machine has enough RAM
    if [ $(/container_memory_limit.sh) -le 3900 ]; then \
        echo && \
        echo "The builder machine needs at least 4 GB of RAM to run CLIFF" && \
        echo "annotator tests. Please increase RAM available to Docker or" && \
        echo "try rebuilding on a bigger machine." && \
        echo && \
        exit 1; \
    fi && \
    #
    # Build CLIFF
    cd /usr/src/CLIFF/ && \
    mvn package && \
    #
    # Copy exploded WAR to Tomcat 7's webroot
    mv webapp/target/cliff-2.6.0/ /usr/lib/tomcat7/webapps/cliff/ && \
    #
    # Cleanup
    mvn clean && \
    rm -rf ~/.m2/ && \
    true

# Configure Tomcat 7
RUN \
    #
    # Copy configuration
    mv /usr/src/tomcat7/conf/logging.properties /usr/lib/tomcat7/conf/logging.properties && \
    mv /usr/src/tomcat7/conf/server.xml /usr/lib/tomcat7/conf/server.xml && \
    rm -rf /usr/src/tomcat7/ && \
    #
    # No secrets in configuration
    chmod 644 /usr/lib/tomcat7/conf/* && \
    #
    # Some extra directories that seem to be needed
    mkdir -p /usr/lib/tomcat7/conf/Catalina/localhost/ && \
    chown -R www-data:www-data /usr/lib/tomcat7/conf/Catalina/localhost/ && \
    mkdir -p /usr/lib/tomcat7/work/Catalina/localhost/ && \
    chown -R www-data:www-data /usr/lib/tomcat7/work/Catalina/localhost/ && \
    true

# Expose Tomcat 7's port
EXPOSE 8080

# Change to non-privileged user
USER www-data

# Annotator requires some more RAM
ENV JAVA_OPTS "-Xmx4096m"

# Run Tomcat 7
CMD ["catalina.sh", "run"]
<commit_msg>Use more stable mirrors for Maven and Tomcat<commit_after>#
# CLIFF annotator service
#

FROM dockermediacloud/java-base:latest

# Download and extract CLAVIN's geonames index
RUN \
    mkdir -p /etc/cliff2/IndexDirectory/ && \
    curl -L "https://github.com/berkmancenter/mediacloud-clavin-build-geonames-index/releases/download/2019-09-06/IndexDirectory.tar.gz" \
        > /var/tmp/clavin-geonames-index.tar.gz && \
    tar -zxf /var/tmp/clavin-geonames-index.tar.gz -C /etc/cliff2/IndexDirectory/ --strip 1 && \
    rm /var/tmp/clavin-geonames-index.tar.gz && \
    true

# Install Maven for building CLIFF
# (can't use APT because we didn't install Java through it)
RUN \
    mkdir -p /usr/lib/maven/ && \
    curl -L "https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.2/apache-maven-3.6.2-bin.tar.gz" \
        > /var/tmp/maven.tar.gz && \
    tar -zxf /var/tmp/maven.tar.gz -C /usr/lib/maven/ --strip 1 && \
    rm /var/tmp/maven.tar.gz && \
    true
ENV PATH="/usr/lib/maven/bin:${PATH}"

# Install Tomcat 7
RUN \
    mkdir -p /usr/lib/tomcat7/ && \
    curl -L "https://archive.apache.org/dist/tomcat/tomcat-7/v7.0.96/bin/apache-tomcat-7.0.96.tar.gz" \
        > /var/tmp/tomcat7.tar.gz && \
    tar -zxf /var/tmp/tomcat7.tar.gz -C /usr/lib/tomcat7/ --strip 1 && \
    rm /var/tmp/tomcat7.tar.gz && \
    true
ENV PATH="/usr/lib/tomcat7/bin:${PATH}"

# Copy source
RUN mkdir -p /usr/src/
COPY src/ /usr/src/

# Build CLIFF
RUN \
    #
    # Test if submodules were checked out
    if [ ! -f /usr/src/CLIFF/LICENSE ]; then \
        echo && \
        echo "Git submodules haven't been checked out, please run:" && \
        echo && \
        echo "    git submodule update --init --recursive" && \
        echo && \
        echo "and then rebuild this container." && \
        echo && \
        exit 1; \
    fi && \
    #
    # Test if the builder machine has enough RAM
    if [ $(/container_memory_limit.sh) -le 3900 ]; then \
        echo && \
        echo "The builder machine needs at least 4 GB of RAM to run CLIFF" && \
        echo "annotator tests. Please increase RAM available to Docker or" && \
        echo "try rebuilding on a bigger machine." && \
        echo && \
        exit 1; \
    fi && \
    #
    # Build CLIFF
    cd /usr/src/CLIFF/ && \
    mvn package && \
    #
    # Copy exploded WAR to Tomcat 7's webroot
    mv webapp/target/cliff-2.6.0/ /usr/lib/tomcat7/webapps/cliff/ && \
    #
    # Cleanup
    mvn clean && \
    rm -rf ~/.m2/ && \
    true

# Configure Tomcat 7
RUN \
    #
    # Copy configuration
    mv /usr/src/tomcat7/conf/logging.properties /usr/lib/tomcat7/conf/logging.properties && \
    mv /usr/src/tomcat7/conf/server.xml /usr/lib/tomcat7/conf/server.xml && \
    rm -rf /usr/src/tomcat7/ && \
    #
    # No secrets in configuration
    chmod 644 /usr/lib/tomcat7/conf/* && \
    #
    # Some extra directories that seem to be needed
    mkdir -p /usr/lib/tomcat7/conf/Catalina/localhost/ && \
    chown -R www-data:www-data /usr/lib/tomcat7/conf/Catalina/localhost/ && \
    mkdir -p /usr/lib/tomcat7/work/Catalina/localhost/ && \
    chown -R www-data:www-data /usr/lib/tomcat7/work/Catalina/localhost/ && \
    true

# Expose Tomcat 7's port
EXPOSE 8080

# Change to non-privileged user
USER www-data

# Annotator requires some more RAM
ENV JAVA_OPTS "-Xmx4096m"

# Run Tomcat 7
CMD ["catalina.sh", "run"]

{'fraction_non_alphanumeric': 0.15231886205363757, 'fraction_numerical': 0.021632834493999113, 'mean_word_length': 2.090659340659341, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 10, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1339952', 'n_tokens_mistral': 2643, 'n_tokens_neox': 2471, 'n_words': 569}