Skip to content

Commit 56fd06b

Browse files
committed
new docker workflow
1 parent c83c4ff commit 56fd06b

File tree

4 files changed

+48
-50
lines changed

4 files changed

+48
-50
lines changed

.dockerignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
node_modules
22
npm-debug.log
3+
dist
34
logs
5+
.cache
46
.git
57
.github
68
.vscode
9+
.husky
710
Dockerfile
811
docker-compose.yml
912
README.md
1013
LICENSE
1114
biome.json
12-
commitlint.config.mjs
15+
commitlint.config.mjs
16+
sea-config.json

.github/workflows/docker-image.yml

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,58 @@
11
name: Docker Image CI
22

33
on:
4+
push:
5+
branches: ['**']
46
release:
57
types: [created]
68

9+
env:
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: ${{ github.repository }}
12+
713
jobs:
814
build:
9-
name: Publish Docker image
15+
name: Build and push Docker image
1016
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
packages: write
1120

1221
steps:
1322
- name: Checkout
1423
uses: actions/checkout@v4
1524

16-
- name: Get package version
17-
id: package-version
18-
uses: martinbeentjes/npm-get-version-action@v1.3.1
19-
2025
- name: Set up QEMU
2126
uses: docker/setup-qemu-action@v3
2227

2328
- name: Set up Docker Buildx
2429
uses: docker/setup-buildx-action@v3
2530

26-
- name: Generate Docker meta
31+
- name: Log in to GHCR
32+
uses: docker/login-action@v3
33+
with:
34+
registry: ${{ env.REGISTRY }}
35+
username: ${{ github.actor }}
36+
password: ${{ secrets.GITHUB_TOKEN }}
37+
38+
- name: Generate Docker metadata
2739
id: meta
2840
uses: docker/metadata-action@v5
2941
with:
30-
images: ${{ secrets.DOCKERHUB_USERNAME }}/nodelink
42+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
3143
tags: |
32-
type=raw,value=${{ steps.package-version.outputs.current-version}}
33-
type=raw,value=latest
34-
35-
- name: Login to Docker Hub
36-
uses: docker/login-action@v3
37-
with:
38-
username: ${{ secrets.DOCKERHUB_USERNAME }}
39-
password: ${{ secrets.DOCKERHUB_TOKEN }}
44+
type=ref,event=branch
45+
type=sha,prefix=
46+
type=semver,pattern={{version}}
47+
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') || github.event_name == 'release' }}
4048
41-
- name: Build and Push
49+
- name: Build and push
4250
uses: docker/build-push-action@v5
4351
with:
52+
context: .
4453
push: true
45-
platforms: linux/amd64, linux/arm64
54+
platforms: linux/amd64,linux/arm64
4655
tags: ${{ steps.meta.outputs.tags }}
4756
labels: ${{ steps.meta.outputs.labels }}
57+
cache-from: type=gha
58+
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,28 @@
1-
# Stage 1: Builder - Install dependencies
1+
# Stage 1: Builder - Install dependencies and bundle
22
FROM node:25-alpine AS builder
33

4-
# Install git (required for npm to install dependencies from GitHub)
54
RUN apk add --no-cache git
65

7-
# Set working directory
86
WORKDIR /app
97

10-
# Copy package.json and package-lock.json (if available) to leverage Docker cache
11-
# Use wildcards to ensure both package.json and package-lock.json (or yarn.lock/pnpm-lock.yaml) are copied
128
COPY package.json ./
13-
14-
# Install production dependencies
15-
# This command automatically handles package-lock.json if it exists, otherwise it creates one.
16-
# For Bun, you might use 'bun install --production'.
179
RUN npm install
1810

19-
# Stage 2: Runner - Copy application code and run
20-
FROM node:25-alpine
21-
22-
# Set working directory
23-
WORKDIR /app
24-
25-
# Copy production dependencies from the builder stage
26-
COPY --from=builder /app/node_modules ./node_modules
27-
28-
# Copy the rest of the application source code
29-
# This includes the 'src' directory, default config, and package files for runtime information.
3011
COPY src/ ./src/
12+
COPY scripts/ ./scripts/
3113
COPY config.default.js ./config.default.js
32-
COPY package.json ./package.json
14+
COPY plugins/ ./plugins/
15+
16+
RUN npm install --no-save esbuild && node scripts/build.js
3317

34-
# Expose the port the application listens on (default is 3000 from config.default.js)
35-
EXPOSE 3000
18+
# Stage 2: Runner - Minimal image with bundled output
19+
FROM node:25-alpine
20+
21+
WORKDIR /app
3622

37-
# Set environment variables for configuration
38-
# These can be overridden via docker-compose.yml or 'docker run -e'
39-
# Example: NODELINK_SERVER_PASSWORD=your_secure_password
40-
ENV NODELINK_SERVER_PORT=3000 \
41-
NODELINK_SERVER_HOST=0.0.0.0 \
42-
NODELINK_CLUSTER_ENABLED=true
23+
# Copy bundled application and native modules from builder
24+
COPY --from=builder /app/dist/ ./dist/
25+
COPY --from=builder /app/config.default.js ./config.default.js
26+
COPY --from=builder /app/package.json ./package.json
4327

44-
# Command to run the application
45-
# It uses the 'start' script defined in package.json
46-
CMD ["npm", "start"]
28+
CMD ["node", "--dns-result-order=ipv4first", "--openssl-legacy-provider", "dist/main.mjs"]

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ services:
254254
# NODELINK_MIX_AUTOCLEANUP: "true"
255255

256256
# volumes:
257+
# - ./config.js:/app/config.js
257258
# - ./local-music:/app/local-music
258259
# - ./logs:/app/logs
259260
# - ./.cache:/app/.cache

0 commit comments

Comments
 (0)