Skip to content

Commit bace062

Browse files
committed
Merge branch 'release/v0.4.5'
2 parents f1c6470 + 78e1fc5 commit bace062

File tree

12 files changed

+428
-169
lines changed

12 files changed

+428
-169
lines changed

.github/WORKFLOWS.md

Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This document provides an overview of the CI/CD workflows in this repository.
77
The repository uses GitHub Actions for continuous integration and deployment. The workflows are designed to:
88

99
1. Validate code and run tests
10-
2. Build and publish Docker images for tagged releases
10+
2. Build and publish Docker images for tagged releases and the develop branch
1111
3. Maintain code quality through automated checks
1212

1313
## Workflow Structure
@@ -21,6 +21,7 @@ Triggered when a new tag with the pattern `v*.*.*` is pushed. This workflow:
2121
1. Validates that the tag follows semantic versioning
2222
2. Runs tests for the server package
2323
3. Builds and pushes a Docker image to GitHub Container Registry (if tests pass)
24+
4. Tags the image with the version number and 'latest'
2425

2526
```mermaid
2627
graph TD
@@ -33,58 +34,93 @@ graph TD
3334
F -->|No| H[End Workflow]
3435
```
3536

36-
### Reusable Workflows
37+
#### Develop Branch Workflow (`develop-push.yml`)
3738

38-
#### Test Workflow (`reusable-test.yml`)
39+
Triggered when code is pushed to the develop branch. This workflow:
3940

40-
A reusable workflow that handles testing. It:
41+
1. Runs tests for the server package
42+
2. Builds and pushes a Docker image to GitHub Container Registry with the 'dev' tag (if tests pass)
43+
44+
#### Main Branch Workflow (`main-push.yml`)
45+
46+
Triggered when code is pushed to the main branch. This workflow:
4147

42-
1. Sets up Node.js and pnpm
43-
2. Installs jsdom (required for Vitest DOM testing)
44-
3. Builds the application
45-
4. Runs tests and collects coverage
46-
5. Uploads test results and coverage reports as artifacts
48+
1. Runs tests for the server package
4749

48-
#### Docker Build Workflow (`reusable-docker-build.yml`)
50+
#### Pull Request Workflow (`pull-request.yml`)
4951

50-
A reusable workflow that handles building and pushing Docker images. It:
52+
Triggered when a pull request is opened or updated for the main or develop branches. This workflow:
5153

52-
1. Sets up Docker Buildx
53-
2. Logs in to GitHub Container Registry
54-
3. Extracts metadata for proper tagging
55-
4. Builds and optionally pushes the Docker image
56-
5. Supports tagging with semver and latest
54+
1. Runs tests for the server package
55+
56+
### Reusable Workflows
57+
58+
#### Test Workflow (`reusable-test.yml`)
59+
60+
A reusable workflow that handles testing. It:
61+
62+
1. Sets up Node.js (v22) and pnpm
63+
2. Builds the application
64+
3. Runs tests and collects coverage
65+
4. Uploads test results and coverage reports as artifacts
5766

5867
### Shared Actions
5968

6069
#### Setup Node and pnpm (`setup-node-pnpm`)
6170

62-
Sets up Node.js and pnpm with caching for faster installations.
71+
Sets up Node.js (v22) and pnpm with caching for faster installations. Uses non-frozen lockfile to ensure compatibility.
6372

6473
#### Validate Semver Tag (`validate-semver-tag`)
6574

6675
Validates that a tag follows semantic versioning format (v*.*.*)
6776

68-
#### Test Report (`test-report`)
77+
## Dependencies
78+
79+
The workflows expect jsdom to be included in the package.json of the server application for DOM testing with Vitest.
80+
81+
## Docker Images
82+
83+
The workflow uses GitHub's official Docker actions directly:
84+
- `docker/setup-buildx-action` - For setting up Docker Buildx
85+
- `docker/login-action` - For authenticating with GitHub Container Registry
86+
- `docker/metadata-action` - For generating image tags and labels
87+
- `docker/build-push-action` - For building and pushing Docker images
88+
89+
Important Docker build configuration:
90+
- Context is set to the repository root (`.`)
91+
- Dockerfile path is explicitly set to `apps/server/Dockerfile`
92+
- Cache is enabled for faster builds using GitHub Actions cache
93+
94+
### Simplified Dockerfile Structure
6995

70-
Runs tests and generates reports with coverage information.
96+
The Dockerfile has been simplified to use a two-stage build approach:
7197

72-
## Required Dependencies
98+
1. **Builder Stage**:
99+
- Uses Node.js 22 Alpine as the base image
100+
- Copies the entire repository into the container
101+
- Installs dependencies with `--no-frozen-lockfile` to avoid dependency conflicts
102+
- Builds the application using the pnpm filter
73103

74-
The testing workflow requires the `jsdom` package to be available for DOM testing with Vitest. This dependency is automatically installed during the workflow execution.
104+
2. **Production Stage**:
105+
- Uses a fresh Node.js Alpine image
106+
- Copies only the built application and package.json
107+
- Installs only production dependencies
108+
- Results in a smaller final image with no build tools or source code
75109

76110
## Badges
77111

78112
Workflow status can be displayed in the README.md using the following badge:
79113

80114
```markdown
81-
[![CI/CD Pipeline](https://github.com/cbnsndwch/react-router-nest/actions/workflows/release-tag.yml/badge.svg)](https://github.com/cbnsndwch/react-router-nest/actions/workflows/release-tag.yml)
115+
[![Release Pipeline](https://github.com/cbnsndwch/react-router-nest/actions/workflows/release-tag.yml/badge.svg)](https://github.com/cbnsndwch/react-router-nest/actions/workflows/release-tag.yml)
82116
```
83117

84118
## Troubleshooting
85119

86120
If the workflow fails, check:
87121

88-
1. **Missing dependencies**: Ensure all required dependencies are either in the package.json or installed during workflow execution
89-
2. **Tag format**: Ensure tags follow the semantic versioning format v*.*.* (e.g., v1.0.0)
90-
3. **Test failures**: Look at test artifacts for details on failing tests
122+
1. **Missing dependencies**: Ensure all required dependencies are in the package.json
123+
2. **Node.js version**: The workflow expects Node.js v22+ as specified in the server package.json
124+
3. **Tag format**: Ensure release tags follow the semantic versioning format v*.*.* (e.g., v1.0.0)
125+
4. **Test failures**: Look at test artifacts for details on failing tests
126+
5. **Docker build context**: The Dockerfile expects to be built from the repository root. If you modify the workflows, ensure the Docker context is set to `.` (repository root) and the file parameter points to `apps/server/Dockerfile`

.github/actions/setup-node-pnpm/action.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ runs:
2121
- name: Setup Node.js
2222
uses: actions/setup-node@v4
2323
with:
24-
node-version-file: ${{ inputs.node-version-file }}
24+
node-version: '22'
2525

2626
- name: Setup pnpm
2727
uses: pnpm/action-setup@v4
@@ -46,8 +46,10 @@ runs:
4646
if: ${{ inputs.install-deps == 'true' }}
4747
shell: bash
4848
run: |
49+
# The server package.json has jsdom as a dependency that's added later
50+
# Avoid frozen lockfile to prevent errors when CI adds it
4951
if [[ "${{ inputs.frozen-lockfile }}" == "true" ]]; then
50-
pnpm install --frozen-lockfile
52+
pnpm install --no-frozen-lockfile
5153
else
5254
pnpm install
5355
fi

.github/workflows/develop-push.yml

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,37 @@ jobs:
2323
name: Build & Push Docker Image
2424
needs: test
2525
if: ${{ needs.test.outputs.tests_passed == 'true' }}
26-
uses: ./.github/workflows/reusable-docker-build.yml
27-
with:
28-
push: true
29-
is-develop: true
30-
include-latest: true
26+
runs-on: ubuntu-latest
27+
28+
steps:
29+
- name: Checkout code
30+
uses: actions/checkout@v4
31+
32+
- name: Set up Docker Buildx
33+
uses: docker/setup-buildx-action@v3
34+
35+
- name: Log in to GitHub Container Registry
36+
uses: docker/login-action@v3
37+
with:
38+
registry: ghcr.io
39+
username: ${{ github.actor }}
40+
password: ${{ secrets.GITHUB_TOKEN }}
41+
42+
- name: Extract metadata for Docker
43+
id: meta
44+
uses: docker/metadata-action@v5
45+
with:
46+
images: ghcr.io/cbnsndwch/react-router-nest-server
47+
tags: |
48+
type=raw,value=dev
49+
50+
- name: Build and push Docker image
51+
uses: docker/build-push-action@v5
52+
with:
53+
context: .
54+
file: apps/server/Dockerfile
55+
push: true
56+
tags: ${{ steps.meta.outputs.tags }}
57+
labels: ${{ steps.meta.outputs.labels }}
58+
cache-from: type=gha
59+
cache-to: type=gha,mode=max

.github/workflows/release-tag.yml

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,38 @@ jobs:
4141
name: Build & Push Docker Image
4242
needs: [validate-tag, test]
4343
if: ${{ needs.validate-tag.outputs.is-valid == 'true' && needs.test.outputs.tests_passed == 'true' }}
44-
uses: ./.github/workflows/reusable-docker-build.yml
45-
with:
46-
push: true
47-
tag-version: ${{ needs.validate-tag.outputs.version }}
48-
is-release: true
49-
include-latest: true
44+
runs-on: ubuntu-latest
45+
46+
steps:
47+
- name: Checkout code
48+
uses: actions/checkout@v4
49+
50+
- name: Set up Docker Buildx
51+
uses: docker/setup-buildx-action@v3
52+
53+
- name: Log in to GitHub Container Registry
54+
uses: docker/login-action@v3
55+
with:
56+
registry: ghcr.io
57+
username: ${{ github.actor }}
58+
password: ${{ secrets.GITHUB_TOKEN }}
59+
60+
- name: Extract metadata for Docker
61+
id: meta
62+
uses: docker/metadata-action@v5
63+
with:
64+
images: ghcr.io/cbnsndwch/react-router-nest-server
65+
tags: |
66+
type=semver,pattern={{version}},value=v${{ needs.validate-tag.outputs.version }}
67+
type=raw,value=latest
68+
69+
- name: Build and push Docker image
70+
uses: docker/build-push-action@v5
71+
with:
72+
context: .
73+
file: apps/server/Dockerfile
74+
push: true
75+
tags: ${{ steps.meta.outputs.tags }}
76+
labels: ${{ steps.meta.outputs.labels }}
77+
cache-from: type=gha
78+
cache-to: type=gha,mode=max

.github/workflows/reusable-docker-build.yml

Lines changed: 0 additions & 73 deletions
This file was deleted.

.github/workflows/reusable-test.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ jobs:
4040
install-deps: true
4141
frozen-lockfile: true
4242

43-
- name: Install jsdom for Vitest DOM testing
44-
run: pnpm add -D jsdom --filter "${{ inputs.package-filter }}"
45-
4643
- name: Build application
4744
run: pnpm ${{ inputs.build-command }}
4845

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"Googlebot",
4848
"isbot",
4949
"Pipeable",
50-
"vset"
50+
"vset",
51+
"vtag"
5152
]
5253
}

0 commit comments

Comments
 (0)