diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a5bb51fa4ad666b6d839605ff73d81502c3bdbcb..f14d4653ec9309e85fa16ca316052116c257beb0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -32,7 +32,7 @@ test: tags: - dockerd script: - - docker run --rm unl-its/static-code-analysis sonar-scanner -v + - docker run --rm its-registry.unl.edu/unl-its/docker-ci/static-code-analysis sonar-scanner -v Push to Container Registry: after_script: diff --git a/Makefile b/Makefile index 507c94e8f2ed719639aa21629dbfacb97c4e7141..eea00f842ff2a4a663b0c1d87e550382513edc37 100644 --- a/Makefile +++ b/Makefile @@ -10,11 +10,6 @@ REPO_ORG = its-registry.unl.edu/unl-its/docker-ci #################### 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) -IMAGES_TO_CLEAN := $(addprefix unl-its/, $(shell find ./ -maxdepth 1 -type d -not -name ".*" -printf '%f\n')) - # Get the latest commit #################### GIT_COMMIT = $(strip $(shell git rev-parse --short HEAD)) @@ -23,7 +18,7 @@ GIT_COMMIT = $(strip $(shell git rev-parse --short HEAD)) #################### BUILD_ARGS := --build-arg VCS_REF=$(GIT_COMMIT) -.PHONY: all clean test $(DOCKERFILES) clean_images $(IMAGES_TO_CLEAN) static-code-analysis mobile delete_dangling_images security publish +.PHONY: all clean test $(DOCKERFILES) static-code-analysis mobile delete_dangling_images security publish all: php-lint php-unit-test magento2 mobile static-code-analysis @@ -39,83 +34,62 @@ static-code-analysis: static-code-analysis_latest static-code-analysys_php stati #################### php-lint_5.6: php-lint/5.6/Dockerfile docker build $(BUILD_ARGS) -t ${REPO_ORG}/php-lint:5.6 -f php-lint/5.6/Dockerfile php-lint - docker tag ${REPO_ORG}/php-lint:5.6 unl-its/php-lint:5.6 php-lint_7.0: php-lint/7.0/Dockerfile docker build $(BUILD_ARGS) -t ${REPO_ORG}/php-lint:7.0 -f php-lint/7.0/Dockerfile php-lint - docker tag ${REPO_ORG}/php-lint:7.0 unl-its/php-lint:7.0 php-lint_7.1: php-lint/7.1/Dockerfile docker build $(BUILD_ARGS) -t ${REPO_ORG}/php-lint:7.1 -f php-lint/7.1/Dockerfile php-lint - docker tag ${REPO_ORG}/php-lint:7.1 unl-its/php-lint:7.1 php-lint_7.2: php-lint/7.2/Dockerfile docker build $(BUILD_ARGS) -t ${REPO_ORG}/php-lint:7.2 -f php-lint/7.2/Dockerfile php-lint - docker tag ${REPO_ORG}/php-lint:7.2 unl-its/php-lint:7.2 php-lint_latest: php-lint_7.2 - docker tag unl-its/php-lint:7.2 ${REPO_ORG}/php-lint:latest - docker tag ${REPO_ORG}/php-lint:latest unl-its/php-lint:latest + docker tag ${REPO_ORG}/php-lint:7.2 ${REPO_ORG}/php-lint:latest # PHP Unit Test Images #################### php-unit-test_5.6: php-unit-test/5.6/Dockerfile docker build $(BUILD_ARGS) -t ${REPO_ORG}/php-unit-test:5.6 -f php-unit-test/5.6/Dockerfile php-unit-test - docker tag ${REPO_ORG}/php-unit-test:5.6 unl-its/php-unit-test:5.6 php-unit-test_7.0: php-unit-test/7.0/Dockerfile docker build $(BUILD_ARGS) -t ${REPO_ORG}/php-unit-test:7.0 -f php-unit-test/7.0/Dockerfile php-unit-test - docker tag ${REPO_ORG}/php-unit-test:7.0 unl-its/php-unit-test:7.0 php-unit-test_7.1: php-unit-test/7.1/Dockerfile docker build $(BUILD_ARGS) -t ${REPO_ORG}/php-unit-test:7.1 -f php-unit-test/7.1/Dockerfile php-unit-test - docker tag ${REPO_ORG}/php-unit-test:7.1 unl-its/php-unit-test:7.1 php-unit-test_7.2: php-unit-test/7.2/Dockerfile docker build $(BUILD_ARGS) -t ${REPO_ORG}/php-unit-test:7.2 -f php-unit-test/7.2/Dockerfile php-unit-test - docker tag ${REPO_ORG}/php-unit-test:7.2 unl-its/php-unit-test:7.2 php-unit-test_latest: php-unit-test_7.2 docker tag ${REPO_ORG}/php-unit-test:7.2 ${REPO_ORG}/php-unit-test:latest - docker tag ${REPO_ORG}/php-unit-test:7.2 unl-its/php-unit-test:latest # Application Images #################### magento2-unit-test: magento2-unit-test/latest/Dockerfile docker build $(BUILD_ARGS) -t ${REPO_ORG}/magento2-unit-test:latest magento2-unit-test/latest - docker tag ${REPO_ORG}/magento2-unit-test:latest unl-its/magento2-unit-test:latest magento2-xml-lint: magento2-unit-test magento2-xml-lint/latest/Dockerfile docker build $(BUILD_ARGS) -t ${REPO_ORG}/magento2-xml-lint:latest magento2-xml-lint/latest - docker tag ${REPO_ORG}/magento2-xml-lint:latest unl-its/magento2-xml-lint:latest # Mobile Applications #################### android-build-server: android-build-server/Dockerfile docker build $(BUILD_ARGS) -t ${REPO_ORG}/android-build-server:latest android-build-server - docker tag ${REPO_ORG}/android-build-server:latest unl-its/android-build-server:latest # Sonarqube static-code-analysis # ##################### static-code-analysis_latest: static-code-analysis/Dockerfile docker build $(BUILD_ARGS) -t ${REPO_ORG}/static-code-analysis:latest static-code-analysis/ - docker tag ${REPO_ORG}/static-code-analysis:latest unl-its/static-code-analysis:latest static-code-analysys_php: static-code-analysis/Dockerfile docker build $(BUILD_ARGS) -t ${REPO_ORG}/static-code-analysis:php static-code-analysis/ - docker tag ${REPO_ORG}/static-code-analysis:php unl-its/static-code-analysis:php static-code-analysys_python: static-code-analysis/Dockerfile docker build $(BUILD_ARGS) -t ${REPO_ORG}/static-code-analysis:python static-code-analysis/ - docker tag ${REPO_ORG}/static-code-analysis:python unl-its/static-code-analysis:python static-code-analysys_android: android-build-server static-code-analysis/android/Dockerfile docker build $(BUILD_ARGS) -t ${REPO_ORG}/static-code-analysis:android static-code-analysis/android/ - docker tag ${REPO_ORG}/static-code-analysis:android unl-its/static-code-analysis:android - -# Cleanup -#################### -clean: clean_images test: $(DOCKERFILES) $(DOCKERFILES): @@ -123,18 +97,13 @@ $(DOCKERFILES): @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) delete_dangling_images -$(IMAGES_TO_CLEAN): - @echo "Uninstalling $@" - @docker rmi $(shell docker images --format '{{.Repository}}:{{.Tag}}' --filter reference=$@) - -IMAGES_TO_SCAN = $(shell docker images --format '{{.Repository}}:{{.Tag}}' | grep unl-its ) -security: - @docker login -u ${TENABLE_IO_ACCESS_KEY} -p ${TENABLE_IO_SECRET_KEY} registry.cloud.tenable.com - @for image in $(IMAGES_TO_SCAN); do \ - docker tag $$image registry.cloud.tenable.com/`echo $$image | cut -d "/" -f 2`; \ - docker push registry.cloud.tenable.com/`echo $$image | cut -d "/" -f 2`; \ - done +#IMAGES_TO_SCAN = $(shell docker images --format '{{.Repository}}:{{.Tag}}' | grep unl-its ) +#security: +# @docker login -u ${TENABLE_IO_ACCESS_KEY} -p ${TENABLE_IO_SECRET_KEY} registry.cloud.tenable.com +# @for image in $(IMAGES_TO_SCAN); do \ +# docker tag $$image registry.cloud.tenable.com/`echo $$image | cut -d "/" -f 2`; \ +# docker push registry.cloud.tenable.com/`echo $$image | cut -d "/" -f 2`; \ +# done IMAGES_TO_PUBLISH = $(shell docker images --format '{{.Repository}}:{{.Tag}}' --filter 'dangling=false' | grep $(REPO_ORG) | grep -v ':<none>$$' ) publish: @@ -149,12 +118,10 @@ delete_dangling_images: help: @echo -e "make [all] \n\t # Creates all the images" @echo -e "make <TARGET> \n\t # Creates an specific image" - @echo -e "make clean \n\t # Cleanup" @echo -e "make publish \n\t # Push the images to the UNL registry" - @echo -e "make security \n\t # Send the images to Tenable. Use env variables TENABLE_IO_ACCESS_KEY and TENABLE_IO_SECRET_KEY" +# @echo -e "make security \n\t # Send the images to Tenable. Use env variables TENABLE_IO_ACCESS_KEY and TENABLE_IO_SECRET_KEY" debug: @echo -e "DOCKERFILES: \t $(DOCKERFILES)" - @echo -e "IMAGES_TO_CLEAN:\t $(IMAGES_TO_CLEAN)" - @echo -e "IMAGES_TO_SCAN:\t $(IMAGES_TO_SCAN)" +# @echo -e "IMAGES_TO_SCAN:\t $(IMAGES_TO_SCAN)" @echo -e "IMAGES_TO_PUBLISH:\t $(IMAGES_TO_PUBLISH)" diff --git a/README.md b/README.md index 995a52e832bc53cdca5c6e566c1ef646defbcea2..7c1f31e244d211b5e709ea4cf67c8a38ddc36e3d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ -# docker-ci +[](https://git.unl.edu/unl-its/docker-ci/commits/develop) + +# Docker-ci Containers used on CI ## Building Images -To build these images, clone this repository onto a machine with docker and make installed. Run `make` and all of the images will be built and installed as local docker images. +To build these images, clone this repository onto a machine with docker and make installed. Run `make` and all of the images will be built and installed as local docker images. \ No newline at end of file diff --git a/examples/.gitkeep b/examples/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/examples/Android.md b/examples/Android.md new file mode 100644 index 0000000000000000000000000000000000000000..1fc8b7b4668c1b1268758d343047e4210c453757 --- /dev/null +++ b/examples/Android.md @@ -0,0 +1,32 @@ +# Android example of .gitlab-ci.yml + +## Standard Android app with SonarQube analysis + +- One 'Analysis' stage with one job. +- The job SonarQube is executed only in the branch `develop`. + +``` yml +stages: + - Analysis + +variables: + GRADLE_USER_HOME: ${CI_PROJECT_DIR}/gradle_home + +before_script: + - ./gradlew dependencies + - for d in /opt/android-sdk-linux/build-tools/*; do PATH="$PATH:$d"; done + +SonarQube: + stage: Analysis + image: its-registry.unl.edu/unl-its/docker-ci/static-code-analysis:android + tags: + - docker + only: + - develop + cache: + paths: + - gradle_home + script: + - ./gradlew sonarqube -Dsonar.host.url=$SONAR_URL -Dsonar.projectKey=$CI_PROJECT_PATH_SLUG -Dsonar.login=$SONAR_TOKEN + +``` diff --git a/examples/PHP.md b/examples/PHP.md new file mode 100644 index 0000000000000000000000000000000000000000..d1ce96b8bace3b4fc5cd34e585e5e00e551f4d5f --- /dev/null +++ b/examples/PHP.md @@ -0,0 +1,39 @@ +# PHP examples of .gitlab-ci.yml + +## Standard PHP app with lint and SonarQube analysis + +- One 'test' stage with two jobs. +- The jobs needs a runner with docker-host capabilities. +- The job SonarQube is executed only in the branch `develop`. + +``` yml +# To use this script, you must have the following variables defined +# You can define them at the project or the group level +# +# SONAR_URL: Full URL to the SonarQube server +# SONAR_TOKEN: API token for SonarQube + +variables: + GITLAB_CI: 1 + +stages: + - test + +PHP Lint: + stage: test + image: its-registry.unl.edu/unl-its/docker-ci/php-lint:7.0 + tags: + - docker + script: + - php-lint -d ./ + +SonarQube: + stage: test + image: its-registry.unl.edu/unl-its/docker-ci/static-code-analysis:php + tags: + - docker + only: + - develop + script: + - sonar-scanner -Dsonar.host.url=$SONAR_URL -Dsonar.projectKey=$CI_PROJECT_PATH_SLUG -Dsonar.sources=. -Dsonar.login=$SONAR_TOKEN +``` diff --git a/magento2-xml-lint/latest/Dockerfile b/magento2-xml-lint/latest/Dockerfile index b7d5072b9930e4ee66e6fbfed5c15825dd53bfea..399e2c7fd88d1151ee7ab15c2718069a44a2bdc0 100644 --- a/magento2-xml-lint/latest/Dockerfile +++ b/magento2-xml-lint/latest/Dockerfile @@ -1,4 +1,4 @@ -FROM unl-its/magento2-unit-test:latest +FROM its-registry.unl.edu/unl-its/docker-ci/magento2-unit-test:latest ARG BUILD_DATE ARG VCS_REF @@ -9,7 +9,7 @@ LABEL org.label-schema.build-date=$BUILD_DATE \ 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" \ + org.label-schema.schema-version="1.1" \ maintainer="Alan Nelson <alan.nelson@nebraska.edu>" # Scripts diff --git a/static-code-analysis/android/Dockerfile b/static-code-analysis/android/Dockerfile index 9b41a18c8fd95d528a0029ed19668f1bcab1d36d..7ec3ab9376c38e78432e870652708fffa1ede442 100644 --- a/static-code-analysis/android/Dockerfile +++ b/static-code-analysis/android/Dockerfile @@ -1,4 +1,4 @@ -FROM unl-its/android-build-server +FROM its-registry.unl.edu/unl-its/docker-ci/android-build-server ARG BUILD_DATE ARG VCS_REF @@ -21,4 +21,4 @@ WORKDIR /opt RUN mkdir -p /opt/src \ && curl -q -o sonarscanner.zip -L https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${SONAR_SCANNER_VERSION}.zip \ && unzip -q sonarscanner.zip -d ${SONAR_HOME} \ - && rm sonarscanner.zip \ No newline at end of file + && rm sonarscanner.zip