Skip to content
This repository has been archived by the owner on Nov 4, 2022. It is now read-only.

Commit

Permalink
add docker
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylong committed Apr 13, 2019
1 parent e901143 commit 9a8ff3d
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 28 deletions.
33 changes: 27 additions & 6 deletions Dockerfile
@@ -1,22 +1,43 @@
FROM httpd:alpine

MAINTAINER Jeremy Long <jeremy.long@gmail.com>
ARG BUILD_DATE
ARG BUILD_VERSION

# Labels.
LABEL maintainer="jeremy.long@gmail.com"
LABEL name="springett/nvdmirror"
LABEL version=$BUILD_VERSION
LABEL org.label-schema.schema-version="1.0"
LABEL org.label-schema.build-date=$BUILD_DATE
LABEL org.label-schema.name="springett/nvdmirror"
LABEL org.label-schema.description="NIST Data Mirror"
LABEL org.label-schema.url="https://github.com/stevespringett/nist-data-mirror"
LABEL org.label-schema.vcs-url="https://github.com/ballerinalang/container-support"
LABEL org.label-schema.vendor="springett"
LABEL org.label-schema.version=$BUILD_VERSION
LABEL org.label-schema.docker.cmd="docker run -dit --name mirror -p 80:80 --mount type=bind,source=\"$(pwd)\"/target/docs/,target=/usr/local/apache2/htdocs springett/nvdmirror"

ENV user=mirror

RUN apk update && \
apk add --no-cache openjdk8 dcron nano && \
apk add --no-cache openjdk8-jre dcron nss && \
mkdir -p /var/log/cron && \
mkdir -m 0644 -p /var/spool/cron/crontabs && \
touch /var/log/cron.log && \
mkdir -m 0644 -p /etc/cron.d && \
mkdir -p /var/spool/cron/crontabs && \
mkdir /tmp/nvd && \
mkdir /usr/local/apache2/htdocs/backup && \
adduser -D ${user} && \
touch /var/log/cron.log && \
rm -rf /var/lib/apt/lists/* /tmp/*

RUN echo "Include conf/mirror.conf"
COPY /src/docker/scripts/* /
COPY /src/docker/crontab/* /etc/cron.d/
COPY /src/docker/crontab/* /var/spool/cron/crontabs/mirror
COPY /src/docker/conf/mirror.conf /usr/local/apache2/conf
COPY /target/nist-data-mirror.jar /usr/local/bin/

EXPOSE 80/tcp

#USER ${user}

ENTRYPOINT ["/entry.sh"]
CMD ["/cmd.sh"]
3 changes: 3 additions & 0 deletions docker-build.sh
@@ -0,0 +1,3 @@
#!/bin/sh

docker build --no-cache=true --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') -t springett/nvdmirror .
8 changes: 8 additions & 0 deletions docker-run.sh
@@ -0,0 +1,8 @@
#!/bin/sh

mkdir target/docs
docker run -dit \
--name mirror \
-p 80:80 \
--mount type=bind,source="$(pwd)"/target/docs/,target=/usr/local/apache2/htdocs \
springett/nvdmirror
4 changes: 4 additions & 0 deletions docker-shell.sh
@@ -0,0 +1,4 @@
#!/bin/sh

#id=${docker ps -aqf 'name=mirror'}
docker exec -it mirror /bin/bash
48 changes: 47 additions & 1 deletion pom.xml
Expand Up @@ -24,7 +24,7 @@
</licenses>

<properties>
<maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
<maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ss'Z'</maven.build.timestamp.format>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -35,6 +35,7 @@
<maven.source.plugin.version>3.0.1</maven.source.plugin.version>
<maven.jar.plugin.version>3.0.2</maven.jar.plugin.version>
<maven.github.release.plugin.version>1.2.0</maven.github.release.plugin.version>
<dockerfile.maven.plugin>1.4.9</dockerfile.maven.plugin>
</properties>

<developers>
Expand Down Expand Up @@ -137,6 +138,51 @@
</build>

<profiles>
<profile>
<id>docker</id>
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>docker</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>${dockerfile.maven.plugin}</version>
<executions>
<execution>
<id>build</id>
<goals>
<goal>build</goal>
</goals>
<configuration>
<repository>springett/nvdmirror</repository>
<tag>${project.version}</tag>
<buildArgs>
<BUILD_DATE>${timestamp}</BUILD_DATE>
<BUILD_VERSION>${project.version}</BUILD_VERSION>
</buildArgs>
</configuration>
</execution>
<execution>
<id>tag</id>
<goals>
<goal>tag</goal>
</goals>
<configuration>
<repository>springett/nvdmirror</repository>
<tag>latest</tag>
</configuration>
</execution>
</executions>

</plugin>
</plugins>
</build>
</profile>
<profile>
<id>release</id>
<activation>
Expand Down
1 change: 1 addition & 0 deletions src/docker/conf/mirror.conf
@@ -1,6 +1,7 @@
#
# Configuration for the httpd mirror
#
ServerName localhost
<Directory /usr/local/apache2/htdocs>
Options +Indexes +MultiViews
IndexOptions FancyIndexing -SuppressLastModified
Expand Down
12 changes: 8 additions & 4 deletions src/docker/scripts/cmd.sh
@@ -1,10 +1,14 @@
#!/bin/sh

echo "Starting mirror"
/mirror.sh
/usr/local/bin/httpd-foreground
rm -f /usr/local/apache2/htdocs/*.html

#
# see https://github.com/xordiv/docker-alpine-cron
#
crond -s /var/spool/cron/crontabs -b -L /var/log/cron.log "$@" && tail -f /var/log/cron.log
crond -s /var/spool/cron/crontabs -b -L /var/log/cron.log "$@" && tail -f /var/log/cron.log &

echo "Mirror started"
/usr/local/bin/httpd-foreground
rm -f /usr/local/apache2/htdocs/*.html


12 changes: 0 additions & 12 deletions src/docker/scripts/entry.sh
@@ -1,15 +1,3 @@
#!/bin/sh

#
# see https://github.com/xordiv/docker-alpine-cron
#

set -e

rm -rf /var/spool/cron/crontabs && mkdir -m 0644 -p /var/spool/cron/crontabs

[ "$(ls -A /etc/cron.d)" ] && cp -f /etc/cron.d/* /var/spool/cron/crontabs/ || true

chmod -R 0644 /var/spool/cron/crontabs

exec "$@"
12 changes: 7 additions & 5 deletions src/docker/scripts/mirror.sh
Expand Up @@ -8,11 +8,13 @@ for f in $files
do
echo "/tmp/nvd/$f"
if [ -f "/tmp/nvd/$f" ]; then
if [ ! -d "/usr/local/apache2/htdocs/backup/$timestamp" ]; then
mkdir -p "/usr/local/apache2/htdocs/backup/$timestamp"
fi
if [ -f "/usr/local/apache2/htdocs/$f" ]; then
mv "/usr/local/apache2/htdocs/$f" "/usr/local/apache2/htdocs/backup/$timestamp/"
if [ -d "/usr/local/apache2/htdocs/backup/" ]; then
if [ ! -d "/usr/local/apache2/htdocs/backup/$timestamp" ]; then
mkdir -p "/usr/local/apache2/htdocs/backup/$timestamp"
fi
if [ -f "/usr/local/apache2/htdocs/$f" ]; then
mv "/usr/local/apache2/htdocs/$f" "/usr/local/apache2/htdocs/backup/$timestamp/"
fi
fi
cp -f "/tmp/nvd/$f" "/usr/local/apache2/htdocs/$f"
fi
Expand Down

0 comments on commit 9a8ff3d

Please sign in to comment.