diff --git a/Makefile b/Makefile index 25757a2..5cc1a63 100644 --- a/Makefile +++ b/Makefile @@ -29,14 +29,14 @@ setup-cluster: kubectl apply -k kind/cluster/lb --server-side ssh-secret: - cp kustomization/overlays/dev/resources/tekton/secret/secret.yaml.distkustomization/overlays/dev/resources/tekton/secret/secret.yaml + cp kustomization/base/tekton/secret/secret.yaml.dist kustomization/base/tekton/secret/secret.yaml docker-secret: docker login reg.cadoles.com mkdir -p kustomization/base/tekton/secret/dockerconfig docker --config kustomization/base/tekton/secret/dockerconfig login reg.cadoles.com # mv kustomization/base/tekton/secret/dockerconfig/config.json kustomization/base/tekton/secret/dockerconfig/.dockerconfigjson - kubectl create secret generic regcred --from-file=config.json=kustomization/base/tekton/secret/dockerconfig/config.json + kubectl create secret generic regcred --from-file=config.json=kustomization/base/tekton/secret/dockerconfig/config.json -n tekton deploy-dev: ## Déploie le projet dans le cluster (nécessite la variable $HARBOR_USER_NAME) skaffold dev -p dev --cleanup=false --default-repo reg.cadoles.com/${HARBOR_USER_NAME} diff --git a/README.md b/README.md index ba5f576..97bf2e8 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,22 @@ CI du projet MSE - -[Documentation](doc/tekton.md) - - ### Lancement de l'environnement +Lancer l'environnement + ``` make create-cluster - skaffold dev ``` + +Préparer les secrets +``` +make ssh-secret +make docker-secret +``` +Editer le fichier `kustomization/base/tekton/secret/secret.yaml` avec les identifiants git + + +### Lancement d'un pipeline +[Documentation](doc/tekton.md) diff --git a/kustomization/base/tekton/pipeline/pipeline-symfonyapp.yaml b/kustomization/base/tekton/pipeline/pipeline-symfonyapp.yaml index d8512cf..3fdfdf0 100644 --- a/kustomization/base/tekton/pipeline/pipeline-symfonyapp.yaml +++ b/kustomization/base/tekton/pipeline/pipeline-symfonyapp.yaml @@ -9,6 +9,9 @@ spec: - name: repo-url type: string description: The git repo URL to clone from. + - name: revision + type: string + description: The git repo branch to checkout. - name: image type: string description: Full name of image repo. @@ -33,6 +36,10 @@ spec: params: - name: url value: $(params.repo-url) + - name: revision + value: $(params.revision) + - name: submodules + value: 'false' # Lecture du readme du projet - name: show-readme runAfter: ["fetch-source"] @@ -68,30 +75,45 @@ spec: - name: config workspace: config - - name: kaniko-build - taskRef: - name: kaniko - params: - - name: IMAGE - value: $(params.image) - - name: DOCKERFILE - value: $(params.dockerfile) - - name: EXTRA_ARGS - value: - - --skip-tls-verify - - --insecure - workspaces: - - name: source - workspace: shared-data - - name: dockerconfig - workspace: docker-credentials + # Execution des tests unitaires avec une BDD en sidecar + - name: php-unit-test runAfter: - fetch-source # - php-cs-fixer # - phpstan # - php-security-check - retries: 3 + taskRef: + name: php-unit-test + workspaces: + - name: source + workspace: shared-data + + # - name: kaniko-build + # taskRef: + # name: kaniko + # params: + # - name: IMAGE + # value: $(params.image) + # - name: DOCKERFILE + # value: $(params.dockerfile) + # - name: BUILDER_IMAGE + # value: gcr.io/kaniko-project/executor:v1.20.0 + # - name: EXTRA_ARGS + # value: + # - --skip-tls-verify + # - --insecure + # - --ignore-path=/product_uuid + # workspaces: + # - name: source + # workspace: shared-data + # - name: dockerconfig + # workspace: docker-credentials + # runAfter: + # - fetch-source + # # - php-cs-fixer + # # - phpstan + # # - php-security-check + # retries: 3 - # diff --git a/kustomization/base/tekton/pipeline/pipelinerun.yaml b/kustomization/base/tekton/pipeline/pipelinerun.yaml index 48735a0..9dfffb4 100644 --- a/kustomization/base/tekton/pipeline/pipelinerun.yaml +++ b/kustomization/base/tekton/pipeline/pipelinerun.yaml @@ -2,6 +2,7 @@ apiVersion: tekton.dev/v1beta1 kind: PipelineRun metadata: generateName: symfonyapp-run- + namespace: tekton spec: serviceAccountName: build-bot pipelineRef: @@ -26,7 +27,9 @@ spec: secretName: regcred params: - name: repo-url - value: https://forge.cadoles.com/Cadoles/hydra-dispatcher.git + value: https://forge.cadoles.com/CNOUS/mse.git + - name: revision + value: k8s - name: image value: reg.cadoles.com/mlamalle/testtekton - name: dockerfile diff --git a/kustomization/base/tekton/task/symfonyapp/kustomization.yaml b/kustomization/base/tekton/task/symfonyapp/kustomization.yaml index e462cda..9d01edf 100644 --- a/kustomization/base/tekton/task/symfonyapp/kustomization.yaml +++ b/kustomization/base/tekton/task/symfonyapp/kustomization.yaml @@ -7,3 +7,4 @@ resources: - task/php-cs-fixer.yaml - task/php-security-check.yaml - task/phpstan.yaml +- task/php-unit-test.yaml diff --git a/kustomization/base/tekton/task/symfonyapp/task/php-unit-test.yaml b/kustomization/base/tekton/task/symfonyapp/task/php-unit-test.yaml new file mode 100644 index 0000000..18dbb61 --- /dev/null +++ b/kustomization/base/tekton/task/symfonyapp/task/php-unit-test.yaml @@ -0,0 +1,68 @@ +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: php-unit-test +spec: + description: PHP unit test with bdd sidecar + workspaces: + - name: source + sidecars: + - name: database + image: postgres:16 + env: + - name: POSTGRES_PASSWORD + value: not_so_secret + - name: POSTGRES_HOST_AUTH_METHOD + value: trust + - name: redis + image: redis:4.0 + + steps: + - name: exec + image: reg.cadoles.com/cadoles/symfony:alpine-php-7.4-base-20230926 + env: + - name: PHP_FPM_MEMORY_LIMIT + value: 512m + - name: MSE_DATABASE_DRIVER + value: pdo_pgsql + - name: MSE_DATABASE_HOST + value: localhost + - name: MSE_DATABASE_PORT + value: '5432' + - name: MSE_DATABASE_NAME + value: postgres + - name: MSE_DATABASE_USER + value: postgres + - name: MSE_DATABASE_PASSWORD + value: not_so_secret + - name: MSE_REDIS_SERVER + value: localhost + - name: MSE_REDIS_PORT + value: '6379' + command: + - /bin/sh + args: + - '-c' + - | + set -ex + apk add bash=5.1.16-r0 \ + postgresql-client \ + php7-gd=7.4.33-r1 \ + php7-xsl=7.4.33-r1 \ + php7-pdo=7.4.33-r1 \ + php7-pgsql=7.4.33-r1 \ + php7-pdo_pgsql=7.4.33-r1 \ + php7-soap=7.4.33-r1 \ + php7-ldap=7.4.33-r1 \ + php7-pdo_mysql=7.4.33-r1 \ + php7-bcmath=7.4.33-r1 \ + php7-intl=7.4.33-r1 \ + php7-fileinfo=7.4.33-r1 \ + php7-iconv=7.4.33-r1 \ + php7-pecl-amqp=1.11.0-r0 \ + php7-pecl-redis=5.3.6-r0 + cd $(workspaces.source.path) + app/console doctrine:migrations:migrate -n + ./scripts/run-php-tests.sh --group unit --stderr --testdox -d memory_limit=512M + +