Skip to content

Commit 43bf322

Browse files
authored
0.3.8 (#275)
2 parents 4351cc8 + ec5226e commit 43bf322

File tree

113 files changed

+5726
-2944
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+5726
-2944
lines changed

.devcontainer/devcontainer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@
66
// Should match what is defined in ui/package.json
77
"version": "21.1.0"
88
}
9-
}
9+
},
10+
"mounts": [
11+
"source=${localEnv:HOME}/.ssh,target=/home/vscode/.ssh,type=bind,consistency=cached"
12+
]
1013
}
14+

.github/workflows/build.yml

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
name: build image
2+
on:
3+
push:
4+
branches:
5+
- dev
6+
- main
7+
workflow_dispatch:
8+
pull_request_review:
9+
types: [submitted]
10+
11+
jobs:
12+
build:
13+
runs-on: buildjet-4vcpu-ubuntu-2204
14+
name: Build
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
- name: Set up Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: v21.1.0
22+
cache: 'npm'
23+
cache-dependency-path: '**/package-lock.json'
24+
- name: Set up Golang
25+
uses: actions/setup-go@v4
26+
with:
27+
go-version: '1.24.0'
28+
- name: Build frontend
29+
run: |
30+
make frontend
31+
- name: Build application
32+
run: |
33+
make build_dev
34+
- name: Upload artifact
35+
uses: actions/upload-artifact@v4
36+
with:
37+
name: jetkvm-app
38+
path: bin/jetkvm_app
39+
deploy_and_test:
40+
runs-on: buildjet-4vcpu-ubuntu-2204
41+
name: Smoke test
42+
needs: build
43+
concurrency:
44+
group: smoketest-jk
45+
steps:
46+
- name: Download artifact
47+
uses: actions/download-artifact@v4
48+
with:
49+
name: jetkvm-app
50+
- name: Configure WireGuard and check connectivity
51+
run: |
52+
WG_KEY_FILE=$(mktemp)
53+
echo -n "$CI_WG_PRIVATE" > $WG_KEY_FILE && \
54+
sudo apt-get update && sudo apt-get install -y wireguard-tools && \
55+
sudo ip link add dev wg-ci type wireguard && \
56+
sudo ip addr add $CI_WG_IPS dev wg-ci && \
57+
sudo wg set wg-ci listen-port 51820 \
58+
private-key $WG_KEY_FILE \
59+
peer $CI_WG_PUBLIC \
60+
allowed-ips $CI_WG_ALLOWED_IPS \
61+
endpoint $CI_WG_ENDPOINT \
62+
persistent-keepalive 15 && \
63+
sudo ip link set up dev wg-ci && \
64+
sudo ip r r $CI_HOST via $CI_WG_GATEWAY dev wg-ci
65+
ping -c1 $CI_HOST || (echo "Failed to ping $CI_HOST" && sudo wg show wg-ci && ip r && exit 1)
66+
env:
67+
CI_HOST: ${{ vars.JETKVM_CI_HOST }}
68+
CI_WG_IPS: ${{ vars.JETKVM_CI_WG_IPS }}
69+
CI_WG_GATEWAY: ${{ vars.JETKVM_CI_GATEWAY }}
70+
CI_WG_ALLOWED_IPS: ${{ vars.JETKVM_CI_WG_ALLOWED_IPS }}
71+
CI_WG_PUBLIC: ${{ secrets.JETKVM_CI_WG_PUBLIC }}
72+
CI_WG_PRIVATE: ${{ secrets.JETKVM_CI_WG_PRIVATE }}
73+
CI_WG_ENDPOINT: ${{ secrets.JETKVM_CI_WG_ENDPOINT }}
74+
- name: Configure SSH
75+
run: |
76+
# Write SSH private key to a file
77+
SSH_PRIVATE_KEY=$(mktemp)
78+
echo "$CI_SSH_PRIVATE" > $SSH_PRIVATE_KEY
79+
chmod 0600 $SSH_PRIVATE_KEY
80+
# Configure SSH
81+
mkdir -p ~/.ssh
82+
cat <<EOF >> ~/.ssh/config
83+
Host jkci
84+
HostName $CI_HOST
85+
User $CI_USER
86+
StrictHostKeyChecking no
87+
UserKnownHostsFile /dev/null
88+
IdentityFile $SSH_PRIVATE_KEY
89+
EOF
90+
env:
91+
CI_USER: ${{ vars.JETKVM_CI_USER }}
92+
CI_HOST: ${{ vars.JETKVM_CI_HOST }}
93+
CI_SSH_PRIVATE: ${{ secrets.JETKVM_CI_SSH_PRIVATE }}
94+
- name: Deploy application
95+
run: |
96+
set -e
97+
# Copy the binary to the remote host
98+
echo "+ Copying the application to the remote host"
99+
cat jetkvm_app | gzip | ssh jkci "cat > /userdata/jetkvm/jetkvm_app.update.gz"
100+
# Deploy and run the application on the remote host
101+
echo "+ Deploying the application on the remote host"
102+
ssh jkci ash <<EOF
103+
# Extract the binary
104+
gzip -d /userdata/jetkvm/jetkvm_app.update.gz
105+
# Flush filesystem buffers to ensure all data is written to disk
106+
sync
107+
# Clear the filesystem caches to force a read from disk
108+
echo 1 > /proc/sys/vm/drop_caches
109+
# Reboot the application
110+
reboot -d 5 -f &
111+
EOF
112+
sleep 10
113+
echo "Deployment complete, waiting for JetKVM to come back online "
114+
function check_online() {
115+
for i in {1..60}; do
116+
if ping -c1 -w1 -W1 -q $CI_HOST >/dev/null; then
117+
echo "JetKVM is back online"
118+
return 0
119+
fi
120+
echo -n "."
121+
sleep 1
122+
done
123+
echo "JetKVM did not come back online within 60 seconds"
124+
return 1
125+
}
126+
check_online
127+
env:
128+
CI_HOST: ${{ vars.JETKVM_CI_HOST }}
129+
- name: Run smoke tests
130+
run: |
131+
echo "+ Checking the status of the device"
132+
curl -v http://$CI_HOST/device/status && echo
133+
echo "+ Collecting logs"
134+
ssh jkci "cat /userdata/jetkvm/last.log" > last.log
135+
cat last.log
136+
env:
137+
CI_HOST: ${{ vars.JETKVM_CI_HOST }}
138+
- name: Upload logs
139+
uses: actions/upload-artifact@v4
140+
with:
141+
name: device-logs
142+
path: last.log

.github/workflows/golangci-lint.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
name: golangci-lint
3+
on:
4+
push:
5+
paths:
6+
- "go.sum"
7+
- "go.mod"
8+
- "**.go"
9+
- ".github/workflows/golangci-lint.yml"
10+
- ".golangci.yml"
11+
pull_request:
12+
13+
permissions: # added using https://github.com/step-security/secure-repo
14+
contents: read
15+
16+
jobs:
17+
golangci:
18+
permissions:
19+
contents: read # for actions/checkout to fetch code
20+
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
21+
name: lint
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
26+
- name: Install Go
27+
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
28+
with:
29+
go-version: 1.23.x
30+
- name: Lint
31+
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6.1.1
32+
with:
33+
args: --verbose
34+
version: v1.62.0

.golangci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
linters:
3+
enable:
4+
# - goimports
5+
# - misspell
6+
# - revive
7+
8+
issues:
9+
exclude-rules:
10+
- path: _test.go
11+
linters:
12+
- errcheck

Makefile

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,39 @@
1-
VERSION_DEV := 0.3.8-dev$(shell date +%Y%m%d%H%M)
2-
VERSION := 0.3.7
1+
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
2+
BUILDDATE ?= $(shell date -u +%FT%T%z)
3+
BUILDTS ?= $(shell date -u +%s)
4+
REVISION ?= $(shell git rev-parse HEAD)
5+
VERSION_DEV := 0.3.9-dev$(shell date +%Y%m%d%H%M)
6+
VERSION := 0.3.8
7+
8+
PROMETHEUS_TAG := github.com/prometheus/common/version
9+
KVM_PKG_NAME := github.com/jetkvm/kvm
10+
11+
GO_LDFLAGS := \
12+
-s -w \
13+
-X $(PROMETHEUS_TAG).Branch=$(BRANCH) \
14+
-X $(PROMETHEUS_TAG).BuildDate=$(BUILDDATE) \
15+
-X $(PROMETHEUS_TAG).Revision=$(REVISION) \
16+
-X $(KVM_PKG_NAME).builtTimestamp=$(BUILDTS)
317

418
hash_resource:
519
@shasum -a 256 resource/jetkvm_native | cut -d ' ' -f 1 > resource/jetkvm_native.sha256
620

721
build_dev: hash_resource
822
@echo "Building..."
9-
GOOS=linux GOARCH=arm GOARM=7 go build -ldflags="-s -w -X kvm.builtAppVersion=$(VERSION_DEV)" -o bin/jetkvm_app cmd/main.go
23+
GOOS=linux GOARCH=arm GOARM=7 go build -ldflags="$(GO_LDFLAGS) -X $(KVM_PKG_NAME).builtAppVersion=$(VERSION_DEV)" -o bin/jetkvm_app cmd/main.go
1024

1125
frontend:
1226
cd ui && npm ci && npm run build:device
1327

14-
dev_release: build_dev
28+
dev_release: frontend build_dev
1529
@echo "Uploading release..."
1630
@shasum -a 256 bin/jetkvm_app | cut -d ' ' -f 1 > bin/jetkvm_app.sha256
1731
rclone copyto bin/jetkvm_app r2://jetkvm-update/app/$(VERSION_DEV)/jetkvm_app
1832
rclone copyto bin/jetkvm_app.sha256 r2://jetkvm-update/app/$(VERSION_DEV)/jetkvm_app.sha256
1933

2034
build_release: frontend hash_resource
2135
@echo "Building release..."
22-
GOOS=linux GOARCH=arm GOARM=7 go build -ldflags="-s -w -X kvm.builtAppVersion=$(VERSION)" -o bin/jetkvm_app cmd/main.go
36+
GOOS=linux GOARCH=arm GOARM=7 go build -ldflags="$(GO_LDFLAGS) -X $(KVM_PKG_NAME).builtAppVersion=$(VERSION)" -o bin/jetkvm_app cmd/main.go
2337

2438
release:
2539
@if rclone lsf r2://jetkvm-update/app/$(VERSION)/ | grep -q "jetkvm_app"; then \

block_device.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package kvm
33
import (
44
"context"
55
"errors"
6-
"log"
76
"net"
87
"os"
98
"time"
@@ -94,7 +93,8 @@ func (d *NBDDevice) Start() error {
9493
// Remove the socket file if it already exists
9594
if _, err := os.Stat(nbdSocketPath); err == nil {
9695
if err := os.Remove(nbdSocketPath); err != nil {
97-
log.Fatalf("Failed to remove existing socket file %s: %v", nbdSocketPath, err)
96+
logger.Errorf("Failed to remove existing socket file %s: %v", nbdSocketPath, err)
97+
os.Exit(1)
9898
}
9999
}
100100

@@ -134,22 +134,22 @@ func (d *NBDDevice) runServerConn() {
134134
MaximumBlockSize: uint32(16 * 1024),
135135
SupportsMultiConn: false,
136136
})
137-
log.Println("nbd server exited:", err)
137+
logger.Infof("nbd server exited: %v", err)
138138
}
139139

140140
func (d *NBDDevice) runClientConn() {
141141
err := client.Connect(d.clientConn, d.dev, &client.Options{
142142
ExportName: "jetkvm",
143143
BlockSize: uint32(4 * 1024),
144144
})
145-
log.Println("nbd client exited:", err)
145+
logger.Infof("nbd client exited: %v", err)
146146
}
147147

148148
func (d *NBDDevice) Close() {
149149
if d.dev != nil {
150150
err := client.Disconnect(d.dev)
151151
if err != nil {
152-
log.Println("error disconnecting nbd client:", err)
152+
logger.Warnf("error disconnecting nbd client: %v", err)
153153
}
154154
_ = d.dev.Close()
155155
}

0 commit comments

Comments
 (0)