.gitlab-ci.yml 6.24 KB
Newer Older
Tomáš Pecka's avatar
Tomáš Pecka committed
1
stages:
2 3 4
  - prepare
  - build
  - test
5 6
  - docker-build
  - docker-deploy
Tomáš Pecka's avatar
Tomáš Pecka committed
7 8 9 10 11 12 13 14 15
  - notify

.docker: &docker
  cache: {}  # disable
  services:
    - docker:dind
  variables:
    DOCKER_DRIVER: overlay2
    DOCKER_HOST: docker
Tomáš Pecka's avatar
Tomáš Pecka committed
16
  before_script:
Tomáš Pecka's avatar
Tomáš Pecka committed
17
    - apk add --no-cache docker
Tomáš Pecka's avatar
Tomáš Pecka committed
18
    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
Tomáš Pecka's avatar
Tomáš Pecka committed
19 20
    - docker info

21 22 23 24 25
# -----------------------------------------------------------------------------
# smoke builds

prepare:activemqcpp:
  stage: prepare
Tomáš Pecka's avatar
Tomáš Pecka committed
26
  image: gitlab.fit.cvut.cz:5000/algorithms-library-toolkit/infrastructure/ci-docker-images/activemqcpp:latest
27 28 29 30 31 32 33 34 35 36 37 38 39 40
  script:
    - cp -R /usr/local usrlocal
  artifacts:
    paths:
      - usrlocal
    expire_in: 1 hour

build:worker:
  stage: build
  image: gitlab.fit.cvut.cz:5000/algorithms-library-toolkit/automata-library/cli:snapshot
  dependencies:
    - prepare:activemqcpp
  before_script:
    - cp -R usrlocal/* /usr/local
41
    - apk add --no-cache build-base cmake jsoncpp-dev pkgconf apr-dev spdlog-dev catch2
42
    - wget https://github.com/p-ranav/argparse/archive/v2.1.zip && unzip v2.1.zip && cd argparse-2.1 && cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr . && make && make install && cd ..
43 44
  script:
    - mkdir -p worker/build && cd worker/build
45
    - cmake ..
46 47 48 49 50 51
    - make -j$(grep -c processor /proc/cpuinfo)
  artifacts:
    paths:
      - worker/build
    expire_in: 1 hour

Tomáš Pecka's avatar
Tomáš Pecka committed
52 53 54 55 56 57
build:webui:
  stage: build
  image: gitlab.fit.cvut.cz:5000/algorithms-library-toolkit/automata-library/cli:snapshot
  before_script:
    - apk add --no-cache jsoncpp-dev build-base cmake nodejs npm
  script:
58
    - mkdir -p webui/json_generators/build && cd webui/json_generators/build
Tomáš Pecka's avatar
Tomáš Pecka committed
59 60
    - cmake ..
    - make -j$(grep -c processor /proc/cpuinfo)
61 62
    - ./version-json "$CI_COMMIT_SHORT_SHA" > ../../src/static_jsons/version.json
    - ./algorithms-json                     > ../../src/static_jsons/algorithms.json
Tomáš Pecka's avatar
Tomáš Pecka committed
63 64 65 66 67 68
    - cd ../..
    - npm install
    - npm run build
  artifacts:
    paths:
      - webui/build
69
      - webui/src/static_jsons
Tomáš Pecka's avatar
Tomáš Pecka committed
70 71
    expire_in: 1 hour

72 73 74 75 76 77 78 79 80 81 82
# -----------------------------------------------------------------------------
# test

test:worker:
  stage: test
  image: gitlab.fit.cvut.cz:5000/algorithms-library-toolkit/automata-library/cli:snapshot
  dependencies:
    - build:worker
    - prepare:activemqcpp
  before_script:
    - cp -R usrlocal/* /usr/local
Tomáš Pecka's avatar
Tomáš Pecka committed
83
    - apk add --no-cache cmake jsoncpp apr libuuid spdlog
84 85 86 87
  script:
    - cd worker/build
    - ctest --output-on-failure . -j$(grep -c processor /proc/cpuinfo)

88 89
test:worker:clang-format:
  stage: test
Tomáš Pecka's avatar
Tomáš Pecka committed
90
  image: gitlab.fit.cvut.cz:5000/algorithms-library-toolkit/infrastructure/ci-docker-images/alt-builder:latest
91 92
  script:
    - ANCESTOR=$(git merge-base origin/master HEAD) # find nearest common ancestor between HEAD and master
93
    - git diff $ANCESTOR..HEAD | tee orig.patch | /usr/share/clang/clang-format-11/clang-format-diff.py -p1 | sed "s/+++ /+++ b\//    g;s/--- /--- a\//g" > clang-format.patch
94 95 96 97 98 99 100
    - if [[ -s clang-format.patch ]]; then cat clang-format.patch; echo "Download the patch in the artifact directory"; false; fi     # file exists and has nonzero size - fail
  artifacts:
    when: always
    paths:
      - orig.patch
      - clang-format.patch

Tomáš Pecka's avatar
Tomáš Pecka committed
101 102 103 104
test:webui:
  stage: test
  image: alpine:latest
  dependencies:
105
    - build:webui
Tomáš Pecka's avatar
Tomáš Pecka committed
106 107 108 109 110 111 112
  before_script:
    - apk add --no-cache nodejs npm
  script:
    - cd webui
    - npm install
    - CI=true npm test

Tomáš Pecka's avatar
Tomáš Pecka committed
113
# -----------------------------------------------------------------------------
114
# build docker images
Tomáš Pecka's avatar
Tomáš Pecka committed
115

116
.docker-build:
Tomáš Pecka's avatar
Tomáš Pecka committed
117
  <<: *docker
118
  stage: docker-build
Tomáš Pecka's avatar
Tomáš Pecka committed
119 120
  script:
    - SERVICE="$(echo $CI_JOB_NAME | cut -d':' -f2)"
121 122 123 124 125 126 127 128
    - TAG="ci-$CI_COMMIT_SHORT_SHA"
    - IMAGE="${CI_REGISTRY_IMAGE}/${SERVICE}"
    - docker build -f $DOCKERFILE $CONTEXT -t "${IMAGE}:${TAG}" --target $TARGET --build-arg VERSION=$CI_COMMIT_SHORT_SHA
    - docker save -o images.tar "${IMAGE}:${TAG}"
  artifacts:
    paths:
      - images.tar
    expire_in: 1 hour
Tomáš Pecka's avatar
Tomáš Pecka committed
129

130 131
docker-build:server:
  extends: .docker-build
Tomáš Pecka's avatar
Tomáš Pecka committed
132 133 134 135
  variables:
    DOCKERFILE: "server/Dockerfile"
    CONTEXT: "."
    TARGET: "alib_web_server"
Tomáš Pecka's avatar
Tomáš Pecka committed
136

137 138
docker-build:client:
  extends: .docker-build
Tomáš Pecka's avatar
Tomáš Pecka committed
139 140 141 142
  variables:
    DOCKERFILE: "webui/Dockerfile"
    CONTEXT: "."
    TARGET: "webui"
Tomáš Pecka's avatar
Tomáš Pecka committed
143

144 145
docker-build:worker:
  extends: .docker-build
Tomáš Pecka's avatar
Tomáš Pecka committed
146 147 148 149 150
  variables:
    DOCKERFILE: "worker/Dockerfile"
    CONTEXT: "."
    TARGET: "alib_web_worker"

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 177 178 179 180 181 182 183 184 185 186 187 188 189 190
# -----------------------------------------------------------------------------
# deploy docker images

.docker-deploy:
  <<: *docker
  stage: docker-deploy
  script:
    - SERVICE="$(echo $CI_JOB_NAME | cut -d':' -f2)"
    - OLDTAG="ci-${CI_COMMIT_SHORT_SHA}"
    - TAG="$(echo $CI_JOB_NAME | cut -d':' -f3)"
    - IMAGE="${CI_REGISTRY_IMAGE}/${SERVICE}"
    - docker load -i images.tar
    - docker tag "${IMAGE}:${OLDTAG}" "${IMAGE}:${TAG}"
    - docker push "${IMAGE}:${TAG}"

.docker-deploy:latest: &docker-deploy-latest
  only:
    - master
.docker-deploy:staging: &docker-deploy-staging
  only:
    - staging

.docker-deploy:server:
  extends: .docker-deploy
  dependencies:
    - docker-build:server

.docker-deploy:client:
  extends: .docker-deploy
  dependencies:
    - docker-build:client

.docker-deploy:worker:
  extends: .docker-deploy
  dependencies:
    - docker-build:worker

docker-deploy:server:latest:
  <<: *docker-deploy-latest
  extends: .docker-deploy:server
Tomáš Pecka's avatar
Tomáš Pecka committed
191

192 193 194
docker-deploy:server:staging:
  <<: *docker-deploy-staging
  extends: .docker-deploy:server
Tomáš Pecka's avatar
Tomáš Pecka committed
195

196 197 198
docker-deploy:client:latest:
  <<: *docker-deploy-latest
  extends: .docker-deploy:client
Tomáš Pecka's avatar
Tomáš Pecka committed
199

200 201 202
docker-deploy:client:staging:
  <<: *docker-deploy-staging
  extends: .docker-deploy:client
Tomáš Pecka's avatar
Tomáš Pecka committed
203

204 205 206
docker-deploy:worker:latest:
  <<: *docker-deploy-latest
  extends: .docker-deploy:worker
Tomáš Pecka's avatar
Tomáš Pecka committed
207

208 209 210
docker-deploy:worker:staging:
  <<: *docker-deploy-staging
  extends: .docker-deploy:worker
Tomáš Pecka's avatar
Tomáš Pecka committed
211 212


Tomáš Pecka's avatar
Tomáš Pecka committed
213 214 215 216 217 218 219 220
# -----------------------------------------------------------------------------
# notify

.notify:
  stage: notify
  before_script:
    - apk add --no-cache curl
  dependencies: []
Tomáš Pecka's avatar
Tomáš Pecka committed
221
  script:
Tomáš Pecka's avatar
Tomáš Pecka committed
222 223 224 225 226 227 228 229 230 231 232
    - curl -X POST -F token="$TOKEN" -F ref=master https://gitlab.fit.cvut.cz/api/v4/projects/$PROJECT_ID/trigger/pipeline

# -----------------------------------------------------------------------------

notify:altvm:
  extends: .notify
  variables:
    TOKEN: "$TOKEN_TRIGGER_ALTVM"
    PROJECT_ID: "22206"
  only:
    - master
Tomáš Pecka's avatar
Tomáš Pecka committed
233
    - staging