diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000000000000000000000000000000000000..b8d60516196bffa30d883f7ab559bbbf3633682c
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,157 @@
+variables:
+  FDO_UPSTREAM_REPO: mesa/shader-db
+  MESA_TEMPLATES_COMMIT: &ci-templates-commit ffe4d1b10aab7534489f0c4bbc4c5899df17d3f2
+
+default:
+  # Retry build or test jobs up to twice when the gitlab-runner itself fails somehow.
+  retry:
+    max: 2
+    when:
+      - runner_system_failure
+
+include:
+  - project: 'freedesktop/ci-templates'
+    ref: *ci-templates-commit
+    file:
+      - '/templates/ci-fairy.yml'
+      - '/templates/debian.yml'
+
+
+# YAML anchors for rule conditions
+# --------------------------------
+.rules-anchors:
+  rules:
+    # Pipeline for forked project branch
+    - if: &is-forked-branch '$CI_COMMIT_BRANCH && $CI_PROJECT_NAMESPACE != "mesa"'
+      when: manual
+    # Forked project branch / pre-merge pipeline
+    - if: &is-forked-branch-or-pre-merge '$CI_PROJECT_NAMESPACE != "mesa" || $CI_PIPELINE_SOURCE == "merge_request_event"'
+      when: manual
+    # Pipeline runs for the main branch of the upstream Mesa project
+    - if: &is-mesa-main '$CI_PROJECT_NAMESPACE == "mesa" && $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH && $CI_COMMIT_BRANCH'
+      when: always
+    # Post-merge pipeline
+    - if: &is-post-merge '$CI_PROJECT_NAMESPACE == "mesa" && $CI_COMMIT_BRANCH'
+      when: on_success
+    # Pre-merge pipeline
+    - if: &is-pre-merge '$CI_PIPELINE_SOURCE == "merge_request_event"'
+      when: on_success
+
+
+# Sanity checks of MR settings and commit logs
+sanity:
+  extends:
+    - .fdo.ci-fairy
+  stage: .pre
+  rules:
+    - if: *is-pre-merge
+      when: on_success
+    # Other cases default to never
+  variables:
+    GIT_STRATEGY: none
+  script:
+    # ci-fairy check-commits --junit-xml=check-commits.xml
+    - ci-fairy check-merge-request --require-allow-collaboration --junit-xml=check-merge-request.xml
+  artifacts:
+    when: on_failure
+    reports:
+      junit: check-*.xml
+
+
+.debian-container:
+  variables:
+    FDO_DISTRIBUTION_VERSION: bullseye
+    FDO_DISTRIBUTION_TAG: 2023-02-18-initial-ci-rev2
+
+debian:
+  extends:
+    - .fdo.container-build@debian
+    - .debian-container
+  rules:
+    # Always run after a merge
+    - if: *is-post-merge
+      when: on_success
+    # Run job if it is for a merge request and the CI was modified
+    - if: *is-pre-merge
+      changes:
+        - .gitlab-ci.yml
+    # Allow triggering jobs manually in other cases
+    - when: manual
+  variables:
+    # bump FDO_DISTRIBUTION_TAG above when you change the packages below
+    FDO_DISTRIBUTION_PACKAGES: >
+      bison
+      curl
+      flex
+      g++
+      gcc
+      git
+      libgbm-dev
+      libepoxy-dev
+      libexpat-dev
+      libpciaccess-dev
+      make
+      ninja-build
+      pkg-config
+      python3-mako
+      python3-pip
+      python3-setuptools
+      wget
+      zlib1g-dev
+      zstd
+
+
+mesa-drivers:
+  extends:
+    - .fdo.distribution-image@debian
+    - .debian-container
+  rules:
+    # Run pipeline by default if it is for a merge request.
+    - if: *is-pre-merge
+      when: on_success
+    # Allow triggering jobs manually in other cases
+    - when: manual
+  variables:
+    GALLIUM_DRIVERS: >
+      freedreno
+      iris
+      nouveau
+      r300
+      v3d
+      vc4
+
+  before_script:
+    - set -eu
+
+    # Meson in the debian repos is too old, so install from pip
+    - python3 -m pip install meson
+
+    # Install Mesa
+    - echo -e "\e[0Ksection_start:$(date +%s):mesa-install[collapsed=true]\r\e[0KInstalling Mesa's drm-shim drivers"
+    - git clone --depth 1 https://gitlab.freedesktop.org/mesa/mesa.git
+    - sh mesa/.gitlab-ci/container/build-libdrm.sh
+    # `-D tools=intel` is needed until this bug is fixed:
+    # https://gitlab.freedesktop.org/mesa/mesa/-/issues/7789
+    - meson setup mesa build
+      --buildtype debug
+      --prefix "$PWD"/install
+      --libdir lib
+      -D vulkan-drivers=
+      -D llvm=disabled
+      -D glx=disabled
+      -D platforms=
+      -D tools=drm-shim,intel
+      -D gallium-drivers=$(echo "$GALLIUM_DRIVERS" | sed 's/ /,/g')
+    - meson install -C build
+    - echo -e "\e[0Ksection_end:$(date +%s):mesa-install\r\e[0K"
+
+    # Mesa script expects shader-db there
+    - make
+    - mkdir /usr/local/shader-db
+    - mv run /usr/local/shader-db
+    - mv shaders /usr/local/shader-db
+    - mv fossils /usr/local/shader-db
+
+  script:
+    - find install -not -type d | sort
+    - sh mesa/.gitlab-ci/run-shader-db.sh