Skip to content

Commit 1a9daa0

Browse files
committed
add script to build inside docker
1 parent 358512f commit 1a9daa0

File tree

4 files changed

+85
-12
lines changed

4 files changed

+85
-12
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: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ LOG_TRACE_SCOPES="${LOG_TRACE_SCOPES:-jetkvm,cloud,websocket,native,jsonrpc}"
4747
RUN_GO_TESTS=false
4848
RUN_GO_TESTS_ONLY=false
4949
INSTALL_APP=false
50+
BUILD_IN_DOCKER=false
51+
DOCKER_BUILD_DEBUG=false
52+
DOCKER_BUILD_TAG=ghcr.io/jetkvm/buildkit:latest
5053

5154
# Parse command line arguments
5255
while [[ $# -gt 0 ]]; do
@@ -71,6 +74,14 @@ while [[ $# -gt 0 ]]; do
7174
RESET_USB_HID_DEVICE=true
7275
shift
7376
;;
77+
--build-in-docker)
78+
BUILD_IN_DOCKER=true
79+
shift
80+
;;
81+
--docker-build-debug)
82+
DOCKER_BUILD_DEBUG=true
83+
shift
84+
;;
7485
--run-go-tests)
7586
RUN_GO_TESTS=true
7687
shift
@@ -103,9 +114,56 @@ if [ -z "$REMOTE_HOST" ]; then
103114
exit 1
104115
fi
105116

117+
# check if the current CPU architecture is x86_64
118+
if [ "$(uname -m)" != "x86_64" ]; then
119+
msg_warn "Warning: This script is only supported on x86_64 architecture"
120+
BUILD_IN_DOCKER=true
121+
fi
122+
123+
if [ "$BUILD_IN_DOCKER" = true ]; then
124+
if [ "$JETKVM_INSIDE_DOCKER" = 1 ]; then
125+
msg_err "Error: already running inside Docker"
126+
exit
127+
fi
128+
129+
BUILD_ARGS="--build-arg BUILDPLATFORM=linux/amd64"
130+
if [ "$DOCKER_BUILD_DEBUG" = true ]; then
131+
BUILD_ARGS="$BUILD_ARGS --progress=plain --no-cache"
132+
fi
133+
134+
msg_info "Checking if Docker is available ..."
135+
if ! command -v docker &> /dev/null; then
136+
msg_err "Error: Docker is not installed"
137+
exit 1
138+
fi
139+
msg_info "▶ Building build environment ..."
140+
TMP_DIR=$(mktemp -d)
141+
cp -r .devcontainer "${TMP_DIR}"
142+
cp go.mod go.sum Dockerfile.build "${TMP_DIR}"
143+
pushd "${TMP_DIR}" > /dev/null
144+
docker build $BUILD_ARGS -t ${DOCKER_BUILD_TAG} -f Dockerfile.build .
145+
popd > /dev/null
146+
rm -rf "${TMP_DIR}"
147+
fi
148+
149+
do_make() {
150+
if [ "$BUILD_IN_DOCKER" = true ]; then
151+
msg_info "▶ Building the project in Docker ..."
152+
docker run \
153+
--interactive \
154+
--tty \
155+
--rm \
156+
--env JETKVM_INSIDE_DOCKER=1 \
157+
-v "$(pwd):/build" \
158+
${DOCKER_BUILD_TAG} make "$@"
159+
else
160+
make "$@"
161+
fi
162+
}
163+
106164
# Build the development version on the host
107165
# 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
166+
if [[ "$SKIP_UI_BUILD" = false && "$JETKVM_INSIDE_DOCKER" != 1 ]]; then
109167
msg_info "▶ Building frontend"
110168
make frontend
111169
fi
@@ -155,7 +213,7 @@ fi
155213
if [ "$INSTALL_APP" = true ]
156214
then
157215
msg_info "▶ Building release binary"
158-
make build_release SKIP_NATIVE_IF_EXISTS=${SKIP_NATIVE_BUILD}
216+
do_make build_release SKIP_NATIVE_IF_EXISTS=${SKIP_NATIVE_BUILD}
159217

160218
# Copy the binary to the remote host as if we were the OTA updater.
161219
ssh "${REMOTE_USER}@${REMOTE_HOST}" "cat > /userdata/jetkvm/jetkvm_app.update" < bin/jetkvm_app
@@ -164,7 +222,7 @@ then
164222
ssh "${REMOTE_USER}@${REMOTE_HOST}" "reboot"
165223
else
166224
msg_info "▶ Building development binary"
167-
make build_dev SKIP_NATIVE_IF_EXISTS=${SKIP_NATIVE_BUILD}
225+
do_make build_dev SKIP_NATIVE_IF_EXISTS=${SKIP_NATIVE_BUILD}
168226

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

0 commit comments

Comments
 (0)