blob: 6c275ec21089fb3858f4a5962b0a2f60f6c0bfd9 [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
Marc Kupietz96972c62026-07-31 09:50:14 +090036 - 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 +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
Marc Kupietz5b6a51e2022-04-11 21:23:30 +020042 - start_section install_collocatordb "Building and installing collocatordb"
Marc Kupietza7afe932022-05-19 09:21:03 +020043 - git clone "https://korap.ids-mannheim.de/gerrit/ids-kl/collocatordb"
Marc Kupietz5b6a51e2022-04-11 21:23:30 +020044 - cd collocatordb
45 - mkdir -p build
46 - cd build
Marc Kupietz25ab1702026-07-30 16:19:57 +090047 - cmake $CCACHE_OPTS ..
Marc Kupietz5b6a51e2022-04-11 21:23:30 +020048 - make
Marc Kupietz25ab1702026-07-30 16:19:57 +090049 - command -v ccache > /dev/null && ccache --show-stats || true
Marc Kupietz5b6a51e2022-04-11 21:23:30 +020050 - make install # && ctest --extra-verbose
51 - ldconfig
52 - end_section install_collocatordb
53 - cd ../..
54
55 script:
56 - start_section build_perl_dependencies "Installing Perl dependencies"
Marc Kupietz18d78352024-02-20 20:55:54 +010057 - cpanm -n -l $PERL_LOCAL_LIB_ROOT https://github.com/Akron/Mojolicious-Plugin-Localize.git
Marc Kupietz59c05362026-07-31 07:58:10 +090058 # Makefile.PL uses Devel::CheckLib to look for libcollocatordb, so it has to
59 # be there before --installdeps can determine the dependencies at all
60 - cpanm -n -l $PERL_LOCAL_LIB_ROOT Devel::CheckLib
Marc Kupietz18d78352024-02-20 20:55:54 +010061 - cpanm -n -l $PERL_LOCAL_LIB_ROOT --installdeps .
Marc Kupietz5b6a51e2022-04-11 21:23:30 +020062 - end_section build_perl_dependencies
63
64 - start_section build_derekovecs-server "Building DeReKoVecs server"
65 - perl Makefile.PL
66 - make
67 - make install
68 - end_section build_derekovecs-server
69
Marc Kupietz3e3e3262022-04-12 23:11:45 +020070 - start_section run_derekovecs-server "Testing DeReKoVecs server"
71 - prove --verbose t
Marc Kupietz5b6a51e2022-04-11 21:23:30 +020072 - end_section run_derekovecs-server
73
Marc Kupietzddba9082023-11-06 06:59:14 +010074deploy:
75 rules:
76 - if: $CI_COMMIT_TAG =~ /.+/
77 variables:
78 VID: $CI_COMMIT_TAG
79 - when: manual
80 variables:
81 VID: $CI_COMMIT_BRANCH-$CI_COMMIT_SHORT_SHA
82 stage: deploy
83 before_script:
84 - source `find .. -name section_helper.sh`
85 - start_section install_linux_packages "Installing missing Linux packages"
86 - 'command -v ssh-agent >/dev/null || apt-get install openssh-client -y'
87 - mkdir -p ~/.ssh
88 - chmod 700 ~/.ssh
89 - eval $(ssh-agent -s)
90 - chmod 400 "$SSH_PRIVATE_KEY"
91 - ssh-add "$SSH_PRIVATE_KEY"
92 - end_section install_linux_packages
93 script:
94 - echo "This is a manual job which doesn't start automatically, and the pipeline can complete without it starting."
95 - 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 +020096
97build-docker:
98 image: docker:latest
99 services:
100 - docker:dind
101 rules:
102 - if: $CI_COMMIT_TAG =~ /.+/
103 variables:
104 VID: $CI_COMMIT_TAG
105 - when: manual
106 variables:
107 VID: $CI_COMMIT_BRANCH-$CI_COMMIT_SHORT_SHA
108 stage: build
109 before_script:
Marc Kupietz10ccb982024-09-12 14:15:13 +0200110 - apk update
111 - apk add --no-cache git
112 script:
Marc Kupietz10ccb982024-09-12 14:15:13 +0200113 - sed -i -e "s/RUN rm -rf example-models//" Dockerfile
Marc Kupietz10ccb982024-09-12 14:15:13 +0200114 - docker build -f Dockerfile -t idscorpuslinguistics/derekovecs:$VID-large .
115 - wget https://github.com/slimtoolkit/slim/releases/latest/download/dist_linux.tar.gz
116 - tar zxf dist_linux.tar.gz
117 - export PATH=$(pwd)/dist_linux:$PATH
Marc Kupietze82c7a02024-09-13 14:49:26 +0200118 - 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 +0200119 - docker build -f Dockerfile.remove-example-data --tag idscorpuslinguistics/derekovecs:latest --tag idscorpuslinguistics/derekovecs:$VID .
120 - docker save idscorpuslinguistics/derekovecs:$VID | xz -T0 -M16G -9 > derekovecs.tar.xz
121 artifacts:
122 paths:
123 - derekovecs.tar.xz
Marc Kupietza9923bd2024-09-13 14:49:45 +0200124
125upload-docker:
126 only:
127 - master
128 - tags
129 variables:
130 VID: $CI_COMMIT_TAG
131 stage: deploy
132 image: docker:latest
133 services:
134 - docker:dind
135 script:
Marc Kupietza9923bd2024-09-13 14:49:45 +0200136 - unxz -c derekovecs.tar.xz | docker load
137 - echo "$DOCKER_HUB_PASSWORD" | docker login -u "$DOCKER_HUB_USERNAME" --password-stdin
138 - docker push idscorpuslinguistics/derekovecs:$VID
Marc Kupietz46b35282024-09-13 19:24:52 +0200139 - docker push idscorpuslinguistics/derekovecs
Marc Kupietza9923bd2024-09-13 14:49:45 +0200140 dependencies:
141 - build-docker
142 environment:
143 name: production