Skip to content

Commit f1f1564

Browse files
authored
Merge pull request #64 from udx/worker-upgrade
Maintenance Update
2 parents 9649125 + 466ddc9 commit f1f1564

File tree

12 files changed

+195
-158
lines changed

12 files changed

+195
-158
lines changed

.github/workflows/tests.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
name: Tests
3+
4+
on:
5+
push:
6+
pull_request:
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
test:
13+
name: Build and Test
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v6
19+
20+
- name: Build image and run tests
21+
run: make test

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Use the latest udx-worker as the base image
2-
FROM usabilitydynamics/udx-worker:0.36.0
2+
FROM usabilitydynamics/udx-worker:0.37.0
33

44
# Add metadata labels
5-
LABEL version="0.24.0"
5+
LABEL version="0.25.0"
66

77
# Set build arguments for Node.js version and application port
88
ARG NODE_VERSION=22.21.1
@@ -75,4 +75,4 @@ WORKDIR "${APP_HOME}"
7575
ENTRYPOINT ["/usr/local/worker/bin/entrypoint.sh"]
7676

7777
# Use the default command from parent image
78-
CMD ["tail", "-f", "/dev/null"]
78+
CMD ["tail", "-f", "/dev/null"]

Makefile

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ include Makefile.help
66
.DEFAULT_GOAL := help
77

88
# Phony targets ensure Make doesn't get confused by filenames
9-
.PHONY: build run deploy run-it clean exec log test dev-pipeline run-all-tests wait-container-ready
9+
.PHONY: build run deploy run-it clean exec log test dev-pipeline run-all-tests run-test wait-container-ready
1010

1111
# Docker Commands for Reusability
1212
DOCKER_RUN_BASE := docker run --rm --name $(CONTAINER_NAME) \
@@ -22,6 +22,12 @@ endif
2222

2323
DOCKER_EXEC := docker exec -it $(CONTAINER_NAME)
2424
DOCKER_CLEAN := docker rm -f $(CONTAINER_NAME) || true
25+
TEST_VOLUMES := \
26+
-v $(PWD)/src/tests:/usr/src/app/tests \
27+
-v $(PWD)/src/examples/simple-server/index.js:/usr/src/app/index.js \
28+
-v $(PWD)/src/examples/simple-server/.config/worker/services.yaml:/home/udx/.config/worker/services.yaml
29+
TEST_ENV := -e NODE_ENV=test
30+
TEST_RUN := docker run --rm $(TEST_VOLUMES) $(TEST_ENV) $(DOCKER_IMAGE)
2531

2632
# Build the Docker image with multi-platform support
2733
build:
@@ -42,6 +48,11 @@ run: clean
4248
@$(MAKE) wait-container-ready
4349
@echo "Container started successfully."
4450

51+
# Deploy Docker container (production mode)
52+
deploy: clean
53+
@echo "Deploying Docker container (production mode)..."
54+
@$(MAKE) run NODE_ENV=production
55+
4556
# Run Docker container in interactive mode
4657
run-it:
4758
$(MAKE) run INTERACTIVE=true CMD="/bin/bash"
@@ -77,23 +88,28 @@ wait-container-ready:
7788
@echo "Container is ready."
7889

7990
# Run all tests in the tests directory
80-
run-all-tests:
91+
run-all-tests: build
8192
@echo "Running all tests in Docker container..."
82-
@docker run --rm \
83-
-v $(PWD)/src/tests:/usr/src/app/tests \
84-
-v $(PWD)/src/examples/simple-server/index.js:/usr/src/app/index.js \
85-
-v $(PWD)/src/examples/simple-server/.config/worker/services.yaml:/home/udx/.config/worker/services.yaml \
86-
-e NODE_ENV=test \
87-
$(DOCKER_IMAGE) \
93+
@$(TEST_RUN) \
8894
/bin/sh -c 'cd /usr/src/app/tests && for test_script in *.sh; do \
8995
echo "Running $$test_script..."; \
9096
sh ./$$test_script || { echo "Test $$test_script failed"; exit 1; }; \
9197
done'
9298

99+
# Run a specific test script
100+
run-test: build
101+
@if [ -z "$(TEST_SCRIPT)" ]; then \
102+
echo "TEST_SCRIPT is required (e.g., make run-test TEST_SCRIPT=10_validate_environment.sh)"; \
103+
exit 1; \
104+
fi
105+
@echo "Running test $(TEST_SCRIPT) in Docker container..."
106+
@$(TEST_RUN) \
107+
/bin/sh -c 'cd /usr/src/app/tests && sh ./$(TEST_SCRIPT)'
108+
93109
# Run validation tests (build and run-all-tests)
94-
test: build run-all-tests
110+
test: run-all-tests
95111
@echo "Validation tests completed."
96112

97113
# Development pipeline (build and test)
98-
dev-pipeline: build test
114+
dev-pipeline: test
99115
@echo "Development pipeline completed successfully."

Makefile.help

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ help:
99
@echo " clean Stop and remove any existing container with the specified name"
1010
@echo " wait-container-ready Wait for the container to be ready by checking application readiness"
1111
@echo " run-test Run a specific test script in the test environment (requires TEST_SCRIPT variable)"
12-
@echo " run-all-tests Run all test scripts in the tests directory with a test environment"
13-
@echo " test Run validation tests (build and run-all-tests)"
14-
@echo " dev-pipeline Execute the full development pipeline (build and test)\n"
12+
@echo " run-all-tests Build the image and run all test scripts"
13+
@echo " test Run validation tests (same as run-all-tests)"
14+
@echo " dev-pipeline Execute the validation pipeline\n"
1515
@echo "Variables (with default values):\n"
1616
@echo " IMAGE_NAME = $(IMAGE_NAME) # Name of the Docker image"
1717
@echo " TAG = $(TAG) # Tag for the Docker image"
@@ -27,5 +27,6 @@ help:
2727
@echo " BUILD_PLATFORMS = $(BUILD_PLATFORMS) # Platforms for multi-platform builds"
2828
@echo " NO_CACHE = $(NO_CACHE) # Disable cache when building Docker images"
2929
@echo " DETACHED = $(DETACHED) # Run containers in detached mode by default"
30-
@echo " CMD = $(CMD) # Default command to run inside the container\n"
30+
@echo " CMD = $(CMD) # Default command to run inside the container"
31+
@echo " TEST_SCRIPT = $(TEST_SCRIPT) # Test script to run with run-test\n"
3132
@echo "To run a specific test with run-test, set the TEST_SCRIPT variable, e.g., 'make run-test TEST_SCRIPT=10_validate_environment.sh'"

Makefile.variables

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ NO_CACHE ?= false
2424
# Runtime Options
2525
DETACHED ?= true
2626
CMD ?= /bin/bash
27+
TEST_SCRIPT ?=

README.md

Lines changed: 40 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,185 +1,85 @@
1-
# UDX Worker Node.js
1+
<img src="assets/logo.svg" alt="UDX Worker Node.js">
22

33
[![Docker Pulls](https://img.shields.io/docker/pulls/usabilitydynamics/udx-worker-nodejs.svg)](https://hub.docker.com/r/usabilitydynamics/udx-worker-nodejs) [![License](https://img.shields.io/github/license/udx/worker-nodejs.svg)](LICENSE)
44

5-
**A versatile Docker image for running Node.js applications with built-in process management, providing a ready-to-use environment to deploy and manage your JavaScript projects.**
5+
**Node.js runtime image built on UDX Worker.**
66

7-
[Quick Start](#-quick-start)[Development](#-development)[Documentation](#-documentation)[Contributing](#-contributing)
7+
[Quick Start](#quick-start)[Usage](#usage)[Development](#development)[Resources](#resources)
88

9-
## 🚀 Overview
9+
## Overview
1010

11-
UDX Worker Node.js is a specialized Docker image built on UDX Worker that provides:
11+
UDX Worker Node.js is a Docker image that provides a ready-to-use Node.js runtime with the same operational model as `udx/worker` (https://github.com/udx/worker).
1212

13-
- 🔧 **Node.js Runtime**: Ready-to-use environment for JavaScript applications
14-
- 📦 **Process Management**: Built-in supervisor-based service management
15-
- 🛠️ **Service Configuration**: YAML-based service definition and control
16-
- 🔄 **Zero Downtime**: Seamless application updates and restarts
17-
- 🏗️ **Base Image**: Built on `udx-worker` for secure, efficient operations
13+
## Quick Start
1814

19-
## 👨‍💻 Development
15+
Requirements: Docker and Node.js (for the CLI).
2016

21-
### 📋 Prerequisites
22-
23-
- `Docker` installed and running on your system
24-
- Node.js application code (optional)
25-
26-
## 🚀 Quick Start
27-
28-
### Example 1: Simple Service
29-
30-
1. Create a service configuration in `.config/worker/services.yaml`:
31-
32-
```yaml
33-
kind: workerService
34-
version: udx.io/worker-v1/service
35-
services:
36-
- name: "node-app"
37-
command: "node index.js"
38-
autostart: true
39-
autorestart: true
40-
envs:
41-
- "PORT=3000"
42-
```
43-
44-
2. Pull and run the image:
17+
1. Install the deployment CLI ([@udx/worker-deployment](https://www.npmjs.com/package/@udx/worker-deployment)).
4518

4619
```bash
47-
docker pull usabilitydynamics/udx-worker-nodejs:latest
48-
docker run -d --name my-node-app -p 3000:3000 -v $(pwd)/.config:/home/udx/.config usabilitydynamics/udx-worker-nodejs:latest
49-
```
50-
51-
### Example 2: Custom Application
52-
53-
1. Create your service configuration in `.config/worker/services.yaml`:
54-
55-
```yaml
56-
kind: workerService
57-
version: udx.io/worker-v1/service
58-
services:
59-
- name: "api-server"
60-
command: "node api/server.js"
61-
autostart: true
62-
autorestart: true
63-
envs:
64-
- "PORT=3000"
65-
- "NODE_ENV=production"
66-
- name: "worker-queue"
67-
command: "node worker.js"
68-
autostart: true
69-
envs:
70-
- "QUEUE_URL=redis://localhost:6379"
20+
npm install -g @udx/worker-deployment
7121
```
7222

73-
2. Create a `docker-compose.yml`:
74-
75-
```yaml
76-
version: '3'
77-
services:
78-
app:
79-
image: usabilitydynamics/udx-worker-nodejs:latest
80-
volumes:
81-
- ./:/usr/src/app
82-
- ./.config:/home/udx/.config
83-
ports:
84-
- "3000:3000"
85-
```
86-
87-
### Development Setup
88-
89-
1. Clone this repository:
23+
2. Generate a config and edit `deploy.yml` for your app.
9024

91-
```
92-
git clone https://github.com/udx/udx-worker-nodejs.git
93-
cd udx-worker-nodejs
25+
```bash
26+
worker config
9427
```
9528

96-
2. Build the Docker image:
29+
3. Run the container.
9730

31+
```bash
32+
worker run
9833
```
99-
make build
100-
```
101-
102-
3. Run Tests to verify functionality:
10334

104-
```
105-
make run-all-tests
106-
```
35+
## Usage
10736

108-
You can add additional tests in the `src/tests/` directory as needed.
37+
- Deploy configuration: https://github.com/udx/worker-deployment/blob/latest/docs/deploy-config.md
10938

110-
## ⚙️ Configuration
39+
- Service configuration: https://github.com/udx/worker/blob/latest/docs/runtime/services.md
11140

112-
You can configure build and runtime variables in `Makefile.variables`:
41+
- Runtime config and secrets: https://github.com/udx/worker/blob/latest/docs/runtime/config.md
11342

114-
- Node.js version. _(Node.js 20.x LTS supported by default)_
115-
- Port mappings
116-
- Source paths
43+
### Examples
11744

118-
Adjust these variables to suit your environment or specific deployment requirements.
45+
- `src/examples/simple-server` is included as a minimal sample.
11946

120-
## 🛠️ Makefile Commands Helper
47+
## Development
12148

122-
Use make to view all available commands:
49+
```bash
50+
git clone https://github.com/udx/worker-nodejs.git
51+
cd worker-nodejs
12352

53+
make build
54+
make test
12455
```
125-
make help
126-
```
127-
128-
These commands offer options for building, running, and testing your application seamlessly.
129-
130-
## 📚 Documentation
131-
132-
### 🔧 Based on udx-worker
133-
134-
Built on [`udx-worker`](https://github.com/udx/worker), this image benefits from secure, resource-efficient configurations and best practices, providing a reliable foundation for Node.js applications.
13556

136-
### Core Concepts
57+
To run a single test:
13758

138-
- **Process Management**: Uses supervisor-based worker process manager
139-
- **Service Configuration**: Defined through `services.yaml`
140-
- **Configuration**: Customizable through `Makefile.variables`
141-
142-
### Additional Resources
143-
144-
- Build variables can be configured in `Makefile.variables`
145-
- View available commands with `make help`
146-
- Test examples available in `src/tests/`
59+
```bash
60+
make run-test TEST_SCRIPT=10_validate_environment.sh
61+
```
14762

148-
## 🛠️ Development
63+
Build defaults for contributors live in `Makefile.variables` (Node.js version, ports, build args).
14964

150-
Contribute to the project:
65+
## Resources
15166

152-
1. Fork the repository
153-
2. Create your feature branch
154-
3. Submit a pull request
67+
- Base image docs: https://github.com/udx/worker/tree/latest/docs
68+
- Deployment CLI: https://github.com/udx/worker-deployment/tree/latest/docs
69+
- Docker Hub: https://hub.docker.com/r/usabilitydynamics/udx-worker-nodejs
15570

156-
## 🤝 Contributing
157-
We welcome contributions! Here's how you can help:
71+
## Contributing
15872

15973
1. Fork the repository
16074
2. Create a feature branch
16175
3. Commit your changes
16276
4. Push to your branch
16377
5. Open a Pull Request
16478

165-
Please ensure your PR:
166-
- Follows our coding standards
167-
- Includes appropriate tests
168-
- Updates relevant documentation
169-
170-
## 🔗 Resources
171-
- [Docker Hub](https://hub.docker.com/r/usabilitydynamics/udx-worker-nodejs)
172-
- [UDX Worker Documentation](https://github.com/udx/worker)
173-
- [Product Page](https://udx.io/products/udx-worker-nodejs)
174-
175-
## 🎯 Custom Development
176-
Need specific features or customizations?
177-
[Contact our team](https://udx.io/) for professional development services.
178-
179-
## 📄 License
180-
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
79+
Please ensure your PR includes appropriate tests and documentation updates.
18180

18281
---
82+
18383
<div align="center">
18484
Built by <a href="https://udx.io">UDX</a> © 2025
185-
</div>
85+
</div>

0 commit comments

Comments
 (0)