| Marc Kupietz | ffd6d2a | 2026-08-21 12:29:32 +0200 | [diff] [blame] | 1 | # The build needs root, for apt-get, and a perl with cpanm. metacpan/metacpan-api |
| 2 | # used to provide both, but it runs as an unprivileged user now, where apt-get |
| 3 | # fails with "Permission denied" and cmake never gets installed. Pinned to the |
| 4 | # distribution as well, so that an upstream rebuild cannot move rocksdb under us. |
| 5 | image: perl:5.40-trixie |
| Marc Kupietz | 5b6a51e | 2022-04-11 21:23:30 +0200 | [diff] [blame] | 6 | |
| Marc Kupietz | 18d7835 | 2024-02-20 20:55:54 +0100 | [diff] [blame] | 7 | variables: |
| 8 | # Set `CCACHE_BASEDIR` and `CCACHE_DIR` to point `ccache` towards the cached |
| 9 | # path on the gitlab-runner. This enables to cache the output of `ccache` |
| 10 | # between various runs. |
| 11 | CCACHE_BASEDIR: "${CI_PROJECT_DIR}" |
| 12 | CCACHE_DIR: "${CI_PROJECT_DIR}/ccache" |
| 13 | # Set `ccache` to `content` to prevent rebuilding of the CI/CD containers to |
| 14 | # trigger a recreate of the cache. By using `content` the compiler's `mtime` |
| 15 | # is not considered as part of the hash. |
| 16 | CCACHE_COMPILERCHECK: "content" |
| 17 | # Enable caching for `apt-get`. |
| 18 | APT_CACHE_DIR: "${CI_PROJECT_DIR}/apt-cache" |
| 19 | # Export `noninteractive` frontend to prevent requesting user input. |
| 20 | DEBIAN_FRONTEND: "noninteractive" |
| 21 | PERL_LOCAL_LIB_ROOT: ./perl5 |
| 22 | PERL5LIB: ./perl5/lib/perl5 |
| 23 | |
| Marc Kupietz | 5b6a51e | 2022-04-11 21:23:30 +0200 | [diff] [blame] | 24 | build-and-test: |
| 25 | stage: build |
| Marc Kupietz | 18d7835 | 2024-02-20 20:55:54 +0100 | [diff] [blame] | 26 | cache: |
| Marc Kupietz | ffd6d2a | 2026-08-21 12:29:32 +0200 | [diff] [blame] | 27 | # Cache is shared between branches, but has a unique cache per job. The |
| 28 | # image is part of the key: perl5/ holds what cpanm decided was missing in |
| 29 | # that image, so a cache from another one is incomplete. |
| 30 | key: derekovecs-perl-5.40-trixie |
| Marc Kupietz | 18d7835 | 2024-02-20 20:55:54 +0100 | [diff] [blame] | 31 | paths: |
| 32 | # Note: directories should align with `$APT_CACHE_DIR` and `$CCACHE_DIR`. |
| 33 | - apt-cache/ |
| 34 | - ccache/ |
| 35 | - perl5/ |
| Marc Kupietz | 5b6a51e | 2022-04-11 21:23:30 +0200 | [diff] [blame] | 36 | before_script: |
| 37 | - pwd |
| 38 | - source `find .. -name section_helper.sh` |
| 39 | |
| 40 | - start_section install_linux_packages "Installing missing Linux packages" |
| Marc Kupietz | 18d7835 | 2024-02-20 20:55:54 +0100 | [diff] [blame] | 41 | - mkdir -pv $APT_CACHE_DIR ccache |
| Marc Kupietz | 96972c6 | 2026-07-31 09:50:14 +0900 | [diff] [blame] | 42 | - apt-get update && apt-get -o dir::cache::archives="$APT_CACHE_DIR" -y install ccache cmake librocksdb-dev libgflags-dev libsnappy-dev zlib1g-dev libbz2-dev liblz4-dev libzstd-dev libomp-dev |
| Marc Kupietz | 25ab170 | 2026-07-30 16:19:57 +0900 | [diff] [blame] | 43 | # ccache only makes the build faster, it must never be able to make it fail, |
| 44 | # so everything that uses it is guarded and CCACHE_OPTS stays empty without it |
| Marc Kupietz | ffd6d2a | 2026-08-21 12:29:32 +0200 | [diff] [blame] | 45 | # a failed package install used to show up much later as "cmake: command |
| 46 | # not found" in the middle of the collocatordb build |
| 47 | - command -v cmake > /dev/null || { echo "cmake is missing, the package installation did not work"; exit 1; } |
| Marc Kupietz | 25ab170 | 2026-07-30 16:19:57 +0900 | [diff] [blame] | 48 | - if CCACHE=$(command -v ccache); then ln -sf "$CCACHE" /usr/local/sbin/gcc && ln -sf "$CCACHE" /usr/local/sbin/g++ && CCACHE_OPTS="-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache"; else echo "ccache is not available - building without it"; CCACHE_OPTS=""; fi |
| Marc Kupietz | 5b6a51e | 2022-04-11 21:23:30 +0200 | [diff] [blame] | 49 | - end_section install_linux_packages |
| 50 | |
| Marc Kupietz | 5b6a51e | 2022-04-11 21:23:30 +0200 | [diff] [blame] | 51 | - start_section install_collocatordb "Building and installing collocatordb" |
| Marc Kupietz | a7afe93 | 2022-05-19 09:21:03 +0200 | [diff] [blame] | 52 | - git clone "https://korap.ids-mannheim.de/gerrit/ids-kl/collocatordb" |
| Marc Kupietz | 5b6a51e | 2022-04-11 21:23:30 +0200 | [diff] [blame] | 53 | - cd collocatordb |
| 54 | - mkdir -p build |
| 55 | - cd build |
| Marc Kupietz | 25ab170 | 2026-07-30 16:19:57 +0900 | [diff] [blame] | 56 | - cmake $CCACHE_OPTS .. |
| Marc Kupietz | 5b6a51e | 2022-04-11 21:23:30 +0200 | [diff] [blame] | 57 | - make |
| Marc Kupietz | 25ab170 | 2026-07-30 16:19:57 +0900 | [diff] [blame] | 58 | - command -v ccache > /dev/null && ccache --show-stats || true |
| Marc Kupietz | 5b6a51e | 2022-04-11 21:23:30 +0200 | [diff] [blame] | 59 | - make install # && ctest --extra-verbose |
| 60 | - ldconfig |
| 61 | - end_section install_collocatordb |
| 62 | - cd ../.. |
| 63 | |
| 64 | script: |
| 65 | - start_section build_perl_dependencies "Installing Perl dependencies" |
| Marc Kupietz | 18d7835 | 2024-02-20 20:55:54 +0100 | [diff] [blame] | 66 | - cpanm -n -l $PERL_LOCAL_LIB_ROOT https://github.com/Akron/Mojolicious-Plugin-Localize.git |
| Marc Kupietz | e20daf1 | 2026-07-31 09:55:55 +0900 | [diff] [blame] | 67 | # Devel::CheckLib, which Makefile.PL needs to find libcollocatordb before it |
| 68 | # can tell anybody about the dependencies, comes bundled in inc/ |
| Marc Kupietz | 18d7835 | 2024-02-20 20:55:54 +0100 | [diff] [blame] | 69 | - cpanm -n -l $PERL_LOCAL_LIB_ROOT --installdeps . |
| Marc Kupietz | 5b6a51e | 2022-04-11 21:23:30 +0200 | [diff] [blame] | 70 | - end_section build_perl_dependencies |
| 71 | |
| 72 | - start_section build_derekovecs-server "Building DeReKoVecs server" |
| 73 | - perl Makefile.PL |
| 74 | - make |
| 75 | - make install |
| 76 | - end_section build_derekovecs-server |
| 77 | |
| Marc Kupietz | 3e3e326 | 2022-04-12 23:11:45 +0200 | [diff] [blame] | 78 | - start_section run_derekovecs-server "Testing DeReKoVecs server" |
| Marc Kupietz | ffd6d2a | 2026-08-21 12:29:32 +0200 | [diff] [blame] | 79 | # the server test starts morbo, which cpanm installed into the local lib |
| 80 | - export PATH="$CI_PROJECT_DIR/perl5/bin:$PATH" |
| Marc Kupietz | 3e3e326 | 2022-04-12 23:11:45 +0200 | [diff] [blame] | 81 | - prove --verbose t |
| Marc Kupietz | 5b6a51e | 2022-04-11 21:23:30 +0200 | [diff] [blame] | 82 | - end_section run_derekovecs-server |
| 83 | |
| Marc Kupietz | ddba908 | 2023-11-06 06:59:14 +0100 | [diff] [blame] | 84 | deploy: |
| 85 | rules: |
| 86 | - if: $CI_COMMIT_TAG =~ /.+/ |
| 87 | variables: |
| 88 | VID: $CI_COMMIT_TAG |
| 89 | - when: manual |
| 90 | variables: |
| 91 | VID: $CI_COMMIT_BRANCH-$CI_COMMIT_SHORT_SHA |
| 92 | stage: deploy |
| 93 | before_script: |
| 94 | - source `find .. -name section_helper.sh` |
| 95 | - start_section install_linux_packages "Installing missing Linux packages" |
| 96 | - 'command -v ssh-agent >/dev/null || apt-get install openssh-client -y' |
| 97 | - mkdir -p ~/.ssh |
| 98 | - chmod 700 ~/.ssh |
| 99 | - eval $(ssh-agent -s) |
| 100 | - chmod 400 "$SSH_PRIVATE_KEY" |
| 101 | - ssh-add "$SSH_PRIVATE_KEY" |
| 102 | - end_section install_linux_packages |
| 103 | script: |
| 104 | - echo "This is a manual job which doesn't start automatically, and the pipeline can complete without it starting." |
| 105 | - ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $DEPLOY_HOST "cd /opt/korap/derekovecs && git stash && git pull && cpanm --installdeps . && cpanm . && rm -rf _Inline && sudo systemctl restart derekovecs" |
| Marc Kupietz | 10ccb98 | 2024-09-12 14:15:13 +0200 | [diff] [blame] | 106 | |
| 107 | build-docker: |
| 108 | image: docker:latest |
| Marc Kupietz | 211fff4 | 2026-07-31 10:31:10 +0900 | [diff] [blame] | 109 | variables: |
| 110 | # the mint container has to reach the container it probes |
| 111 | FF_NETWORK_PER_BUILD: "true" |
| Marc Kupietz | 10ccb98 | 2024-09-12 14:15:13 +0200 | [diff] [blame] | 112 | services: |
| Marc Kupietz | 211fff4 | 2026-07-31 10:31:10 +0900 | [diff] [blame] | 113 | - name: docker:dind |
| 114 | command: [--dns=127.0.0.11] |
| Marc Kupietz | 10ccb98 | 2024-09-12 14:15:13 +0200 | [diff] [blame] | 115 | rules: |
| 116 | - if: $CI_COMMIT_TAG =~ /.+/ |
| 117 | variables: |
| 118 | VID: $CI_COMMIT_TAG |
| 119 | - when: manual |
| 120 | variables: |
| 121 | VID: $CI_COMMIT_BRANCH-$CI_COMMIT_SHORT_SHA |
| 122 | stage: build |
| 123 | before_script: |
| Marc Kupietz | 10ccb98 | 2024-09-12 14:15:13 +0200 | [diff] [blame] | 124 | - apk update |
| 125 | - apk add --no-cache git |
| 126 | script: |
| Marc Kupietz | 211fff4 | 2026-07-31 10:31:10 +0900 | [diff] [blame] | 127 | # the http probe needs a model to serve, so keep the example models in the |
| 128 | # large image and remove them further down with Dockerfile.remove-example-data |
| Marc Kupietz | 10ccb98 | 2024-09-12 14:15:13 +0200 | [diff] [blame] | 129 | - sed -i -e "s/RUN rm -rf example-models//" Dockerfile |
| Marc Kupietz | 10ccb98 | 2024-09-12 14:15:13 +0200 | [diff] [blame] | 130 | - docker build -f Dockerfile -t idscorpuslinguistics/derekovecs:$VID-large . |
| Marc Kupietz | 211fff4 | 2026-07-31 10:31:10 +0900 | [diff] [blame] | 131 | - docker run --rm -v /var/run/docker.sock:/var/run/docker.sock mintoolkit/mint --crt-api-version 1.46 build --http-probe=true --http-probe-start-wait 60 --include-workdir=true --include-path=/usr/local --env MOJO_CONFIG=/derekovecs/example-models/example-docker.conf --tag idscorpuslinguistics/derekovecs:tmp idscorpuslinguistics/derekovecs:$VID-large || true |
| Marc Kupietz | 10ccb98 | 2024-09-12 14:15:13 +0200 | [diff] [blame] | 132 | - docker build -f Dockerfile.remove-example-data --tag idscorpuslinguistics/derekovecs:latest --tag idscorpuslinguistics/derekovecs:$VID . |
| Marc Kupietz | 211fff4 | 2026-07-31 10:31:10 +0900 | [diff] [blame] | 133 | - ARTIFACT=derekovecs-${VID}.tar.xz |
| 134 | - docker save idscorpuslinguistics/derekovecs:$VID | xz -T0 -M16G -9 > "$ARTIFACT" |
| Marc Kupietz | 10ccb98 | 2024-09-12 14:15:13 +0200 | [diff] [blame] | 135 | artifacts: |
| 136 | paths: |
| Marc Kupietz | 211fff4 | 2026-07-31 10:31:10 +0900 | [diff] [blame] | 137 | - derekovecs-*.tar.xz |
| Marc Kupietz | a9923bd | 2024-09-13 14:49:45 +0200 | [diff] [blame] | 138 | |
| 139 | upload-docker: |
| Marc Kupietz | a9923bd | 2024-09-13 14:49:45 +0200 | [diff] [blame] | 140 | stage: deploy |
| 141 | image: docker:latest |
| 142 | services: |
| Marc Kupietz | 211fff4 | 2026-07-31 10:31:10 +0900 | [diff] [blame] | 143 | - name: docker:dind |
| 144 | command: [--dns=127.0.0.11] |
| 145 | needs: |
| 146 | - job: build-docker |
| 147 | artifacts: true |
| Marc Kupietz | a9923bd | 2024-09-13 14:49:45 +0200 | [diff] [blame] | 148 | dependencies: |
| 149 | - build-docker |
| Marc Kupietz | 211fff4 | 2026-07-31 10:31:10 +0900 | [diff] [blame] | 150 | rules: |
| 151 | - if: $CI_COMMIT_TAG =~ /^v.+/ |
| 152 | when: manual |
| 153 | - when: never |
| 154 | script: |
| 155 | - apk update |
| 156 | - apk add --no-cache xz |
| 157 | - ARTIFACT=derekovecs-${CI_COMMIT_TAG}.tar.xz |
| 158 | - xz -d -c "$ARTIFACT" | docker load |
| 159 | - echo "$DOCKER_HUB_PASSWORD" | docker login -u "$DOCKER_HUB_USERNAME" --password-stdin |
| 160 | - docker tag idscorpuslinguistics/derekovecs:$CI_COMMIT_TAG idscorpuslinguistics/derekovecs:latest |
| 161 | - docker push idscorpuslinguistics/derekovecs:$CI_COMMIT_TAG |
| 162 | - docker push idscorpuslinguistics/derekovecs:latest |
| Marc Kupietz | a9923bd | 2024-09-13 14:49:45 +0200 | [diff] [blame] | 163 | environment: |
| 164 | name: production |