From 010ab8ffdf2233cc6ac316e96c13ee503566c0f2 Mon Sep 17 00:00:00 2001
From: Szymon Tomasz Datko <szymon.tomasz.datko@cern.ch>
Date: Sat, 6 Aug 2016 15:24:07 +0200
Subject: [PATCH] Base Dockerfile and build script, README update

---
 Dockerfile | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 README.md  | 22 +++++++++++++
 build.sh   | 64 +++++++++++++++++++++++++++++++++++++
 3 files changed, 178 insertions(+)
 create mode 100644 Dockerfile
 create mode 100755 build.sh

diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..e6a94f3
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,92 @@
+#
+# Dockerfile for security-services/code-checking
+#
+# Maintainer:
+# CERN IT-DI-CSO <computer.security@cern.ch>
+#
+
+#
+# Base image and image metadata
+#
+FROM centos:latest
+MAINTAINER "CERN IT-DI-CSO <computer.security@cern.ch>"
+
+
+#
+# Helpful variables
+#
+ENV basedir /opt
+
+
+#
+# Enable extra repositories 
+#
+RUN yum -y install epel-release
+
+
+#
+# Update the software and install basic development tools
+#
+RUN yum -y update
+RUN yum -y groups mark convert
+RUN yum -y groupinstall 'Development Tools'
+
+
+#
+# Install Python development packages
+#
+RUN yum -y install python-devel python-flake8 python-pep8
+
+
+#
+# Install general useful software
+#
+RUN yum -y install wget unzip unrar sudo
+RUN yum -y install p7zip p7zip-plugins
+RUN yum -y install htop vim
+
+
+#
+# Install dependencies for RATS
+#
+RUN yum -y install expat expat-devel
+RUN yum -y install flex flex-devel
+
+
+#
+# Install dependencies for PMD and FindBugs
+#
+RUN yum -y install java
+
+
+#
+# Install RATS
+#
+WORKDIR $basedir
+RUN wget https://rough-auditing-tool-for-security.googlecode.com/files/rats-2.4.tgz
+RUN tar -xzf rats-2.4.tgz
+
+WORKDIR $basedir/rats-2.4
+RUN ./configure && make && make install
+
+
+#
+# Install PyLint
+#
+RUN yum -y install pylint
+
+
+#
+# Install PMD
+#
+WORKDIR $basedir
+RUN wget https://github.com/pmd/pmd/releases/download/pmd_releases%2F5.5.1/pmd-bin-5.5.1.zip
+RUN unzip pmd-bin-5.5.1.zip
+
+
+#
+# Install FindBugs
+#
+WORKDIR $basedir
+RUN wget http://prdownloads.sourceforge.net/findbugs/findbugs-3.0.1.tar.gz
+RUN tar -xzf findbugs-3.0.1.tar.gz
diff --git a/README.md b/README.md
index e69de29..79e1fbe 100644
--- a/README.md
+++ b/README.md
@@ -0,0 +1,22 @@
+# Security-Services/Code-Checking
+
+This repository contains Dockerfile with additional tools that are used
+to build Docker image **Security-Services/Code-Checking** for automated
+code checking with Gitlab-CI.
+
+
+## Script usage
+
+```
+[fenek@Polluks Security-Services-Code-Checking]$ ./build.sh --help
+Usage:
+  ./build.sh [TAG]
+  ./build.sh [-h|--help]
+
+Arguments:
+  TAG        -- tag string for image, current date by default
+  -h|--help  -- display information about usage
+
+Please, note that Docker service must be running on host.
+```
+
diff --git a/build.sh b/build.sh
new file mode 100755
index 0000000..bee938f
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,64 @@
+#!/bin/sh
+#
+# Script to build Docker image from Dockerfile
+#
+# Maintainer:
+# CERN IT-DI-CSO <computer.security@cern.ch>
+#
+
+#
+# Build parameters
+#
+REPOSITORY='security-services'
+IMAGENAME='code-checking'
+IMAGETAG="${1:-$( date +'%Y-%m-%d' )}"
+
+
+#
+# Display help, if needed
+#
+if [[ "${1}" == '-h' || "${1}" == '--help' || "${#}" > 1 ]]; then
+    echo 'Usage:'
+    echo "  ${0} [TAG]"
+    echo "  ${0} [-h|--help]"
+    echo ''
+    echo 'Arguments:'
+    echo '  TAG        -- tag string for image, current date by default'
+    echo '  -h|--help  -- display information about usage'
+    echo ''
+    echo 'Please, note that Docker service must be running on host.'
+    exit 0
+fi
+
+
+#
+# Display image tag
+#
+echo "Building image with tag: ${IMAGETAG}"
+echo ''
+
+
+#
+# Find and delete any previous image with specified tag
+#
+PREVIOUS=$( docker images \
+            | grep "${REPOSITORY}/${IMAGENAME}" \
+            | grep -e "${IMAGETAG}" \
+            | awk '{ print $3; }' \
+            | sort --unique \
+            | tr '\n' ' ' \
+            | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' )
+
+if [[ ! -z "${PREVIOUS}" ]]; then
+    docker rmi --force "${PREVIOUS}"
+fi
+
+
+#
+# Build the image
+#
+docker build \
+  --no-cache='true' \
+  --tag="${REPOSITORY}/${IMAGENAME}:latest" \
+  --tag="${REPOSITORY}/${IMAGENAME}:${IMAGETAG}" \
+  .   # Run inside current directory
-- 
GitLab