.gitlab-ci.yml 6.53 KB
Newer Older
Wietse Kuipers's avatar
Wietse Kuipers committed
1 2 3 4
variables:
  POSTGRES_DB: thalia
  POSTGRES_USER: postgres
  POSTGRES_PASSWORD: ""
5 6
  # https://hub.docker.com/r/thalia/python-thalia/
  # https://github.com/thaliawww/python-thalia
7 8
  # Should get auto-updated with the official 'python' repository
  # Installs:
Jelle Besseling's avatar
Jelle Besseling committed
9
  #  - pip: coverage, poetry
10
  #  - apt: ghostscript
11
  PY36_IMAGE: thalia/python-thalia:3.6
Thom Wiggers's avatar
Thom Wiggers committed
12
  PY37_IMAGE: thalia/python-thalia:3.7
Thom Wiggers's avatar
Thom Wiggers committed
13
  PIP_CACHE_DIR: "${CI_PROJECT_DIR}/pip-cache"
Wietse Kuipers's avatar
Wietse Kuipers committed
14

Thom Wiggers's avatar
Thom Wiggers committed
15 16 17 18
stages:
  - test
  - deploy

19
codestyle:
Thom Wiggers's avatar
Thom Wiggers committed
20
  stage: test
Thom Wiggers's avatar
Thom Wiggers committed
21
  image: $PY36_IMAGE
Jelle Besseling's avatar
Jelle Besseling committed
22 23
  before_script:
    - poetry install --no-interaction
Thom Wiggers's avatar
Thom Wiggers committed
24
  script:
Jelle Besseling's avatar
Jelle Besseling committed
25
    - poetry run flake8 website
26
    # Check for obsolete translations in .po files (starting with `#~`).
27
    - cd website
28
    - grep --include="*.po" --files-with-matches --recursive "^#~" && exit 1 || echo "No obsolete translations found."
29 30 31 32 33 34
    # Check for untranslated strings in .po files
    - empty_strings=$(sed '$a\\' **/locale/nl/LC_MESSAGES/django.po | tac | sed '/^$/N;/\nmsgstr ""$/,/^msgid/!d' | tac)
    - empty_strings+=$(sed '$a\\' locale/nl/LC_MESSAGES/django.po | tac | sed '/^$/N;/\nmsgstr ""$/,/^msgid/!d' | tac)
    - if [[ $empty_strings ]]; then echo $empty_strings && exit 1; else echo "No untranslated strings found."; fi
    # Check for fuzzy translations in .po files
    - grep --include="*.po" --files-with-matches --recursive "#, fuzzy" && exit 1 || echo "No fuzzy translations found."
Thom Wiggers's avatar
Thom Wiggers committed
35 36

.djangotest: &djangotest
Thom Wiggers's avatar
Thom Wiggers committed
37
  stage: test
Thom Wiggers's avatar
Thom Wiggers committed
38 39
  services:
    - postgres:latest
Thom Wiggers's avatar
Thom Wiggers committed
40 41
  before_script:
    - git log -1
Jelle Besseling's avatar
Jelle Besseling committed
42
    - poetry install --no-interaction
Thom Wiggers's avatar
Thom Wiggers committed
43
  script:
Thom Wiggers's avatar
Thom Wiggers committed
44
    - cd website
Jelle Besseling's avatar
Jelle Besseling committed
45 46 47
    - poetry run python manage.py check
    - poetry run python manage.py templatecheck --project-only
    - poetry run python manage.py makemigrations --no-input --check --dry-run
48
    - poetry run python -Wall -mcoverage run manage.py test
Thom Wiggers's avatar
Thom Wiggers committed
49
    - coverage report
Thom Wiggers's avatar
Thom Wiggers committed
50

Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
51
python36-django21:
Thom Wiggers's avatar
Thom Wiggers committed
52
  <<: *djangotest
Thom Wiggers's avatar
Thom Wiggers committed
53
  image: $PY36_IMAGE
Thom Wiggers's avatar
Thom Wiggers committed
54

Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
55
python37-django21:
Thom Wiggers's avatar
Thom Wiggers committed
56
  <<: *djangotest
Thom Wiggers's avatar
Thom Wiggers committed
57
  image: $PY37_IMAGE
58 59 60 61 62 63 64 65 66 67 68 69
  after_script:
    - cd website
    - coverage html --directory=covhtml --title="${CI_COMMIT_REF_SLUG} Coverage Report"
  artifacts:
    paths:
      - website/covhtml/

.sshsetup: &sshsetup
  before_script:
    - mkdir -p ~/.ssh
    - echo "$IVO_KNOWN_HOST" > ~/.ssh/known_hosts
    - echo "$COVERAGE_DEPLOY_SSH_KEY" > ~/.ssh/id_coverage
70 71
    - echo "$DOCS_DEPLOY_SSH_KEY" > ~/.ssh/id_docs
    - chmod 0600 ~/.ssh/id_*
72 73 74 75 76 77 78 79 80
    - apt-get update
    - apt-get install -y openssh-client

coverage deploy:
  stage: deploy
  image: debian:stretch
  dependencies:
    - python37-django21
  environment:
81
    name: coverage/${CI_COMMIT_REF_NAME}
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
    url: https://coverage.technicie.nl/${CI_COMMIT_REF_SLUG}/
    on_stop: coverage remove
  <<: *sshsetup
  script:
    - |
      sftp -i ~/.ssh/id_coverage coveragewww@ivo.thalia.nu -b <<EOF
      -rm ${CI_COMMIT_REF_SLUG}/*
      -rmdir ${CI_COMMIT_REF_SLUG}
      put -r website/covhtml ${CI_COMMIT_REF_SLUG}
      EOF

coverage remove:
    stage: deploy
    when: manual
    image: debian:stretch
    environment:
98
        name: coverage/${CI_COMMIT_REF_NAME}
99 100 101 102 103 104 105 106 107 108
        action: stop
    variables:
        GIT_STRATEGY: none
    <<: *sshsetup
    script:
      - |
        sftp -i ~/.ssh/id_coverage coveragewww@ivo.thalia.nu -b <<EOF
        rm ${CI_COMMIT_REF_SLUG}/*
        rmdir ${CI_COMMIT_REF_SLUG}
        EOF
Thom Wiggers's avatar
Thom Wiggers committed
109

110
docs tests:
Thom Wiggers's avatar
Thom Wiggers committed
111
  stage: test
Thom Wiggers's avatar
Thom Wiggers committed
112
  image: $PY36_IMAGE
Thom Wiggers's avatar
Thom Wiggers committed
113 114
  before_script:
    # install django deps
Jelle Besseling's avatar
Jelle Besseling committed
115
    - poetry install --no-interaction --extras "docs"
Thom Wiggers's avatar
Thom Wiggers committed
116
  script:
Thom Wiggers's avatar
Thom Wiggers committed
117
    - echo "Building current docs"
Jelle Besseling's avatar
Jelle Besseling committed
118 119 120
    - cd docs
    - env -u GITLAB_CI poetry run make doctest
    - env -u GITLAB_CI poetry run sphinx-build -W . _build
Thom Wiggers's avatar
Thom Wiggers committed
121
    - echo "Checking if there are changes"
Jelle Besseling's avatar
Jelle Besseling committed
122
    - poetry run ./generate-apidocs.sh
Thom Wiggers's avatar
Thom Wiggers committed
123
    - git diff --exit-code
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
  artifacts:
    paths:
      - docs/_build

docs deploy:
  stage: deploy
  image: debian:stretch
  dependencies:
    - docs tests
  environment:
    name: docs/${CI_COMMIT_REF_NAME}
    url: https://docs.technicie.nl/${CI_COMMIT_REF_SLUG}/
    on_stop: docs remove
  <<: *sshsetup
  script:
    - |
      sftp -i ~/.ssh/id_docs docswww@ivo.thalia.nu -b <<EOF
      -rm ${CI_COMMIT_REF_SLUG}/*/*
      -rm ${CI_COMMIT_REF_SLUG}/*
      -rmdir ${CI_COMMIT_REF_SLUG}/_images
      -rmdir ${CI_COMMIT_REF_SLUG}/_modules
      -rmdir ${CI_COMMIT_REF_SLUG}/_sources
      -rmdir ${CI_COMMIT_REF_SLUG}/_static
      -rmdir ${CI_COMMIT_REF_SLUG}/doctest
      -rmdir ${CI_COMMIT_REF_SLUG}/doctrees
      -rmdir ${CI_COMMIT_REF_SLUG}
      -mkdir ${CI_COMMIT_REF_SLUG}
      put -r docs/_build/* ${CI_COMMIT_REF_SLUG}
      EOF

docs remove:
  stage: deploy
  when: manual
  image: debian:stretch
  environment:
    name: docs/${CI_COMMIT_REF_NAME}
    action: stop
  variables:
    GIT_STRATEGY: none
  <<: *sshsetup
  script:
    - |
      sftp -i ~/.ssh/id_docs docswww@ivo.thalia.nu -b <<EOF
      rm ${CI_COMMIT_REF_SLUG}/*/*
      rm ${CI_COMMIT_REF_SLUG}/*
      rmdir ${CI_COMMIT_REF_SLUG}/_images
      rmdir ${CI_COMMIT_REF_SLUG}/_modules
      rmdir ${CI_COMMIT_REF_SLUG}/_sources
      rmdir ${CI_COMMIT_REF_SLUG}/_static
      rmdir ${CI_COMMIT_REF_SLUG}/doctest
      rmdir ${CI_COMMIT_REF_SLUG}/doctrees
      rmdir ${CI_COMMIT_REF_SLUG}
      EOF
Thom Wiggers's avatar
Thom Wiggers committed
177

Thom Wiggers's avatar
Thom Wiggers committed
178 179 180 181 182 183 184 185
build docker image:
  stage: test
  services:
    - docker:dind
  image: thalia/docker-compose
  tags:
    - docker
  before_script:
186
    - echo $DOCKER_REGISTRY_PASSWORD | docker login --username thaliawww --password-stdin registry.hub.docker.com
Thom Wiggers's avatar
Thom Wiggers committed
187
  script:
Joren Vrancken's avatar
Joren Vrancken committed
188
    - docker-compose config -q
189
    - docker-compose build --build-arg install_dev_requirements=0 --build-arg source_commit=$(git rev-parse HEAD) web
Thom Wiggers's avatar
Thom Wiggers committed
190 191 192 193
    - docker-compose run --rm web test
    - docker tag $DOCKER_LATEST $DOCKER_TAG
    - docker push $DOCKER_TAG
  variables:
194 195
    DOCKER_LATEST: registry.hub.docker.com/thalia/concrexit:latest
    DOCKER_TAG: registry.hub.docker.com/thalia/concrexit:$CI_COMMIT_SHA
Thom Wiggers's avatar
Thom Wiggers committed
196 197 198 199 200 201 202 203 204 205 206 207 208

tag docker image:
  stage: deploy
  services:
    - docker:dind
  image: docker:git
  tags:
    - docker
  only:
    - tags
  dependencies:
    - build docker image
  before_script:
209
    - echo $DOCKER_REGISTRY_PASSWORD | docker login --username thaliawww --password-stdin registry.hub.docker.com
Thom Wiggers's avatar
Thom Wiggers committed
210 211
  script:
    - docker pull $DOCKER_TAG
Thom Wiggers's avatar
Thom Wiggers committed
212
    - docker tag $DOCKER_TAG $DOCKER_TAG_PRODUCTION
213
    - docker tag $DOCKER_TAG $DOCKER_LATEST
Thom Wiggers's avatar
Thom Wiggers committed
214
    - docker push $DOCKER_TAG_PRODUCTION
215
    - docker push $DOCKER_LATEST
Thom Wiggers's avatar
Thom Wiggers committed
216
  variables:
217 218
    DOCKER_TAG: registry.hub.docker.com/thalia/concrexit:$CI_COMMIT_SHA
    DOCKER_TAG_PRODUCTION: registry.hub.docker.com/thalia/concrexit:$CI_COMMIT_TAG
219
    DOCKER_LATEST: registry.hub.docker.com/thalia/concrexit:latest
Thom Wiggers's avatar
Thom Wiggers committed
220 221


Thom Wiggers's avatar
Thom Wiggers committed
222
cache:
223
  key: "$CI_JOB_NAME"
Thom Wiggers's avatar
Thom Wiggers committed
224
  paths:
Thom Wiggers's avatar
Thom Wiggers committed
225
    - "${PIP_CACHE_DIR}"
Thom Wiggers's avatar
Thom Wiggers committed
226 227

# vim: set sw=2 ts=2 et :