Skip to content

Fix Docker build directory creation and environment variable issues#4

Merged
dbir0 merged 3 commits intomainfrom
copilot/fix-62d81484-adf7-46d5-a2d8-573059903a3a
Sep 25, 2025
Merged

Fix Docker build directory creation and environment variable issues#4
dbir0 merged 3 commits intomainfrom
copilot/fix-62d81484-adf7-46d5-a2d8-573059903a3a

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Sep 25, 2025

This PR resolves the Docker build failures that were preventing OpenWrt from building successfully in containerized environments, specifically addressing the error:

touch: cannot touch '/workspace/build/host/.prereq-build': No such file or directory
gmake: *** [/workspace/build/openwrt/include/toplevel.mk:184: /workspace/build/host/.prereq-build] Error 1

Root Cause Analysis

The build failures were caused by multiple interconnected issues:

  1. Missing Directory Structure: The setup_openwrt() function attempted to clean directories that didn't exist yet, and never created the required build directory structure before moving OpenWrt source files
  2. Readonly Variable Conflicts: Using UID and GID environment variables caused bash errors since these are readonly shell variables
  3. Insufficient Volume Mounting: Docker volumes were mounted only for /workspace/build/openwrt/ but OpenWrt's build system needs to create directories at /workspace/build/host/
  4. Dockerfile Syntax Issues: The heredoc syntax for creating the entrypoint script was causing Docker build failures

Changes Made

scripts/build.sh

  • Added proper directory creation in setup_openwrt() with mkdir -p "$BUILD_DIR" and mkdir -p "$OPENWRT_DIR"
  • Enhanced build_firmware() to create OpenWrt-required directories (host/, staging_dir/) before build starts

scripts/docker-build.sh

  • Changed from readonly UID/GID to HOST_UID/HOST_GID environment variables in both run_build() and open_shell() functions

docker-compose.yml

  • Updated environment variable references from ${UID:-1000} to ${HOST_UID:-1000}
  • Changed volume mount from /workspace/build/openwrt:rw to /workspace/build:rw to allow OpenWrt build system full access to create required subdirectories

Dockerfile

  • Rewrote entrypoint script creation using echo commands instead of heredoc to fix Docker parsing issues
  • Simplified environment variables to avoid conflicts with OpenWrt's build detection

Verification

The fix has been tested and verified:

  • Docker image builds successfully without syntax errors
  • Container starts properly with correct user permissions and environment
  • OpenWrt build process proceeds through initial setup and prerequisite checks
  • The original directory creation error is completely resolved

The build now progresses to the feed installation phase (which fails in sandboxed environments due to network restrictions, as expected), demonstrating that the core directory and permission issues have been successfully resolved.

This enables the GitHub Actions workflow to build OpenWrt firmware images in Docker containers as intended.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • git.openwrt.org
    • Triggering command: /usr/lib/git-core/git-remote-https origin REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Openwrt is not building in docker. It seems like it's due to all of the handling of the opernwrt paths to various directories.

touch: cannot touch '/workspace/build/host/.prereq-build': No such file or directory
gmake: *** [/workspace/build/openwrt/include/toplevel.mk:184: /workspace/build/host/.prereq-build] Error 1

It should successfully build in docker as a part of github action workflow, it currently doesn't build successfully


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits September 25, 2025 17:24
Co-authored-by: dbir0 <10812601+dbir0@users.noreply.github.com>
…variable problems

Co-authored-by: dbir0 <10812601+dbir0@users.noreply.github.com>
Copilot AI changed the title Openwrt is not building in docker. It seems like it's due to all of the handling of the opernwrt paths to various directories. touch: cannot touch '/workspace/build/host/.prereq-build': No such file or directory gmake: *** [/workspace/build/openwrt/i... Fix Docker build directory creation and environment variable issues Sep 25, 2025
Copilot AI requested a review from dbir0 September 25, 2025 17:39
@dbir0
Copy link
Copy Markdown
Owner

dbir0 commented Sep 25, 2025

Still has build issues, seems to have progressed further though

Builder info
/usr/bin/docker buildx build --cache-from type=gha --cache-to type=gha,mode=max --iidfile /home/runner/work/_temp/docker-actions-toolkit-Q2TGBy/build-iidfile-7c9739f82e.txt --label org.opencontainers.image.created=2025-09-25T17:35:11.238Z --label org.opencontainers.image.description=Personal openwrt builds --label org.opencontainers.image.licenses=GPL-2.0 --label org.opencontainers.image.revision=ab9eebeec47956fb3f0cd63f6cf7436162fa0f53 --label org.opencontainers.image.source=https://github.com/dbir0/openwrt_builds --label org.opencontainers.image.title=openwrt_builds --label org.opencontainers.image.url=https://github.com/dbir0/openwrt_builds --label org.opencontainers.image.version=pr-4 --attest type=provenance,mode=max,builder-id=https://github.com/dbir0/openwrt_builds/actions/runs/18015540774 --tag ghcr.io/dbir0/openwrt_builds:pr-4 --tag ghcr.io/dbir0/openwrt_builds:-ab9eebe --metadata-file /home/runner/work/_temp/docker-actions-toolkit-Q2TGBy/build-metadata-27028aeff4.json .
WARNING: No output specified with docker-container driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load
ERROR: failed to build: invalid tag "ghcr.io/dbir0/openwrt_builds:-ab9eebe": invalid reference format
Error: buildx failed with: ERROR: failed to build: invalid tag "ghcr.io/dbir0/openwrt_builds:-ab9eebe": invalid reference format

@dbir0 dbir0 marked this pull request as ready for review September 25, 2025 17:48
@dbir0 dbir0 merged commit 14f8d2e into main Sep 25, 2025
4 of 8 checks passed
@dbir0 dbir0 deleted the copilot/fix-62d81484-adf7-46d5-a2d8-573059903a3a branch September 25, 2025 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants