blob: 8a0d1c1481ae4ccd114c23a943b2f0282ef8043b [file] [log] [blame]
Marc Kupietz5b6a51e2022-04-11 21:23:30 +02001image: metacpan/metacpan-api
2
Marc Kupietz18d78352024-02-20 20:55:54 +01003variables:
4 # Set `CCACHE_BASEDIR` and `CCACHE_DIR` to point `ccache` towards the cached
5 # path on the gitlab-runner. This enables to cache the output of `ccache`
6 # between various runs.
7 CCACHE_BASEDIR: "${CI_PROJECT_DIR}"
8 CCACHE_DIR: "${CI_PROJECT_DIR}/ccache"
9 # Set `ccache` to `content` to prevent rebuilding of the CI/CD containers to
10 # trigger a recreate of the cache. By using `content` the compiler's `mtime`
11 # is not considered as part of the hash.
12 CCACHE_COMPILERCHECK: "content"
13 # Enable caching for `apt-get`.
14 APT_CACHE_DIR: "${CI_PROJECT_DIR}/apt-cache"
15 # Export `noninteractive` frontend to prevent requesting user input.
16 DEBIAN_FRONTEND: "noninteractive"
17 PERL_LOCAL_LIB_ROOT: ./perl5
18 PERL5LIB: ./perl5/lib/perl5
19
Marc Kupietz5b6a51e2022-04-11 21:23:30 +020020build-and-test:
21 stage: build
Marc Kupietz18d78352024-02-20 20:55:54 +010022 cache:
23 # Cache is shared between branches, but has a unique cache per job.
24 key: derekovecs
25 paths:
26 # Note: directories should align with `$APT_CACHE_DIR` and `$CCACHE_DIR`.
27 - apt-cache/
28 - ccache/
29 - perl5/
Marc Kupietz5b6a51e2022-04-11 21:23:30 +020030 before_script:
31 - pwd
32 - source `find .. -name section_helper.sh`
33
34 - start_section install_linux_packages "Installing missing Linux packages"
Marc Kupietz18d78352024-02-20 20:55:54 +010035 - mkdir -pv $APT_CACHE_DIR ccache
36 - apt-get update && apt-get -o dir::cache::archives="$APT_CACHE_DIR" -y install ccache cmake libgflags-dev libsnappy-dev zlib1g-dev libbz2-dev liblz4-dev libzstd-dev libomp-dev
Marc Kupietz25ab1702026-07-30 16:19:57 +090037 # ccache only makes the build faster, it must never be able to make it fail,
38 # so everything that uses it is guarded and CCACHE_OPTS stays empty without it
39 - 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 +020040 - end_section install_linux_packages
41
42 - start_section install_rocksdb_static "Building and installing rocksdb-static"
Marc Kupietzd196a6f2024-08-05 22:18:20 +020043 - git clone https://github.com/kupietz/rocksdb.git -b 5.11.fb --single-branch
44 - cd rocksdb
Marc Kupietz3e3e3262022-04-12 23:11:45 +020045 - export PROCS=$(nproc)
Marc Kupietz5b6a51e2022-04-11 21:23:30 +020046 - make -j $PROCS static_lib DISABLE_WARNING_AS_ERROR=1 WARNING_FLAGS=-w
Marc Kupietz25ab1702026-07-30 16:19:57 +090047 - command -v ccache > /dev/null && ccache --show-stats || true
Marc Kupietz5b6a51e2022-04-11 21:23:30 +020048 - make install-static DISABLE_WARNING_AS_ERROR=1 WARNING_FLAGS=-w
49 - end_section install_rocksdb_static
50
51 - start_section install_rocksdb_shared "Building and installing rocksdb-shared"
52 - make -j $PROCS shared_lib DISABLE_WARNING_AS_ERROR=1 WARNING_FLAGS=-w
53 - make install-shared DISABLE_WARNING_AS_ERROR=1 WARNING_FLAGS=-w
54 - ldconfig
55 - cd ..
56 - end_section rocksdb_shared
57
58 - start_section install_collocatordb "Building and installing collocatordb"
Marc Kupietza7afe932022-05-19 09:21:03 +020059 - git clone "https://korap.ids-mannheim.de/gerrit/ids-kl/collocatordb"
Marc Kupietz5b6a51e2022-04-11 21:23:30 +020060 - cd collocatordb
61 - mkdir -p build
62 - cd build
Marc Kupietz25ab1702026-07-30 16:19:57 +090063 - cmake $CCACHE_OPTS ..
Marc Kupietz5b6a51e2022-04-11 21:23:30 +020064 - make
Marc Kupietz25ab1702026-07-30 16:19:57 +090065 - command -v ccache > /dev/null && ccache --show-stats || true
Marc Kupietz5b6a51e2022-04-11 21:23:30 +020066 - make install # && ctest --extra-verbose
67 - ldconfig
68 - end_section install_collocatordb
69 - cd ../..
70
71 script:
72 - start_section build_perl_dependencies "Installing Perl dependencies"
Marc Kupietz18d78352024-02-20 20:55:54 +010073 - cpanm -n -l $PERL_LOCAL_LIB_ROOT https://github.com/Akron/Mojolicious-Plugin-Localize.git
Marc Kupietz59c05362026-07-31 07:58:10 +090074 # Makefile.PL uses Devel::CheckLib to look for libcollocatordb, so it has to
75 # be there before --installdeps can determine the dependencies at all
76 - cpanm -n -l $PERL_LOCAL_LIB_ROOT Devel::CheckLib
Marc Kupietz18d78352024-02-20 20:55:54 +010077 - cpanm -n -l $PERL_LOCAL_LIB_ROOT --installdeps .
Marc Kupietz5b6a51e2022-04-11 21:23:30 +020078 - end_section build_perl_dependencies
79
80 - start_section build_derekovecs-server "Building DeReKoVecs server"
81 - perl Makefile.PL
82 - make
83 - make install
84 - end_section build_derekovecs-server
85
Marc Kupietz3e3e3262022-04-12 23:11:45 +020086 - start_section run_derekovecs-server "Testing DeReKoVecs server"
87 - prove --verbose t
Marc Kupietz5b6a51e2022-04-11 21:23:30 +020088 - end_section run_derekovecs-server
89
Marc Kupietzddba9082023-11-06 06:59:14 +010090deploy:
91 rules:
92 - if: $CI_COMMIT_TAG =~ /.+/
93 variables:
94 VID: $CI_COMMIT_TAG
95 - when: manual
96 variables:
97 VID: $CI_COMMIT_BRANCH-$CI_COMMIT_SHORT_SHA
98 stage: deploy
99 before_script:
100 - source `find .. -name section_helper.sh`
101 - start_section install_linux_packages "Installing missing Linux packages"
102 - 'command -v ssh-agent >/dev/null || apt-get install openssh-client -y'
103 - mkdir -p ~/.ssh
104 - chmod 700 ~/.ssh
105 - eval $(ssh-agent -s)
106 - chmod 400 "$SSH_PRIVATE_KEY"
107 - ssh-add "$SSH_PRIVATE_KEY"
108 - end_section install_linux_packages
109 script:
110 - echo "This is a manual job which doesn't start automatically, and the pipeline can complete without it starting."
111 - 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 +0200112
113build-docker:
114 image: docker:latest
115 services:
116 - docker:dind
117 rules:
118 - if: $CI_COMMIT_TAG =~ /.+/
119 variables:
120 VID: $CI_COMMIT_TAG
121 - when: manual
122 variables:
123 VID: $CI_COMMIT_BRANCH-$CI_COMMIT_SHORT_SHA
124 stage: build
125 before_script:
Marc Kupietz10ccb982024-09-12 14:15:13 +0200126 - apk update
127 - apk add --no-cache git
128 script:
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 .
131 - wget https://github.com/slimtoolkit/slim/releases/latest/download/dist_linux.tar.gz
132 - tar zxf dist_linux.tar.gz
133 - export PATH=$(pwd)/dist_linux:$PATH
Marc Kupietze82c7a02024-09-13 14:49:26 +0200134 - docker run --rm -v /var/run/docker.sock:/var/run/docker.sock dslim/slim --in-container build --http-probe-start-wait 10 --include-workdir --include-path /usr/local --env MOJO_CONFIG=/derekovecs/example-models/example-docker.conf --tag idscorpuslinguistics/derekovecs:tmp idscorpuslinguistics/derekovecs:$VID-large
Marc Kupietz10ccb982024-09-12 14:15:13 +0200135 - docker build -f Dockerfile.remove-example-data --tag idscorpuslinguistics/derekovecs:latest --tag idscorpuslinguistics/derekovecs:$VID .
136 - docker save idscorpuslinguistics/derekovecs:$VID | xz -T0 -M16G -9 > derekovecs.tar.xz
137 artifacts:
138 paths:
139 - derekovecs.tar.xz
Marc Kupietza9923bd2024-09-13 14:49:45 +0200140
141upload-docker:
142 only:
143 - master
144 - tags
145 variables:
146 VID: $CI_COMMIT_TAG
147 stage: deploy
148 image: docker:latest
149 services:
150 - docker:dind
151 script:
Marc Kupietza9923bd2024-09-13 14:49:45 +0200152 - unxz -c derekovecs.tar.xz | docker load
153 - echo "$DOCKER_HUB_PASSWORD" | docker login -u "$DOCKER_HUB_USERNAME" --password-stdin
154 - docker push idscorpuslinguistics/derekovecs:$VID
Marc Kupietz46b35282024-09-13 19:24:52 +0200155 - docker push idscorpuslinguistics/derekovecs
Marc Kupietza9923bd2024-09-13 14:49:45 +0200156 dependencies:
157 - build-docker
158 environment:
159 name: production