blob: 754e65deb73b1f542353a36b70e6350794a03128 [file] [log] [blame]
# The build needs root, for apt-get, and a perl with cpanm. metacpan/metacpan-api
# used to provide both, but it runs as an unprivileged user now, where apt-get
# fails with "Permission denied" and cmake never gets installed. Pinned to the
# distribution as well, so that an upstream rebuild cannot move rocksdb under us.
image: perl:5.40-trixie
variables:
# Set `CCACHE_BASEDIR` and `CCACHE_DIR` to point `ccache` towards the cached
# path on the gitlab-runner. This enables to cache the output of `ccache`
# between various runs.
CCACHE_BASEDIR: "${CI_PROJECT_DIR}"
CCACHE_DIR: "${CI_PROJECT_DIR}/ccache"
# Set `ccache` to `content` to prevent rebuilding of the CI/CD containers to
# trigger a recreate of the cache. By using `content` the compiler's `mtime`
# is not considered as part of the hash.
CCACHE_COMPILERCHECK: "content"
# Enable caching for `apt-get`.
APT_CACHE_DIR: "${CI_PROJECT_DIR}/apt-cache"
# Export `noninteractive` frontend to prevent requesting user input.
DEBIAN_FRONTEND: "noninteractive"
PERL_LOCAL_LIB_ROOT: ./perl5
PERL5LIB: ./perl5/lib/perl5
build-and-test:
stage: build
cache:
# Cache is shared between branches, but has a unique cache per job. The
# image is part of the key: perl5/ holds what cpanm decided was missing in
# that image, so a cache from another one is incomplete.
key: derekovecs-perl-5.40-trixie
paths:
# Note: directories should align with `$APT_CACHE_DIR` and `$CCACHE_DIR`.
- apt-cache/
- ccache/
- perl5/
before_script:
- pwd
- source `find .. -name section_helper.sh`
- start_section install_linux_packages "Installing missing Linux packages"
- mkdir -pv $APT_CACHE_DIR ccache
- 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
# ccache only makes the build faster, it must never be able to make it fail,
# so everything that uses it is guarded and CCACHE_OPTS stays empty without it
# a failed package install used to show up much later as "cmake: command
# not found" in the middle of the collocatordb build
- command -v cmake > /dev/null || { echo "cmake is missing, the package installation did not work"; exit 1; }
- 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
- end_section install_linux_packages
- start_section install_collocatordb "Building and installing collocatordb"
- git clone "https://korap.ids-mannheim.de/gerrit/ids-kl/collocatordb"
- cd collocatordb
- mkdir -p build
- cd build
- cmake $CCACHE_OPTS ..
- make
- command -v ccache > /dev/null && ccache --show-stats || true
- make install # && ctest --extra-verbose
- ldconfig
- end_section install_collocatordb
- cd ../..
script:
- start_section build_perl_dependencies "Installing Perl dependencies"
- cpanm -n -l $PERL_LOCAL_LIB_ROOT https://github.com/Akron/Mojolicious-Plugin-Localize.git
# Devel::CheckLib, which Makefile.PL needs to find libcollocatordb before it
# can tell anybody about the dependencies, comes bundled in inc/
- cpanm -n -l $PERL_LOCAL_LIB_ROOT --installdeps .
- end_section build_perl_dependencies
- start_section build_derekovecs-server "Building DeReKoVecs server"
- perl Makefile.PL
- make
- make install
- end_section build_derekovecs-server
- start_section run_derekovecs-server "Testing DeReKoVecs server"
# the server test starts morbo, which cpanm installed into the local lib
- export PATH="$CI_PROJECT_DIR/perl5/bin:$PATH"
- prove --verbose t
- end_section run_derekovecs-server
deploy:
rules:
- if: $CI_COMMIT_TAG =~ /.+/
variables:
VID: $CI_COMMIT_TAG
- when: manual
variables:
VID: $CI_COMMIT_BRANCH-$CI_COMMIT_SHORT_SHA
stage: deploy
before_script:
- source `find .. -name section_helper.sh`
- start_section install_linux_packages "Installing missing Linux packages"
- 'command -v ssh-agent >/dev/null || apt-get install openssh-client -y'
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- eval $(ssh-agent -s)
- chmod 400 "$SSH_PRIVATE_KEY"
- ssh-add "$SSH_PRIVATE_KEY"
- end_section install_linux_packages
script:
- echo "This is a manual job which doesn't start automatically, and the pipeline can complete without it starting."
- 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"
build-docker:
image: docker:latest
variables:
# the mint container has to reach the container it probes
FF_NETWORK_PER_BUILD: "true"
services:
- name: docker:dind
command: [--dns=127.0.0.11]
rules:
- if: $CI_COMMIT_TAG =~ /.+/
variables:
VID: $CI_COMMIT_TAG
- when: manual
variables:
VID: $CI_COMMIT_BRANCH-$CI_COMMIT_SHORT_SHA
stage: build
before_script:
- apk update
- apk add --no-cache git
script:
# the http probe needs a model to serve, so keep the example models in the
# large image and remove them further down with Dockerfile.remove-example-data
- sed -i -e "s/RUN rm -rf example-models//" Dockerfile
- docker build -f Dockerfile -t idscorpuslinguistics/derekovecs:$VID-large .
- 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
- docker build -f Dockerfile.remove-example-data --tag idscorpuslinguistics/derekovecs:latest --tag idscorpuslinguistics/derekovecs:$VID .
- ARTIFACT=derekovecs-${VID}.tar.xz
- docker save idscorpuslinguistics/derekovecs:$VID | xz -T0 -M16G -9 > "$ARTIFACT"
artifacts:
paths:
- derekovecs-*.tar.xz
upload-docker:
stage: deploy
image: docker:latest
services:
- name: docker:dind
command: [--dns=127.0.0.11]
needs:
- job: build-docker
artifacts: true
dependencies:
- build-docker
rules:
- if: $CI_COMMIT_TAG =~ /^v.+/
when: manual
- when: never
script:
- apk update
- apk add --no-cache xz
- ARTIFACT=derekovecs-${CI_COMMIT_TAG}.tar.xz
- xz -d -c "$ARTIFACT" | docker load
- echo "$DOCKER_HUB_PASSWORD" | docker login -u "$DOCKER_HUB_USERNAME" --password-stdin
- docker tag idscorpuslinguistics/derekovecs:$CI_COMMIT_TAG idscorpuslinguistics/derekovecs:latest
- docker push idscorpuslinguistics/derekovecs:$CI_COMMIT_TAG
- docker push idscorpuslinguistics/derekovecs:latest
environment:
name: production