Skip to content

Commit f4bb4ee

Browse files
authored
Merge pull request #10 from fccview/feature/security-improvement
Ehm.. refactored a bunch.. sorry
2 parents e268fbd + e88f364 commit f4bb4ee

26 files changed

+1266
-703
lines changed

.github/workflows/build.yml

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
name: Build
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
push-to-registry:
7+
description: "Whether to push images to the container registry"
8+
required: false
9+
default: false
10+
type: boolean
11+
12+
env:
13+
REGISTRY: ghcr.io
14+
IMAGE_NAME: ${{ github.repository }}
15+
16+
jobs:
17+
build:
18+
runs-on: ${{ matrix.runner }}
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
include:
23+
- platform: linux/amd64
24+
arch: amd64
25+
runner: ubuntu-latest
26+
test: true
27+
- platform: linux/arm64
28+
arch: arm64
29+
runner: ubuntu-24.04-arm
30+
test: true
31+
- platform: linux/arm/v7
32+
arch: armv7
33+
runner: ubuntu-24.04-arm
34+
test: false
35+
36+
steps:
37+
- name: Checkout repository
38+
uses: actions/checkout@v4
39+
40+
- name: Set up QEMU
41+
uses: docker/setup-qemu-action@v3
42+
43+
- name: Set up Docker Buildx
44+
uses: docker/setup-buildx-action@v3
45+
46+
- name: Log in to the Container registry
47+
if: inputs.push-to-registry
48+
uses: docker/login-action@v3
49+
with:
50+
registry: ${{ env.REGISTRY }}
51+
username: ${{ github.actor }}
52+
password: ${{ secrets.GITHUB_TOKEN }}
53+
54+
- name: Extract metadata (tags, labels) for Docker
55+
if: inputs.push-to-registry
56+
id: meta
57+
uses: docker/metadata-action@v5
58+
with:
59+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
60+
61+
- name: Build Docker image
62+
id: build
63+
uses: docker/build-push-action@v6
64+
with:
65+
context: .
66+
platforms: ${{ matrix.platform }}
67+
labels: ${{ steps.meta.outputs.labels }}
68+
load: ${{ matrix.test }}
69+
tags: hypermind-test:${{ github.sha }}
70+
cache-from: type=gha
71+
cache-to: type=gha,mode=max
72+
73+
- name: Run container for testing
74+
if: matrix.test
75+
run: docker run -d --name hypermind-test -p 3000:3000 hypermind-test:${{ github.sha }}
76+
77+
- name: Wait for server to be ready
78+
if: matrix.test
79+
run: |
80+
for i in {1..30}; do
81+
if curl -sf http://localhost:3000/api/stats; then
82+
echo "Server is ready"
83+
exit 0
84+
fi
85+
echo "Waiting for server... ($i/30)"
86+
sleep 1
87+
done
88+
echo "Server failed to start"
89+
docker logs hypermind-test
90+
exit 1
91+
92+
- name: Verify API response
93+
if: matrix.test
94+
run: |
95+
response=$(curl -sf http://localhost:3000/api/stats)
96+
echo "Response: $response"
97+
echo "$response" | jq -e '.count != null and .id != null'
98+
99+
- name: Cleanup test container
100+
if: always() && matrix.test
101+
run: docker rm -f hypermind-test || true
102+
103+
- name: Push by digest
104+
if: inputs.push-to-registry
105+
id: push
106+
uses: docker/build-push-action@v6
107+
with:
108+
context: .
109+
platforms: ${{ matrix.platform }}
110+
labels: ${{ steps.meta.outputs.labels }}
111+
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
112+
cache-from: type=gha
113+
114+
- name: Export digest
115+
if: inputs.push-to-registry
116+
run: |
117+
mkdir -p ${{ runner.temp }}/digests
118+
digest="${{ steps.push.outputs.digest }}"
119+
touch "${{ runner.temp }}/digests/${digest#sha256:}"
120+
121+
- name: Upload digest
122+
if: inputs.push-to-registry
123+
uses: actions/upload-artifact@v4
124+
with:
125+
name: digests-${{ matrix.arch }}
126+
path: ${{ runner.temp }}/digests/*
127+
if-no-files-found: error
128+
retention-days: 1

.github/workflows/ci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
branches: ["main"]
6+
7+
jobs:
8+
build:
9+
uses: ./.github/workflows/build.yml
10+
permissions:
11+
contents: read
12+
with:
13+
push-to-registry: false

.github/workflows/publish.yml

Lines changed: 4 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
name: Publish Docker Image
22

33
on:
4-
pull_request:
5-
branches: ["main"]
64
push:
75
branches: ["main"]
86
release:
@@ -15,73 +13,16 @@ env:
1513

1614
jobs:
1715
build:
18-
runs-on: ${{ matrix.runner }}
16+
uses: ./.github/workflows/build.yml
1917
permissions:
2018
contents: read
2119
packages: write
22-
strategy:
23-
fail-fast: false
24-
matrix:
25-
include:
26-
- platform: linux/amd64
27-
runner: ubuntu-latest
28-
- platform: linux/arm64
29-
runner: ubuntu-24.04-arm
30-
- platform: linux/arm/v7
31-
runner: ubuntu-24.04-arm
32-
33-
steps:
34-
- name: Checkout repository
35-
uses: actions/checkout@v4
36-
37-
- name: Set up QEMU
38-
uses: docker/setup-qemu-action@v3
39-
40-
- name: Set up Docker Buildx
41-
uses: docker/setup-buildx-action@v3
42-
43-
- name: Log in to the Container registry
44-
if: github.event_name != 'pull_request'
45-
uses: docker/login-action@v3
46-
with:
47-
registry: ${{ env.REGISTRY }}
48-
username: ${{ github.actor }}
49-
password: ${{ secrets.GITHUB_TOKEN }}
50-
51-
- name: Extract metadata (tags, labels) for Docker
52-
id: meta
53-
uses: docker/metadata-action@v5
54-
with:
55-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
56-
57-
- name: Build and push by digest
58-
id: build
59-
uses: docker/build-push-action@v6
60-
with:
61-
context: .
62-
platforms: ${{ matrix.platform }}
63-
labels: ${{ steps.meta.outputs.labels }}
64-
outputs: ${{ github.event_name != 'pull_request' && format('type=image,name={0}/{1},push-by-digest=true,name-canonical=true,push=true', env.REGISTRY, env.IMAGE_NAME) || 'type=docker' }}
65-
66-
- name: Export digest
67-
if: github.event_name != 'pull_request'
68-
run: |
69-
mkdir -p ${{ runner.temp }}/digests
70-
digest="${{ steps.build.outputs.digest }}"
71-
touch "${{ runner.temp }}/digests/${digest#sha256:}"
72-
73-
- name: Upload digest
74-
if: github.event_name != 'pull_request'
75-
uses: actions/upload-artifact@v4
76-
with:
77-
name: digests-${{ matrix.platform == 'linux/amd64' && 'amd64' || matrix.platform == 'linux/arm64' && 'arm64' || 'armv7' }}
78-
path: ${{ runner.temp }}/digests/*
79-
if-no-files-found: error
80-
retention-days: 1
20+
secrets: inherit
21+
with:
22+
push-to-registry: true
8123

8224
merge:
8325
runs-on: ubuntu-latest
84-
if: github.event_name != 'pull_request'
8526
needs: build
8627
permissions:
8728
contents: read

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ COPY package*.json ./
66

77
RUN npm ci --omit=dev
88

9+
COPY public/ ./public/
910
COPY server.js hypermind2.svg LICENSE ./
11+
COPY src/ ./src/
1012

1113
ENV PORT=3000
1214
ENV NODE_ENV=production

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ services:
7373

7474
```
7575

76+
## Environment Variables
77+
78+
| Variable | Default | Description |
79+
|----------|---------|-------------|
80+
| `PORT` | `3000` | The port the web dashboard listens on. Since `--network host` is used, this port opens directly on the host. |
81+
| `MAX_PEERS` | `10000` | Maximum number of peers to track in the swarm. Unless you're expecting the entire internet to join, the default is probably fine. |
82+
7683
## Usage
7784

7885
Open your browser to: `http://localhost:3000`

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ services:
66
restart: unless-stopped
77
environment:
88
- PORT=3000
9+
- MAX_PEERS=10000

package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"homepage": "https://github.com/lklynet/hypermind#readme",
2727
"type": "commonjs",
2828
"dependencies": {
29+
"dotenv": "^17.2.3",
2930
"express": "^5.2.1",
3031
"hyperswarm": "^4.16.0"
3132
}

0 commit comments

Comments
 (0)