diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b907acd3bde5d0ecfac9a5fbee30d75fed789af9..40005c59cb91f61b53b5e5983d2597a3d84bd86f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,62 +1,13 @@ -cache: - key: "$CI_COMMIT_REF_SLUG" - paths: - - ./vendor/ - - ./composer - stages: - - pre - - qa + - pre-build + - build + - test - install - -composer: - stage: pre - image: siutoba/docker-web - script: - - composer config cache-files-dir ./composer - - composer install --prefer-dist > /dev/null - artifacts: - paths: - - ./vendor/ - - ./bin - expire_in: 1 day - -sonar: - stage: qa - image: zaquestion/sonarqube-scanner - script: - - sonar-scanner -Dsonar.projectBaseDir=./ -Dsonar.login=$SONAR_TOKEN - allow_failure: true - -php-cs-fixer: - stage: qa - image: siutoba/docker-web - script: - - ./bin/php-cs-fixer fix --dry-run --diff src - allow_failure: true - dependencies: - - composer - - -php: - stage: install - image: siutoba/docker-web:develop - variables: - POSTGRES_DB: db_jurumi - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - services: - - postgres:9.6 - script: - - ./bin/instalador proyecto:definir-variables --no-interaction - - ./bin/instalador proyecto:instalar --no-interaction --no-progress - - ./bin/instalador permisos:simple --no-interaction --no-progress - dependencies: - - composer - artifacts: - paths: - - ./instalador.log - when: on_failure - expire_in: 10 day - - + - quality + - publish + - deploy + +include: + - local: '/docker/.gitlab-ci-image.yml' + - local: '/backend/.gitlab-ci.yml' + # - local: '/api/.gitlab-ci.yml' \ No newline at end of file diff --git a/api/.gitlab-ci.yml b/api/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..7e94419fd0562005ec21a4d108d68508723c3a5a --- /dev/null +++ b/api/.gitlab-ci.yml @@ -0,0 +1,76 @@ +# api:php-cs-fixer: +# extends: +# - .php-cs-fixer +# script: +# - ./php-cs-fixer fix --dry-run --diff --config api/.php_cs +# only: +# changes: +# - api/**/* + +# api:vendor_scanning: +# extends: +# - .vendor_scanning +# script: +# - ./security-checker.phar security:check composer.lock +# only: +# changes: +# - ./* +# - api/**/* +# - core/**/* + +api:docker-image: + stage: build + extends: + - .docker:image-cache + - .docker:image-app + variables: + CI_IMAGE_APP: api + only: + changes: + - ./* + - core/**/* + - api/**/* + - docker/**/* + +api:docker-publish: + stage: publish + extends: + - .docker:publish + variables: + GIT_STRATEGY: none + CI_IMAGE_APP: api + CI_IMAGE_TAG: $CI_REGISTRY_IMAGE/api:$CI_COMMIT_REF_NAME + needs: + - api:docker-image + only: + refs: + - develop + - master + - tags + changes: + - ./* + - core/**/* + - api/**/* + - docker/**/* + - version + +api:deploy-test: + stage: deploy + extends: + - .deploy:test + variables: + DEPLOY_URL: $PORTAINER_HOOK_api + needs: + - api:docker-publish + only: + refs: + - develop + - master + - tags + changes: + - ./* + - core/**/* + - api/**/* + - docker/**/* + - version + when: manual diff --git a/backend/.gitlab-ci.yml b/backend/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..abd7f32d9c693e1d948d8e1087c0e76940c477c0 --- /dev/null +++ b/backend/.gitlab-ci.yml @@ -0,0 +1,59 @@ +backend:php-cs-fixer: + extends: + - .php-cs-fixer + script: + - ./php-cs-fixer fix --dry-run --diff --config backend/.php_cs + only: + changes: + - backend/**/* + +backend:vendor_scanning: + extends: + - .vendor_scanning + script: + - ./security-checker.phar security:check composer.lock + only: + changes: + - ./* + - backend/**/* + - core/**/* + +backend:docker-image: + stage: build + extends: + - .docker:image-app + variables: + CI_IMAGE_APP: backend + DOCKERFILE: docker/Dockerfile + only: + changes: + - ./* + - core/**/* + - backend/**/* + - docker/**/* + +backend:publish-branch: + stage: publish + extends: + - .docker:publish + except: + refs: + - tags + variables: + CI_IMAGE_APP: backend + CI_IMAGE_TAG: "$CI_REGISTRY_IMAGE/$CI_IMAGE_APP/branches:$CI_COMMIT_REF_SLUG" + dependencies: + - backend:docker-image + +backend:publish-version: + stage: publish + extends: + - .docker:publish + only: + refs: + - tags + variables: + CI_IMAGE_APP: backend + CI_IMAGE_TAG: "$CI_REGISTRY_IMAGE/$CI_IMAGE_APP:$CI_COMMIT_REF_SLUG" + dependencies: + - backend:docker-image diff --git a/backend/.php_cs b/backend/.php_cs new file mode 100644 index 0000000000000000000000000000000000000000..defa84006a94672d059c73df4df2222a1f09c820 --- /dev/null +++ b/backend/.php_cs @@ -0,0 +1,10 @@ +<?php + +$finder = PhpCsFixer\Finder::create() + ->in(__DIR__.'/src') + ->in(__DIR__.'/db') +; + +return PhpCsFixer\Config::create() + ->setFinder($finder) +; diff --git a/docker/.gitlab-ci-image.yml b/docker/.gitlab-ci-image.yml new file mode 100644 index 0000000000000000000000000000000000000000..a783e15d0d707e4b586df3a3a84d361cad6517a6 --- /dev/null +++ b/docker/.gitlab-ci-image.yml @@ -0,0 +1,67 @@ +.php-cs-fixer: + stage: quality + image: siutoba/php:7.3-alpine + before_script: + - wget https://cs.symfony.com/download/php-cs-fixer-v2.phar -O php-cs-fixer + - chmod +x php-cs-fixer + allow_failure: true + dependencies: [] + +.vendor_scanning: + stage: quality + image: siutoba/php:7.3-alpine + before_script: + - wget https://get.sensiolabs.org/security-checker.phar + - chmod +x security-checker.phar + allow_failure: true + dependencies: [] + +.docker: + # https://gitlab.com/gitlab-com/support-forum/issues/4416#note_199451215 + image: docker:20.10.16 + services: + - name: docker:20.10.16-dind + command: ["--insecure-registry", "gitlab-runner.intranet.unam.edu.ar:6000", "--registry-mirror", "http://gitlab-runner.intranet.unam.edu.ar:6000"] + tags: + - docker + variables: + # si tag:kubernetes -> DOCKER_HOST: localhost + # si tag:docker -> NO definir DOCKER_HOST + # DOCKER_HOST: tcp://docker:2375 + DOCKER_DRIVER: overlay2 + DOCKER_BUILDKIT: "1" + DOCKER_TLS_CERTDIR: "/certs" + before_script: + - docker info + - echo -n $CI_JOB_TOKEN | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY + +.docker:image-app: + stage: build + extends: + - .docker + script: + - export CI_IMAGE_APP_BUILD="$CI_REGISTRY_IMAGE/$CI_IMAGE_APP/build:$CI_COMMIT_SHA" + - export DOCKERFILE="${DOCKERFILE:-Dockerfile}" + - > + docker build + --pull + --tag $CI_IMAGE_APP_BUILD + --file $DOCKERFILE + --build-arg APP_ENV=prod + --build-arg SRC=$CI_IMAGE_APP + . + - docker push $CI_IMAGE_APP_BUILD + - echo "IMAGEN $CI_IMAGE_APP_BUILD" + +.docker:publish: + stage: publish + extends: + - .docker + variables: + - GIT_STRATEGY: none + script: + - export CI_IMAGE_SOURCE="$CI_REGISTRY_IMAGE/$CI_IMAGE_APP/build:$CI_COMMIT_SHA" + - docker pull $CI_IMAGE_SOURCE + - docker tag $CI_IMAGE_SOURCE $CI_IMAGE_TAG + - docker push $CI_IMAGE_TAG + - echo "IMAGEN $CI_IMAGE_TAG" \ No newline at end of file