blob: 754e65deb73b1f542353a36b70e6350794a03128 [file] [log] [blame]
Marc Kupietzffd6d2a2026-08-21 12:29:32 +02001# 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.
5image: perl:5.40-trixie
Marc Kupietz5b6a51e2022-04-11 21:23:30 +02006
Marc Kupietz18d78352024-02-20 20:55:54 +01007variables:
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 Kupietz5b6a51e2022-04-11 21:23:30 +020024build-and-test:
25 stage: build
Marc Kupietz18d78352024-02-20 20:55:54 +010026 cache:
Marc Kupietzffd6d2a2026-08-21 12:29:32 +020027 # 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 Kupietz18d78352024-02-20 20:55:54 +010031 paths:
32 # Note: directories should align with `$APT_CACHE_DIR` and `$CCACHE_DIR`.
33 - apt-cache/
34 - ccache/
35 - perl5/
Marc Kupietz5b6a51e2022-04-11 21:23:30 +020036 before_script:
37 - pwd
38 - source `find .. -name section_helper.sh`
39
40 - start_section install_linux_packages "Installing missing Linux packages"
Marc Kupietz18d78352024-02-20 20:55:54 +010041 - mkdir -pv $APT_CACHE_DIR ccache
Marc Kupietz96972c62026-07-31 09:50:14 +090042 - 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 Kupietz25ab1702026-07-30 16:19:57 +090043 # 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 Kupietzffd6d2a2026-08-21 12:29:32 +020045 # 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 Kupietz25ab1702026-07-30 16:19:57 +090048 - 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 Kupietz5b6a51e2022-04-11 21:23:30 +020049 - end_section install_linux_packages
50
Marc Kupietz5b6a51e2022-04-11 21:23:30 +020051 - start_section install_collocatordb "Building and installing collocatordb"
Marc Kupietza7afe932022-05-19 09:21:03 +020052 - git clone "https://korap.ids-mannheim.de/gerrit/ids-kl/collocatordb"
Marc Kupietz5b6a51e2022-04-11 21:23:30 +020053 - cd collocatordb
54 - mkdir -p build
55 - cd build
Marc Kupietz25ab1702026-07-30 16:19:57 +090056 - cmake $CCACHE_OPTS ..
Marc Kupietz5b6a51e2022-04-11 21:23:30 +020057 - make
Marc Kupietz25ab1702026-07-30 16:19:57 +090058 - command -v ccache > /dev/null && ccache --show-stats || true
Marc Kupietz5b6a51e2022-04-11 21:23:30 +020059 - 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 Kupietz18d78352024-02-20 20:55:54 +010066 - cpanm -n -l $PERL_LOCAL_LIB_ROOT https://github.com/Akron/Mojolicious-Plugin-Localize.git
Marc Kupietze20daf12026-07-31 09:55:55 +090067 # Devel::CheckLib, which Makefile.PL needs to find libcollocatordb before it
68 # can tell anybody about the dependencies, comes bundled in inc/
Marc Kupietz18d78352024-02-20 20:55:54 +010069 - cpanm -n -l $PERL_LOCAL_LIB_ROOT --installdeps .
Marc Kupietz5b6a51e2022-04-11 21:23:30 +020070 - 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 Kupietz3e3e3262022-04-12 23:11:45 +020078 - start_section run_derekovecs-server "Testing DeReKoVecs server"
Marc Kupietzffd6d2a2026-08-21 12:29:32 +020079 # the server test starts morbo, which cpanm installed into the local lib
80 - export PATH="$CI_PROJECT_DIR/perl5/bin:$PATH"
Marc Kupietz3e3e3262022-04-12 23:11:45 +020081 - prove --verbose t
Marc Kupietz5b6a51e2022-04-11 21:23:30 +020082 - end_section run_derekovecs-server
83
Marc Kupietzddba9082023-11-06 06:59:14 +010084deploy:
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 Kupietz10ccb982024-09-12 14:15:13 +0200106
107build-docker:
108 image: docker:latest
Marc Kupietz211fff42026-07-31 10:31:10 +0900109 variables:
110 # the mint container has to reach the container it probes
111 FF_NETWORK_PER_BUILD: "true"
Marc Kupietz10ccb982024-09-12 14:15:13 +0200112 services:
Marc Kupietz211fff42026-07-31 10:31:10 +0900113 - name: docker:dind
114 command: [--dns=127.0.0.11]
Marc Kupietz10ccb982024-09-12 14:15:13 +0200115 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 Kupietz10ccb982024-09-12 14:15:13 +0200124 - apk update
125 - apk add --no-cache git
126 script:
Marc Kupietz211fff42026-07-31 10:31:10 +0900127 # 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 Kupietz10ccb982024-09-12 14:15:13 +0200129 - sed -i -e "s/RUN rm -rf example-models//" Dockerfile
Marc Kupietz10ccb982024-09-12 14:15:13 +0200130 - docker build -f Dockerfile -t idscorpuslinguistics/derekovecs:$VID-large .
Marc Kupietz211fff42026-07-31 10:31:10 +0900131 - 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 Kupietz10ccb982024-09-12 14:15:13 +0200132 - docker build -f Dockerfile.remove-example-data --tag idscorpuslinguistics/derekovecs:latest --tag idscorpuslinguistics/derekovecs:$VID .
Marc Kupietz211fff42026-07-31 10:31:10 +0900133 - ARTIFACT=derekovecs-${VID}.tar.xz
134 - docker save idscorpuslinguistics/derekovecs:$VID | xz -T0 -M16G -9 > "$ARTIFACT"
Marc Kupietz10ccb982024-09-12 14:15:13 +0200135 artifacts:
136 paths:
Marc Kupietz211fff42026-07-31 10:31:10 +0900137 - derekovecs-*.tar.xz
Marc Kupietza9923bd2024-09-13 14:49:45 +0200138
139upload-docker:
Marc Kupietza9923bd2024-09-13 14:49:45 +0200140 stage: deploy
141 image: docker:latest
142 services:
Marc Kupietz211fff42026-07-31 10:31:10 +0900143 - name: docker:dind
144 command: [--dns=127.0.0.11]
145 needs:
146 - job: build-docker
147 artifacts: true
Marc Kupietza9923bd2024-09-13 14:49:45 +0200148 dependencies:
149 - build-docker
Marc Kupietz211fff42026-07-31 10:31:10 +0900150 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 Kupietza9923bd2024-09-13 14:49:45 +0200163 environment:
164 name: production