Skip to content

Commit 3caa5a9

Browse files
authored
Merge pull request #22 from fac-32/feat/dev-environment-consistency
feat: Add standardised development environment
2 parents 1c5dac9 + d061719 commit 3caa5a9

File tree

7 files changed

+2560
-307
lines changed

7 files changed

+2560
-307
lines changed

.dockerignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Dependencies
2+
node_modules
3+
dist
4+
5+
# Environment files
6+
.env
7+
.env.*
8+
!/.env.example
9+
10+
# Git
11+
.git
12+
13+
# Logs
14+
npm-debug.log*
15+
yarn-debug.log*
16+
yarn-error.log*
17+
18+
# Editor directories and files
19+
.idea
20+
.vscode
21+
*.suo
22+
*.ntvs*
23+
*.njsproj
24+
*.sln

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v20

Containerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Use a more secure, slim version of the Node.js 20 image as a parent image
2+
FROM node:20-slim
3+
4+
# Set the working directory
5+
WORKDIR /app
6+
7+
# Copy package.json and package-lock.json to the working directory
8+
COPY package*.json ./
9+
10+
# Install project dependencies
11+
RUN npm install
12+
13+
# Copy the rest of the application's source code from your host to your image filesystem.
14+
COPY . .
15+
16+
# Make port 5173 available to the world outside this container
17+
EXPOSE 5173
18+
19+
# Run the app when the container launches
20+
CMD ["npm", "run", "dev", "--", "--host"]

PIPELINE.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# CI/CD Pipeline Best Practices ⚙️
2+
3+
This document outlines the best practices for our CI/CD pipeline to ensure consistent, reliable, and efficient builds.
4+
5+
## Overview 🌎
6+
7+
The primary goal of our CI/CD pipeline is to automate the process of building, testing, and deploying our application. Adhering to these guidelines is crucial for maintaining a stable and predictable development workflow.
8+
9+
## Key Principles 🔑
10+
11+
- **Consistency:** Every build should be consistent, regardless of who triggers it or when.
12+
- **Reproducibility:** We must be able to reproduce any build at any time. This is critical for debugging and for ensuring that what we test is what we deploy.
13+
- **Speed:** A fast pipeline means faster feedback for developers.
14+
15+
## Dependency Management 🖇️
16+
17+
Proper dependency management is the foundation of a reliable CI/CD pipeline.
18+
19+
### The Role of `package.json` and `package-lock.json` 📦
20+
21+
- **`package.json`**: Lists the dependencies your project needs, often with a version range (e.g., `^1.2.3`). This file describes the _intended_ dependencies.
22+
- **`package-lock.json`**: Records the _exact_ version of every dependency that was installed, including sub-dependencies. This file ensures that you get the same dependency tree every single time. **This file must be committed to the repository.**
23+
24+
### `npm install` vs. `npm ci`
25+
26+
This is the most important distinction for our workflow.
27+
28+
- **`npm install`**:
29+
- Use this command for **local development when you need to add or update dependencies**.
30+
- It may update your `package-lock.json` file based on the version ranges in `package.json`.
31+
- **NEVER use `npm install` (without arguments) in the CI/CD pipeline.**
32+
33+
- **`npm ci`** ("Clean Install"):
34+
- This is the **ONLY command that should be used to install dependencies in the CI/CD pipeline**.
35+
- It installs dependencies directly from `package-lock.json`, ignoring `package.json`.
36+
- It guarantees reproducible builds because it always installs the exact same dependency versions.
37+
- It's generally faster than `npm install`.
38+
- It starts by deleting the `node_modules` directory to ensure a clean installation.
39+
40+
## Workflow for Managing Dependencies
41+
42+
### Local Development Workflow
43+
44+
1. **To add a new dependency:**
45+
46+
```bash
47+
npm install <package-name>
48+
```
49+
50+
For a development dependency (e.g., a testing library):
51+
52+
```bash
53+
npm install <package-name> --save-dev
54+
```
55+
56+
2.**Commit changes:** After adding or updating dependencies, commit both the `package.json` and the updated ``package-lock.json` files.
57+
58+
```bash
59+
git add package.json package-lock.json
60+
git commit -m "feat: Add <package-name> dependency"
61+
```
62+
63+
### CI/CD Pipeline Workflow
64+
65+
1.**Checkout code:** The pipeline will check out the latest version of the code from the repository.
66+
67+
2.**Install dependencies:** The pipeline must use `npm ci` to install dependencies.
68+
69+
```yaml
70+
# Example step in a GitHub Actions workflow
71+
- name: Install Dependencies
72+
run: npm ci
73+
```
74+
75+
This ensures that the pipeline uses the exact dependency versions that you tested with locally.
76+
77+
## Best Practices Summary
78+
79+
- **Always** commit your `package-lock.json` file.
80+
- **Always** use `npm ci` in the CI/CD pipeline to install dependencies.
81+
- **Only** use `npm install <package-name>` locally to add or update dependencies.
82+
- **Regularly** update your dependencies locally to get the latest features and security patches, and commit the updated `package-lock.json`.
83+
- Ensure your `package.json` and `package-lock.json` files are in sync before pushing your changes. `npm ci` will fail if they are not, which is a good thing.

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,36 @@ Currently, two official plugins are available:
1111

1212
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
1313

14+
## Development Environment
15+
16+
This project requires **Node.js version 20 or higher**. To ensure a consistent development environment, we have included an `.nvmrc` file.
17+
18+
If you are using [Node Version Manager (nvm)](https://github.com/nvm-sh/nvm), you can switch to the correct Node.js version by running the following command in the project root:
19+
20+
```bash
21+
nvm use
22+
```
23+
24+
This will automatically read the `.nvmrc` file and set your Node.js version accordingly.
25+
26+
## Containerized Development with Podman
27+
28+
For the most consistent development experience across all operating systems, you can use Podman to run the application in a container.
29+
30+
First, build the container image:
31+
32+
```bash
33+
podman build -t keycv-interface .
34+
```
35+
36+
Then, run the container:
37+
38+
```bash
39+
podman run -p 5173:5173 -v ./src:/app/src keycv-interface
40+
```
41+
42+
This will start the Vite development server, and you can access the application at `http://localhost:5173`. The `-v ./src:/app/src` flag mounts the `src` directory into the container, allowing for hot-reloading when you make changes to your code.
43+
1444
## Linting
1545

1646
To run the lint check in this project before pushing your repository, execute the following command:

0 commit comments

Comments
 (0)