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're looking for a single contractor or a full team, I regularly collaborate with a trusted collective of designers and developers to deliver large-scale projects.

See also...

KickTown Football

Website Development for KickTown Football: Custom Build, Merchandise Store, and Booking System

Stock Investment App

Mobile and web app for stock investment, built with TypeScript, React, and WebSockets, offering real-time data and responsive design.

CnCNet - Website & App Development

Comprehensive design and development of web and desktop apps for CnCNet

Bespoke AR Web Configurator for E-Bikes

A bespoke augmented reality web configurator developed to showcase the client's E-Bike, offering fully customizable options such as color selections and feature configurations.

Oriental Garden Restaurant

A complete website redesign featuring a new online ordering system for enhanced customer experience and increased revenue.

Web App Visualizer - Facial Cosmetic Treatment Simulation

A React and TypeScript-powered web app designed to visualize facial cosmetic treatment results for enhanced customer decision-making

React Native - Android & iOS App

Development of a bespoke Android & iOS app for a Health technology startup, built with React Native & TypeScript.

Website - C&C Community

Enhancing the platform with a sleek user interface, improved SEO coverage, and integrated content features like Twitch, and Steam. Offering a central resource for Command & Conquer fans and creators.