Skip to content

Commit 23a3aaa

Browse files
committed
dd script to build inside docker
1 parent 358512f commit 23a3aaa

File tree

4 files changed

+88
-13
lines changed

4 files changed

+88
-13
lines changed

.devcontainer/install-deps.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
#!/bin/bash
22

3-
set -e
3+
SUDO_PATH=$(which sudo)
4+
function sudo() {
5+
if [ "$UID" -eq 0 ]; then
6+
"$@"
7+
else
8+
${SUDO_PATH} "$@"
9+
fi
10+
}
411

5-
sudo apt-get update && sudo apt-get install -y --no-install-recommends \
12+
set -ex
13+
14+
export DEBIAN_FRONTEND=noninteractive
15+
sudo apt-get update && \
16+
sudo apt-get install -y --no-install-recommends \
617
build-essential \
718
device-tree-compiler \
819
gperf g++-multilib gcc-multilib \

Dockerfile.build

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# syntax=docker/dockerfile:1
2-
FROM golang:1.25.1-trixie
2+
FROM --platform=${BUILDPLATFORM} golang:1.25.1-trixie AS builder
33

44
ENV GOTOOLCHAIN=local
5-
ENV GOPATH /go
6-
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
5+
ENV GOPATH=/go
6+
ENV PATH=$GOPATH/bin:/usr/local/go/bin:$PATH
77

8-
ADD .devcontainer/install-deps.sh /install-deps.sh
8+
COPY .devcontainer/install-deps.sh /install-deps.sh
99
RUN /install-deps.sh
1010

1111
# Create build directory

Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ KVM_PKG_NAME := github.com/jetkvm/kvm
1111
BUILDKIT_FLAVOR := arm-rockchip830-linux-uclibcgnueabihf
1212
BUILDKIT_PATH ?= /opt/jetkvm-native-buildkit
1313
SKIP_NATIVE_IF_EXISTS ?= 0
14-
14+
SKIP_UI_BUILD ?= 0
1515

1616
GO_BUILD_ARGS := -tags netgo -tags timetzdata
1717
GO_RELEASE_BUILD_ARGS := -trimpath $(GO_BUILD_ARGS)
@@ -88,6 +88,9 @@ build_dev_test: build_test2json build_gotestsum
8888
tar czfv device-tests.tar.gz -C $(BIN_DIR)/tests .
8989

9090
frontend:
91+
@if [ "$(SKIP_UI_BUILD)" = "1" ]; then \
92+
echo "Skipping frontend build..."; \
93+
else \
9194
cd ui && npm ci && npm run build:device && \
9295
find ../static/ \
9396
-type f \
@@ -102,8 +105,9 @@ frontend:
102105
-o -name '*.svg' \
103106
-o -name '*.webp' \
104107
-o -name '*.woff2' \
105-
\) \
106-
-exec sh -c 'gzip -9 -kfv {}' \;
108+
\) \
109+
-exec sh -c 'gzip -9 -kfv {}' \; \
110+
fi
107111

108112
dev_release: frontend build_dev
109113
@echo "Uploading release... $(VERSION_DEV)"

dev_deploy.sh

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,16 @@ show_help() {
4141
REMOTE_USER="root"
4242
REMOTE_PATH="/userdata/jetkvm/bin"
4343
SKIP_UI_BUILD=false
44+
SKIP_UI_BUILD_RELEASE=0
4445
SKIP_NATIVE_BUILD=0
4546
RESET_USB_HID_DEVICE=false
4647
LOG_TRACE_SCOPES="${LOG_TRACE_SCOPES:-jetkvm,cloud,websocket,native,jsonrpc}"
4748
RUN_GO_TESTS=false
4849
RUN_GO_TESTS_ONLY=false
4950
INSTALL_APP=false
51+
BUILD_IN_DOCKER=false
52+
DOCKER_BUILD_DEBUG=false
53+
DOCKER_BUILD_TAG=ghcr.io/jetkvm/buildkit:latest
5054

5155
# Parse command line arguments
5256
while [[ $# -gt 0 ]]; do
@@ -71,6 +75,14 @@ while [[ $# -gt 0 ]]; do
7175
RESET_USB_HID_DEVICE=true
7276
shift
7377
;;
78+
--build-in-docker)
79+
BUILD_IN_DOCKER=true
80+
shift
81+
;;
82+
--docker-build-debug)
83+
DOCKER_BUILD_DEBUG=true
84+
shift
85+
;;
7486
--run-go-tests)
7587
RUN_GO_TESTS=true
7688
shift
@@ -103,11 +115,59 @@ if [ -z "$REMOTE_HOST" ]; then
103115
exit 1
104116
fi
105117

118+
# check if the current CPU architecture is x86_64
119+
if [ "$(uname -m)" != "x86_64" ]; then
120+
msg_warn "Warning: This script is only supported on x86_64 architecture"
121+
BUILD_IN_DOCKER=true
122+
fi
123+
124+
if [ "$BUILD_IN_DOCKER" = true ]; then
125+
if [ "$JETKVM_INSIDE_DOCKER" = 1 ]; then
126+
msg_err "Error: already running inside Docker"
127+
exit
128+
fi
129+
130+
BUILD_ARGS="--build-arg BUILDPLATFORM=linux/amd64"
131+
if [ "$DOCKER_BUILD_DEBUG" = true ]; then
132+
BUILD_ARGS="$BUILD_ARGS --progress=plain --no-cache"
133+
fi
134+
135+
msg_info "Checking if Docker is available ..."
136+
if ! command -v docker &> /dev/null; then
137+
msg_err "Error: Docker is not installed"
138+
exit 1
139+
fi
140+
msg_info "▶ Building build environment ..."
141+
TMP_DIR=$(mktemp -d)
142+
cp -r .devcontainer "${TMP_DIR}"
143+
cp go.mod go.sum Dockerfile.build "${TMP_DIR}"
144+
pushd "${TMP_DIR}" > /dev/null
145+
docker build $BUILD_ARGS -t ${DOCKER_BUILD_TAG} -f Dockerfile.build .
146+
popd > /dev/null
147+
rm -rf "${TMP_DIR}"
148+
fi
149+
150+
do_make() {
151+
if [ "$BUILD_IN_DOCKER" = true ]; then
152+
msg_info "▶ Building the project in Docker ..."
153+
docker run \
154+
--interactive \
155+
--tty \
156+
--rm \
157+
--env JETKVM_INSIDE_DOCKER=1 \
158+
-v "$(pwd):/build" \
159+
${DOCKER_BUILD_TAG} make "$@"
160+
else
161+
make "$@"
162+
fi
163+
}
164+
106165
# Build the development version on the host
107166
# When using `make build_release`, the frontend will be built regardless of the `SKIP_UI_BUILD` flag
108-
if [[ "$SKIP_UI_BUILD" = false && "$INSTALL_APP" = false ]]; then
167+
if [[ "$SKIP_UI_BUILD" = false && "$JETKVM_INSIDE_DOCKER" != 1 ]]; then
109168
msg_info "▶ Building frontend"
110-
make frontend
169+
make frontend SKIP_UI_BUILD=0
170+
SKIP_UI_BUILD_RELEASE=1
111171
fi
112172

113173
if [ "$RUN_GO_TESTS" = true ]; then
@@ -155,7 +215,7 @@ fi
155215
if [ "$INSTALL_APP" = true ]
156216
then
157217
msg_info "▶ Building release binary"
158-
make build_release SKIP_NATIVE_IF_EXISTS=${SKIP_NATIVE_BUILD}
218+
do_make build_release SKIP_NATIVE_IF_EXISTS=${SKIP_NATIVE_BUILD} SKIP_UI_BUILD=${SKIP_UI_BUILD_RELEASE}
159219

160220
# Copy the binary to the remote host as if we were the OTA updater.
161221
ssh "${REMOTE_USER}@${REMOTE_HOST}" "cat > /userdata/jetkvm/jetkvm_app.update" < bin/jetkvm_app
@@ -164,7 +224,7 @@ then
164224
ssh "${REMOTE_USER}@${REMOTE_HOST}" "reboot"
165225
else
166226
msg_info "▶ Building development binary"
167-
make build_dev SKIP_NATIVE_IF_EXISTS=${SKIP_NATIVE_BUILD}
227+
do_make build_dev SKIP_NATIVE_IF_EXISTS=${SKIP_NATIVE_BUILD} SKIP_UI_BUILD=${SKIP_UI_BUILD_RELEASE}
168228

169229
# Kill any existing instances of the application
170230
ssh "${REMOTE_USER}@${REMOTE_HOST}" "killall jetkvm_app_debug || true"

0 commit comments

Comments
 (0)