blob: cfee89e91bc96aba53c92a5f72177fefba0b50fd [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 Kupietze20daf12026-07-31 09:55:55 +090058 # Devel::CheckLib, which Makefile.PL needs to find libcollocatordb before it
59 # can tell anybody about the dependencies, comes bundled in inc/
Marc Kupietz18d78352024-02-20 20:55:54 +010060 - cpanm -n -l $PERL_LOCAL_LIB_ROOT --installdeps .
Marc Kupietz5b6a51e2022-04-11 21:23:30 +020061 - end_section build_perl_dependencies
62
63 - start_section build_derekovecs-server "Building DeReKoVecs server"
64 - perl Makefile.PL
65 - make
66 - make install
67 - end_section build_derekovecs-server
68
Marc Kupietz3e3e3262022-04-12 23:11:45 +020069 - start_section run_derekovecs-server "Testing DeReKoVecs server"
70 - prove --verbose t
Marc Kupietz5b6a51e2022-04-11 21:23:30 +020071 - end_section run_derekovecs-server
72
Marc Kupietzddba9082023-11-06 06:59:14 +010073deploy:
74 rules:
75 - if: $CI_COMMIT_TAG =~ /.+/
76 variables:
77 VID: $CI_COMMIT_TAG
78 - when: manual
79 variables:
80 VID: $CI_COMMIT_BRANCH-$CI_COMMIT_SHORT_SHA
81 stage: deploy
82 before_script:
83 - source `find .. -name section_helper.sh`
84 - start_section install_linux_packages "Installing missing Linux packages"
85 - 'command -v ssh-agent >/dev/null || apt-get install openssh-client -y'
86 - mkdir -p ~/.ssh
87 - chmod 700 ~/.ssh
88 - eval $(ssh-agent -s)
89 - chmod 400 "$SSH_PRIVATE_KEY"
90 - ssh-add "$SSH_PRIVATE_KEY"
91 - end_section install_linux_packages
92 script:
93 - echo "This is a manual job which doesn't start automatically, and the pipeline can complete without it starting."
94 - 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 +020095
96build-docker:
97 image: docker:latest
Marc Kupietz211fff42026-07-31 10:31:10 +090098 variables:
99 # the mint container has to reach the container it probes
100 FF_NETWORK_PER_BUILD: "true"
Marc Kupietz10ccb982024-09-12 14:15:13 +0200101 services:
Marc Kupietz211fff42026-07-31 10:31:10 +0900102 - name: docker:dind
103 command: [--dns=127.0.0.11]
Marc Kupietz10ccb982024-09-12 14:15:13 +0200104 rules:
105 - if: $CI_COMMIT_TAG =~ /.+/
106 variables:
107 VID: $CI_COMMIT_TAG
108 - when: manual
109 variables:
110 VID: $CI_COMMIT_BRANCH-$CI_COMMIT_SHORT_SHA
111 stage: build
112 before_script:
Marc Kupietz10ccb982024-09-12 14:15:13 +0200113 - apk update
114 - apk add --no-cache git
115 script:
Marc Kupietz211fff42026-07-31 10:31:10 +0900116 # the http probe needs a model to serve, so keep the example models in the
117 # large image and remove them further down with Dockerfile.remove-example-data
Marc Kupietz10ccb982024-09-12 14:15:13 +0200118 - sed -i -e "s/RUN rm -rf example-models//" Dockerfile
Marc Kupietz10ccb982024-09-12 14:15:13 +0200119 - docker build -f Dockerfile -t idscorpuslinguistics/derekovecs:$VID-large .
Marc Kupietz211fff42026-07-31 10:31:10 +0900120 - 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 +0200121 - docker build -f Dockerfile.remove-example-data --tag idscorpuslinguistics/derekovecs:latest --tag idscorpuslinguistics/derekovecs:$VID .
Marc Kupietz211fff42026-07-31 10:31:10 +0900122 - ARTIFACT=derekovecs-${VID}.tar.xz
123 - docker save idscorpuslinguistics/derekovecs:$VID | xz -T0 -M16G -9 > "$ARTIFACT"
Marc Kupietz10ccb982024-09-12 14:15:13 +0200124 artifacts:
125 paths:
Marc Kupietz211fff42026-07-31 10:31:10 +0900126 - derekovecs-*.tar.xz
Marc Kupietza9923bd2024-09-13 14:49:45 +0200127
128upload-docker:
Marc Kupietza9923bd2024-09-13 14:49:45 +0200129 stage: deploy
130 image: docker:latest
131 services:
Marc Kupietz211fff42026-07-31 10:31:10 +0900132 - name: docker:dind
133 command: [--dns=127.0.0.11]
134 needs:
135 - job: build-docker
136 artifacts: true
Marc Kupietza9923bd2024-09-13 14:49:45 +0200137 dependencies:
138 - build-docker
Marc Kupietz211fff42026-07-31 10:31:10 +0900139 rules:
140 - if: $CI_COMMIT_TAG =~ /^v.+/
141 when: manual
142 - when: never
143 script:
144 - apk update
145 - apk add --no-cache xz
146 - ARTIFACT=derekovecs-${CI_COMMIT_TAG}.tar.xz
147 - xz -d -c "$ARTIFACT" | docker load
148 - echo "$DOCKER_HUB_PASSWORD" | docker login -u "$DOCKER_HUB_USERNAME" --password-stdin
149 - docker tag idscorpuslinguistics/derekovecs:$CI_COMMIT_TAG idscorpuslinguistics/derekovecs:latest
150 - docker push idscorpuslinguistics/derekovecs:$CI_COMMIT_TAG
151 - docker push idscorpuslinguistics/derekovecs:latest
Marc Kupietza9923bd2024-09-13 14:49:45 +0200152 environment:
153 name: production