From 155c22f27293a004d4aa9cc2c819f4ce44302d30 Mon Sep 17 00:00:00 2001 From: Jose Raul Barreras <barreras@unl.edu> Date: Tue, 11 Sep 2018 19:57:48 -0500 Subject: [PATCH] add static-code-analysis --- Makefile | 73 ++++++++++++++++++++++------ magento2-unit-test/latest/Dockerfile | 13 +++++ magento2-xml-lint/latest/Dockerfile | 12 +++++ php-lint/5.6/Dockerfile | 12 +++++ php-lint/7.0/Dockerfile | 12 +++++ php-lint/7.1/Dockerfile | 12 +++++ php-lint/7.2/Dockerfile | 12 +++++ static-code-analysis/Dockerfile | 33 +++++++++++++ static-code-analysis/entrypoint.sh | 9 ++++ 9 files changed, 174 insertions(+), 14 deletions(-) create mode 100644 static-code-analysis/Dockerfile create mode 100644 static-code-analysis/entrypoint.sh diff --git a/Makefile b/Makefile index a0b100a..71ca705 100644 --- a/Makefile +++ b/Makefile @@ -2,29 +2,51 @@ # Build File for Docker Images # ###################################### -.PHONY: magento2-unit-test magento2-xml-lint +# All Dockerfiles +#################### +DOCKERFILES := $(shell find ./ -name "Dockerfile") + +# List of images to clean +#################### +IMAGES_TO_CLEAN := $(shell echo $(shell echo $(shell grep -h LABEL $(DOCKERFILES)) | sed -e 's/LABEL name=//g') | tr [:space:] ' \n' | sort -u) + +# Get the latest commit +#################### +GIT_COMMIT = $(strip $(shell git rev-parse --short HEAD)) + +# Get the version number from the code +#################### +CODE_VERSION = $(strip $(shell cat VERSION)) + +# Build date +#################### +BUILD_DATE := `date -u +"%Y-%m-%dT%H:%M:%SZ"` + +# Docker build arguments +#################### +BUILD_ARGS := --build-arg BUILD_DATE=$(BUILD_DATE) + +docker_build := "docker build $(BUILD_ARGS)" + +.PHONY: all clean test $(DOCKERFILES) clean_images $(IMAGES_TO_CLEAN) static-code-analysis all: \ - php-lint_5.6 \ - php-lint_7.0 \ - php-lint_7.1 \ - php-lint_7.2 \ - php-lint_latest \ - magento2-unit-test \ - magento2-xml-lint + php-lint_5.6 php-lint_7.0 php-lint_7.1 php-lint_7.2 php-lint_latest \ + magento2-unit-test magento2-xml-lint \ + static-code-analysis # PHP Images #################### -php-lint_5.6: +php-lint_5.6: php-lint/5.6/Dockerfile docker build -t unl-its/php-lint:5.6 -f php-lint/5.6/Dockerfile php-lint -php-lint_7.0: +php-lint_7.0: php-lint/7.0/Dockerfile docker build -t unl-its/php-lint:7.0 -f php-lint/7.0/Dockerfile php-lint -php-lint_7.1: +php-lint_7.1: php-lint/7.1/Dockerfile docker build -t unl-its/php-lint:7.1 -f php-lint/7.1/Dockerfile php-lint -php-lint_7.2: +php-lint_7.2: php-lint/7.2/Dockerfile docker build -t unl-its/php-lint:7.2 -f php-lint/7.2/Dockerfile php-lint php-lint_latest: php-lint_7.2 @@ -33,12 +55,18 @@ php-lint_latest: php-lint_7.2 # Application Images #################### -magento2-unit-test: +magento2-unit-test: magento2-unit-test/latest/Dockerfile docker build -t unl-its/magento2-unit-test:latest magento2-unit-test/latest -magento2-xml-lint: +magento2-xml-lint: magento2-unit-test magento2-xml-lint/latest/Dockerfile docker build -t unl-its/magento2-xml-lint:latest magento2-xml-lint/latest +# Sonarqube static-code-analysis +# ##################### +static-code-analysis: + docker build $(BUILD_ARGS) -t unl-its/static-code-analysis:latest static-code-analysis/ + docker build $(BUILD_ARGS) -t unl-its/static-code-analysis:php static-code-analysis/ + docker build $(BUILD_ARGS) -t unl-its/static-code-analysis:python static-code-analysis/ # Cleanup #################### @@ -49,3 +77,20 @@ clean: docker image rm unl-its/php-lint:7.2; true docker image rm unl-its/php-lint:latest; true docker image rm unl-its/magento2-unit-test:latest; true + +test: $(DOCKERFILES) +$(DOCKERFILES): + @echo "Linting and validating $(@D)..." + @docker run --rm -i nimmis/label-inspector lint < $(@D)/Dockerfile + @docker run --rm -i nimmis/label-inspector validate < $(@D)/Dockerfile + +clean_images: $(IMAGES_TO_CLEAN) +$(IMAGES_TO_CLEAN): + @echo "Uninstalling $@" + docker rmi $(shell docker images --format '{{.Repository}}:{{.Tag}}' | grep $@) + +help: + @echo -e "make [all] \t # Creates all the images" + @echo -e "make <TARGET> \t # Creates an specific image" + @echo -e "make clean \t # Cleanup" + diff --git a/magento2-unit-test/latest/Dockerfile b/magento2-unit-test/latest/Dockerfile index aae82f3..23b6c24 100644 --- a/magento2-unit-test/latest/Dockerfile +++ b/magento2-unit-test/latest/Dockerfile @@ -1,5 +1,18 @@ FROM centos:7 +ARG BUILD_DATE +ARG VCS_REF +ARG VERSION +LABEL org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.name="Magento Unit Tester" \ + org.label-schema.description="" \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vendor="University of Nebraska - Lincoln" \ + org.label-schema.version=$VERSION \ + org.label-schema.schema-version="1.0" \ + maintainer="Alan Nelson <alan.nelson@nebraska.edu>" + + # Add additional REPOs RUN rpm -i https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \ && rpm -i https://rhel7.iuscommunity.org/ius-release.rpm diff --git a/magento2-xml-lint/latest/Dockerfile b/magento2-xml-lint/latest/Dockerfile index 6e32e1b..b7d5072 100644 --- a/magento2-xml-lint/latest/Dockerfile +++ b/magento2-xml-lint/latest/Dockerfile @@ -1,5 +1,17 @@ FROM unl-its/magento2-unit-test:latest +ARG BUILD_DATE +ARG VCS_REF +ARG VERSION +LABEL org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.name="Magento 2 XML linter" \ + org.label-schema.description="" \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vendor="University of Nebraska - Lincoln" \ + org.label-schema.version=$VERSION \ + org.label-schema.schema-version="1.0" \ + maintainer="Alan Nelson <alan.nelson@nebraska.edu>" + # Scripts COPY xml-lint docker-entrypoint /usr/local/bin/ diff --git a/php-lint/5.6/Dockerfile b/php-lint/5.6/Dockerfile index 4bdddf4..26c505d 100644 --- a/php-lint/5.6/Dockerfile +++ b/php-lint/5.6/Dockerfile @@ -1,5 +1,17 @@ FROM php:5.6-alpine +ARG BUILD_DATE +ARG VCS_REF +ARG VERSION +LABEL org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.name="PHP 5.6 linter" \ + org.label-schema.description="" \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vendor="University of Nebraska - Lincoln" \ + org.label-schema.version=$VERSION \ + org.label-schema.schema-version="1.0" \ + maintainer="Alan Nelson <alan.nelson@nebraska.edu>" + RUN apk add --no-cache bash COPY php-lint docker-entrypoint /usr/local/bin/ diff --git a/php-lint/7.0/Dockerfile b/php-lint/7.0/Dockerfile index c14b10d..4803f61 100644 --- a/php-lint/7.0/Dockerfile +++ b/php-lint/7.0/Dockerfile @@ -1,5 +1,17 @@ FROM php:7.0-alpine +ARG BUILD_DATE +ARG VCS_REF +ARG VERSION +LABEL org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.name="PHP 7.0 linter" \ + org.label-schema.description="" \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vendor="University of Nebraska - Lincoln" \ + org.label-schema.version=$VERSION \ + org.label-schema.schema-version="1.0" \ + maintainer="Alan Nelson <alan.nelson@nebraska.edu>" + RUN apk add --no-cache bash COPY php-lint docker-entrypoint /usr/local/bin/ diff --git a/php-lint/7.1/Dockerfile b/php-lint/7.1/Dockerfile index 2942326..7bdd3b4 100644 --- a/php-lint/7.1/Dockerfile +++ b/php-lint/7.1/Dockerfile @@ -1,5 +1,17 @@ FROM php:7.1-alpine +ARG BUILD_DATE +ARG VCS_REF +ARG VERSION +LABEL org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.name="PHP 7.1 linter" \ + org.label-schema.description="" \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vendor="University of Nebraska - Lincoln" \ + org.label-schema.version=$VERSION \ + org.label-schema.schema-version="1.0" \ + maintainer="Alan Nelson <alan.nelson@nebraska.edu>" + RUN apk add --no-cache bash COPY php-lint docker-entrypoint /usr/local/bin/ diff --git a/php-lint/7.2/Dockerfile b/php-lint/7.2/Dockerfile index 90e9800..fcc2d84 100644 --- a/php-lint/7.2/Dockerfile +++ b/php-lint/7.2/Dockerfile @@ -1,5 +1,17 @@ FROM php:7.2-alpine +ARG BUILD_DATE +ARG VCS_REF +ARG VERSION +LABEL org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.name="PHP 7.2 linter" \ + org.label-schema.description="" \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vendor="University of Nebraska - Lincoln" \ + org.label-schema.version=$VERSION \ + org.label-schema.schema-version="1.0" \ + maintainer="Alan Nelson <alan.nelson@nebraska.edu>" + RUN apk add --no-cache bash COPY php-lint docker-entrypoint /usr/local/bin/ diff --git a/static-code-analysis/Dockerfile b/static-code-analysis/Dockerfile new file mode 100644 index 0000000..9bf7070 --- /dev/null +++ b/static-code-analysis/Dockerfile @@ -0,0 +1,33 @@ +FROM openjdk:8-jre-alpine + +ARG BUILD_DATE +ARG VCS_REF +ARG VERSION +LABEL org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.name="Sonarqube Static Code Analyzer" \ + org.label-schema.description="Docker image for static code analysis using a Sonarqube server" \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vendor="University of Nebraska - Lincoln" \ + org.label-schema.version=$VERSION \ + org.label-schema.schema-version="1.0" \ + maintainer="J.R. Barreras <barreras@unl.edu>" + +ENV SONAR_SCANNER_VERSION 3.2.0.1227 + +WORKDIR /opt + +RUN apk add --no-cache curl sed bash su-exec && \ + mkdir -p /opt/src && \ + curl --insecure -o ./sonarscanner.zip -L https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${SONAR_SCANNER_VERSION}.zip && \ + unzip sonarscanner.zip && \ + rm sonarscanner.zip + +ENV SONAR_RUNNER_HOME=/opt/sonar-scanner-${SONAR_SCANNER_VERSION} +ENV PATH $PATH:/opt/sonar-scanner-${SONAR_SCANNER_VERSION}/bin + +COPY entrypoint.sh /usr/local/bin/ +RUN chmod +x /usr/local/bin/entrypoint.sh +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] + +CMD /bin/bash + diff --git a/static-code-analysis/entrypoint.sh b/static-code-analysis/entrypoint.sh new file mode 100644 index 0000000..ae5005e --- /dev/null +++ b/static-code-analysis/entrypoint.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# Add local user +# Either use the LOCAL_USER_ID if passed in at runtime or +# fallback + +USER_ID=${LOCAL_USER_ID:-9001} + +su-exec user "$@" -- GitLab