.gitlab-ci.yml 5.4 KB
Newer Older
Eric Pommateau's avatar
Eric Pommateau committed
1
stages:
Eric Pommateau's avatar
Eric Pommateau committed
2
    - build
Maxime REYROLLE's avatar
Maxime REYROLLE committed
3
    - lint
Eric Pommateau's avatar
Eric Pommateau committed
4
    - test
Eric Pommateau's avatar
Eric Pommateau committed
5
    - quality
6
    - staging
7
    - release
Eric Pommateau's avatar
Eric Pommateau committed
8 9 10 11 12 13 14

variables:
    CONTAINER_IMAGE: "${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME}"
    MYSQL_DATABASE: pastell_test
    MYSQL_USER: user
    MYSQL_PASSWORD: user
    MYSQL_RANDOM_ROOT_PASSWORD: "yes"
15 16 17 18
    MYSQL_HOST_TEST: 'mysql'
    MYSQL_HOST: 'mysql'
    MYSQL_PORT: '3306'
    PASTELL_SITE_BASE: 'https://localhost/'
19
    PLATEFORME_MAIL: 'admin@pastell.fr'
20

Eric Pommateau's avatar
Eric Pommateau committed
21 22
build:
  stage: build
Eric Pommateau's avatar
Eric Pommateau committed
23 24
  tags:
    - docker-build
25 26
  variables:
    GITHUB_API_TOKEN: "${GITHUB_API_TOKEN}"
Eric Pommateau's avatar
Eric Pommateau committed
27
  script:
28
    - date=$(date)
29
    - sed -i "s/%CI_BUILD_ID%/${CI_PIPELINE_ID}/" ./manifest.yml
30
    - sed -i "s/%BUILD_DATE%/$date/" ./manifest.yml
31
    - sed -i "s/%VERSION%/${CI_COMMIT_REF_NAME}/" ./manifest.yml
32
    - docker login -u "gitlab-ci-token" -p "$CI_JOB_TOKEN" $CI_REGISTRY
33
    - docker build --build-arg GITHUB_API_TOKEN=$GITHUB_API_TOKEN --pull -t ${CONTAINER_IMAGE} .
Eric Pommateau's avatar
Eric Pommateau committed
34
    - docker login -u "gitlab-ci-token" -p "$CI_JOB_TOKEN" $CI_REGISTRY
Eric Pommateau's avatar
Eric Pommateau committed
35
    - docker push ${CONTAINER_IMAGE}
36

Maxime REYROLLE's avatar
Maxime REYROLLE committed
37 38 39
lint:
  stage: lint
  image : "$CONTAINER_IMAGE"
Eric Pommateau's avatar
Eric Pommateau committed
40 41 42
  variables:
    DONT_INIT_DATABASE: "true"
    DONT_RETRIEVE_VALIDCA: "true"
Maxime REYROLLE's avatar
Maxime REYROLLE committed
43 44 45 46
  script:
    - cd /var/www/pastell
    - composer phpcs

47 48 49 50
#Note: il semble que l'entrypoint soit executé deux fois !
# https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/issues/1380
# Ca permet de tester l'idempotence de l'entrypoint, mais c'est pas super quand même

Eric Pommateau's avatar
Eric Pommateau committed
51
unit_test:
Eric Pommateau's avatar
Eric Pommateau committed
52
    stage: test
Eric Pommateau's avatar
Eric Pommateau committed
53
    image : "$CONTAINER_IMAGE"
Eric Pommateau's avatar
Eric Pommateau committed
54 55
    variables:
      XDEBUG_ON: "true"
Maxime REYROLLE's avatar
Maxime REYROLLE committed
56
      PCOV_ON: 1
Eric Pommateau's avatar
Eric Pommateau committed
57
      GIT_STRATEGY: none
Maxime REYROLLE's avatar
Maxime REYROLLE committed
58
      COMPOSER_PROCESS_TIMEOUT: 1200
Eric Pommateau's avatar
Eric Pommateau committed
59
      DONT_RETRIEVE_VALIDCA: "true"
Eric Pommateau's avatar
Eric Pommateau committed
60
    services:
Eric Pommateau's avatar
Eric Pommateau committed
61
        - mysql:5.7.23
62
    script:
Eric Pommateau's avatar
autre  
Eric Pommateau committed
63
        - cd /var/www/pastell
Maxime REYROLLE's avatar
Maxime REYROLLE committed
64 65
        - vendor/bin/pcov clobber
        - php -dpcov.enabled=1 -dpcov.directory=. vendor/bin/phpunit --coverage-text --colors=never --coverage-clover coverage/coverage.xml --log-junit coverage/logfile.xml
Eric Pommateau's avatar
autre  
Eric Pommateau committed
66
        - cp -rf coverage $CI_PROJECT_DIR
Eric Pommateau's avatar
Eric Pommateau committed
67 68 69 70 71 72 73 74 75 76 77
    artifacts:
        paths:
            - coverage
        expire_in: 1h

quality:
  stage: quality
  only:
    - master
  image : gitlab.libriciel.fr:4567/docker/sonar-scanner:latest
  script:
Eric Pommateau's avatar
Eric Pommateau committed
78
    - mkdir -p /var/www/pastell
Eric Pommateau's avatar
Eric Pommateau committed
79 80
    - cp -rf $CI_PROJECT_DIR/* /var/www/pastell
    - cd /var/www/pastell
Eric Pommateau's avatar
Eric Pommateau committed
81
    - /sonar-scanner -Dsonar.login=$SONAR_LOGIN -Dsonar.host.url=$SONAR_HOST_URL
Eric Pommateau's avatar
Eric Pommateau committed
82

83 84
acceptance_test:
    stage: test
Eric Pommateau's avatar
Eric Pommateau committed
85 86
    variables:
        GIT_STRATEGY: none
Eric Pommateau's avatar
Eric Pommateau committed
87
    image :  "$CONTAINER_IMAGE"
Eric Pommateau's avatar
Eric Pommateau committed
88
    services:
Eric Pommateau's avatar
Eric Pommateau committed
89
        - mysql:5.7.23
90
    script:
Eric Pommateau's avatar
Eric Pommateau committed
91
        - service apache2 start
Eric Pommateau's avatar
Eric Pommateau committed
92
        - cd /var/www/pastell
Eric Pommateau's avatar
Eric Pommateau committed
93
        - chown www-data /data/log/pastell.log
Eric Pommateau's avatar
test  
Eric Pommateau committed
94
        - chown www-data -R /data/workspace/
95
        - composer codecept
Eric Pommateau's avatar
Eric Pommateau committed
96 97
    artifacts:
        when: on_failure
98
        paths:
Eric Pommateau's avatar
Eric Pommateau committed
99
            - /var/www/pastell/test/codeception/tests/_output/
100

Eric Pommateau's avatar
Eric Pommateau committed
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
deploy_master:
    stage: staging
    environment:
        name: pastell.master.libriciel.fr
        url: https://pastell.master.libriciel.fr
    only:
        - master
    variables:
        PAYLOAD: "payload={\"text\": \"[pastell.master.libriciel.fr](https://pastell.master.libriciel.fr) a été mis à jour - [build $CI_PIPELINE_ID]($CI_PROJECT_URL/pipelines/$CI_PIPELINE_ID)\"}"
    script:
        - eval $(ssh-agent -s)
        - ssh-add <(echo "$SSH_PRIVATE_KEY")
        - mkdir -p ~/.ssh
        - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
        - scp ./docker-compose.yml gitlab@pastell.master.libriciel.fr:/data/docker-file
        - scp ./docker-compose.master.yml gitlab@pastell.master.libriciel.fr:/data/docker-file/docker-compose.override.yml
        - echo "$MASTER_ENV_FILE_CONTENT" > /tmp/.env
        - scp /tmp/.env gitlab@pastell.master.libriciel.fr:/data/docker-file/
        - ssh -tt gitlab@pastell.master.libriciel.fr "docker login -u gitlab-ci-token -p '$CI_JOB_TOKEN' $CI_REGISTRY && cd /data/docker-file/  && docker-compose pull && docker-compose up -d"
        - curl -i -X POST -d "$PAYLOAD" $MATTERMOST_WEBHOOK

122 123
deploy_ftp:
    stage: staging
124
    image : "$CONTAINER_IMAGE"
125
    only:
Eric Pommateau's avatar
Eric Pommateau committed
126
        - master
127
    before_script:
Eric Pommateau's avatar
Eric Pommateau committed
128
        - rm -f /var/lib/apt/lists/ftp.debian.org_debian_dists*
129 130 131 132
        - apt-get -qq update && apt-get -yqq install openssh-client lftp
        - mkdir -p ~/.ssh
        - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
    script:
Eric Pommateau's avatar
Eric Pommateau committed
133
        - cd /var/www/ && tar cvzf /tmp/pastell-master.tgz pastell
Eric Pommateau's avatar
Eric Pommateau committed
134
        - lftp -p 2222 -u "pastell","${RESSOURCE_LIBRICIEL_FTP_PASSWD}"  "sftp://ressources.libriciel.fr/pastell" -e "put /tmp/pastell-master.tgz; bye"
Eric Pommateau's avatar
Eric Pommateau committed
135 136
release:
    stage: release
Eric Pommateau's avatar
Eric Pommateau committed
137
    only:
Eric Pommateau's avatar
Eric Pommateau committed
138
      - tags
139 140
    image : "$CONTAINER_IMAGE"

Eric Pommateau's avatar
Eric Pommateau committed
141
    variables:
142 143 144
        TARBALL_NAME: pastell-${CI_COMMIT_REF_NAME}.tar.gz
        PAYLOAD: "payload={\"text\": \"[Pastell] Création de la version [$CI_COMMIT_REF_NAME](http://ressources.libriciel.fr/pastell/pastell-${CI_COMMIT_REF_NAME}.tar.gz)\"}"
    before_script:
Eric Pommateau's avatar
Eric Pommateau committed
145 146
        - apt-get -qq update || echo 1
        - apt-get -yqq install openssh-client lftp
147 148
        - mkdir -p ~/.ssh
        - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
Eric Pommateau's avatar
Eric Pommateau committed
149
    script:
150
        - cd /var/www/ && tar cvzf /tmp/${TARBALL_NAME} pastell
151
        - cp /tmp/${TARBALL_NAME} ${CI_PROJECT_DIR}
152
        - lftp -p 2222 -u "pastell","${RESSOURCE_LIBRICIEL_FTP_PASSWD}"  "sftp://ressources.libriciel.fr/pastell" -e "put /tmp/${TARBALL_NAME}; bye"
153 154
        - curl -i -X POST -d "$PAYLOAD" $MATTERMOST_WEBHOOK

155 156
    artifacts:
        paths:
157
          - ${TARBALL_NAME}
Eric Pommateau's avatar
Eric Pommateau committed
158 159