diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index dec1da522875848a1b0de96d20b1d59dd8a7453f..a5bb51fa4ad666b6d839605ff73d81502c3bdbcb 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,6 +2,7 @@ stages: - verify - build - test + - publish - security Check Makefile: @@ -25,7 +26,7 @@ Make All Images: - linux, dockerd script: - make - + test: stage: test tags: @@ -33,7 +34,16 @@ test: script: - docker run --rm unl-its/static-code-analysis sonar-scanner -v -Scan with Tenable: +Push to Container Registry: + after_script: + - rm -f /var/lib/gitlab-runner/.docker/config.json + stage: publish + tags: + - linux, dockerd + script: + - make publish + +.Scan with Tenable: stage: security tags: - linux, dockerd diff --git a/Makefile b/Makefile index f780e23a3583152e12cd29507484e1c9b19eaaa6..507c94e8f2ed719639aa21629dbfacb97c4e7141 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,10 @@ # Build File for Docker Images # ###################################### +# Repo +#################### +REPO_ORG = its-registry.unl.edu/unl-its/docker-ci + # All Dockerfiles #################### DOCKERFILES := $(shell find ./ -name "Dockerfile") @@ -19,7 +23,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 +.PHONY: all clean test $(DOCKERFILES) clean_images $(IMAGES_TO_CLEAN) static-code-analysis mobile delete_dangling_images security publish all: php-lint php-unit-test magento2 mobile static-code-analysis @@ -34,60 +38,80 @@ static-code-analysis: static-code-analysis_latest static-code-analysys_php stati # PHP Lint Images #################### php-lint_5.6: php-lint/5.6/Dockerfile - docker build $(BUILD_ARGS) -t unl-its/php-lint:5.6 -f php-lint/5.6/Dockerfile php-lint + 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 unl-its/php-lint:7.0 -f php-lint/7.0/Dockerfile php-lint + 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 unl-its/php-lint:7.1 -f php-lint/7.1/Dockerfile php-lint + 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 unl-its/php-lint:7.2 -f php-lint/7.2/Dockerfile php-lint + 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 unl-its/php-lint:latest + 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 # PHP Unit Test Images #################### php-unit-test_5.6: php-unit-test/5.6/Dockerfile - docker build $(BUILD_ARGS) -t unl-its/php-unit-test:5.6 -f php-unit-test/5.6/Dockerfile php-unit-test + 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 unl-its/php-unit-test:7.0 -f php-unit-test/7.0/Dockerfile php-unit-test + 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 unl-its/php-unit-test:7.1 -f php-unit-test/7.1/Dockerfile php-unit-test + 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 unl-its/php-unit-test:7.2 -f php-unit-test/7.2/Dockerfile php-unit-test + 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 unl-its/php-unit-test:7.2 unl-its/php-unit-test:latest + 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 unl-its/magento2-unit-test:latest magento2-unit-test/latest + 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 unl-its/magento2-xml-lint:latest magento2-xml-lint/latest + 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 unl-its/android-build-server:latest android-build-server + 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 unl-its/static-code-analysis:latest static-code-analysis/ + 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 unl-its/static-code-analysis:php static-code-analysis/ + 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 unl-its/static-code-analysis:python static-code-analysis/ + 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 unl-its/static-code-analysis:android static-code-analysis/android/ + 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 #################### @@ -112,6 +136,13 @@ security: 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: + @docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} ${CI_REGISTRY} + @for image in $(IMAGES_TO_PUBLISH); do \ + docker push $$image; \ + done + delete_dangling_images: @echo "Removing dangling images" @docker image prune -f @@ -119,9 +150,11 @@ 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" 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_PUBLISH:\t $(IMAGES_TO_PUBLISH)"