Skip to content

Commit

Permalink
refactor(docker): remove yq dependency and simplify config creation
Browse files Browse the repository at this point in the history
- Removed `yq` installation from Dockerfile to reduce image size.
- Simplified default configuration file creation in entrypoint.sh by directly writing YAML content, eliminating the need for `yq`.
- Removed `yq` installation step from hardware.Dockerfile and adjusted file copying accordingly.
  • Loading branch information
skrashevich committed May 7, 2024
1 parent 3ab93fc commit 85392fc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ FROM base
# and other common tools for the echo source.
# alsa-plugins-pulse for ALSA support (+0MB)
# font-droid for FFmpeg drawtext filter (+2MB)
RUN apk add --no-cache tini ffmpeg bash curl jq alsa-plugins-pulse font-droid yq
RUN apk add --no-cache tini ffmpeg bash curl jq alsa-plugins-pulse font-droid

# Hardware Acceleration for Intel CPU (+50MB)
ARG TARGETARCH
Expand Down
16 changes: 4 additions & 12 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,11 @@
CONFIG_PATH=${CONFIG_PATH:-/config/go2rtc.yaml}
PORT=${PORT:-1984}

# Check if yq is available
if ! command -v yq > /dev/null; then
echo "yq command not found. Please install yq."
exit 1
fi

# Create config file with default content if it doesn't exist
# Create the config file with default settings if it doesn't exist
if [ ! -f "$CONFIG_PATH" ]; then
mkdir -p "$(dirname "$CONFIG_PATH")"
if ! yq -o yaml e -n ".api.listen = \":$PORT\"" > "$CONFIG_PATH"; then
echo "Failed to create default config file at $CONFIG_PATH"
exit 1
fi
echo "api:" > "$CONFIG_PATH"
echo -e "\tlisten: ':$PORT'" >> "$CONFIG_PATH"
fi

exec go2rtc -config "$CONFIG_PATH" "$@"
exec go2rtc -config "$CONFIG_PATH" "$@"
3 changes: 1 addition & 2 deletions hardware.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ RUN --mount=type=cache,target=/root/.cache/go-build go mod download

COPY . .
RUN --mount=type=cache,target=/root/.cache/go-build CGO_ENABLED=0 go build -ldflags "-s -w" -trimpath
RUN --mount=type=cache,target=/root/.cache/go-build CGO_ENABLED=0 go install -ldflags "-s -w" -trimpath github.com/mikefarah/yq/v4@v4.42.1

# 2. Collect all files
FROM scratch AS rootfs

COPY --link --from=build /build/go2rtc /go/bin/yq /usr/local/bin/
COPY --link --from=build /build/go2rtc /usr/local/bin/
COPY --link --from=ngrok /bin/ngrok /usr/local/bin/

# 3. Final image
Expand Down

0 comments on commit 85392fc

Please sign in to comment.