GitLab Logo

Creating an optimised GitLab pipline for eslint tests

Steps on how I created an optimised GitLab pipline for running eslint tests.

GitLab
Dependency Proxy
Pipeline

Published 2 years ago

1 minute read

The problem

When I initially started running these pipeline tests I was including node in my gitlab-ci file like this: image: node:latest. Doing this it was fetching and downloading the docker image for node everytime this test ran. It would take 3-4 minutes, far too long.

The aim

Cache the images and use locally on the GitLab instance, in order to run eslint and other tests efficiently.

1 - Enable Depedency Proxy

"The GitLab Dependency Proxy is a local proxy you can use for your frequently-accessed upstream images.

In the case of CI/CD, the Dependency Proxy receives a request and returns the upstream image from a registry, acting as a pull-through cache"

GitLab details the instructions on how to do enable this here.

2 - Create your gitlab-ci.yml

Read more on the CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX here.

# image: node:latest - Replaced by below image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/node:latest stages: - lint eslint: stage: lint cache: key: files: - package-lock.json paths: - node_modules script: # Install ESLint in this docker container - npm install # Run ESLint - npm run test

3 - Edit your package.json

The pipeline is installing the package from the repository and running the npm script test.

"scripts": { ... "test": "eslint . --ext .js,.jsx,.ts,.tsx", // Run from the pipeline },

4 - Tests will now run

When all changes are saved you should see your pipeline running. eslint tests successful

As part of merge requests you will now also see the pipeline running. If tests fail for whatever reason, you will see this. eslint tests fail

Let's chat about your next project

Whether you need a single contractor or a full team, I collaborate with a trusted network of designers and developers. Having worked on large-scale projects, I'm equally committed to supporting businesses of all sizes, locally in Surrey, London, and internationally.

See also...

CnCNet - Website & App Development

Comprehensive design and development of responsive web and desktop apps for CnCNet, enhancing user experience and accessibility.

AR Configurator for E-Bikes

Bespoke augmented reality web configurator for E-Bikes, offering full customization options, including color choices and feature configurations.

Stock Investment App

Real-time stock investment app for web and mobile, built with TypeScript, React, and WebSockets, delivering fast, responsive, and data-driven experiences.

KickTown Football - Website

Custom-built website and API's for KickTown Football, integrating a merchandise store, booking system, and seamless user experience.

Tempest Rising - Official Website

Website development for Slipgate Ironworks' Tempest Rising, crafted to deliver a sleek, immersive experience for fans and players.

Cosmetic Visualiser - Web App

React and TypeScript-powered web app for visualizing facial cosmetic treatments, offering a cutting-edge, interactive user experience.

C&C Community Website

Command & Conquer Community platform with improved SEO, a sleek interface, and content integrations like Twitch and Steam, creating a hub for fans and creators.

React Native Health App

Custom Android and iOS health app developed with React Native and TypeScript, tailored for a health-tech startup, ensuring cross-platform compatibility.

Oriental Garden Restaurant - Website Redesign

Website redesign featuring an online ordering system that boosts sales and enhances customer engagement with a modern, intuitive interface.