Untitled
- Remove these from your current workflow:
- - The entire “Copy golang sources” section
- - make package/lang/golang/compile
- Build golang once
Yes! You can significantly reduce build time by pre-building the Golang package and reusing it across runs. Here’s how to implement this optimization:
- Create a Pre-Build Workflow (.github/workflows/prebuild-golang.yml):
name: Prebuild Golang
on:
workflow_dispatch:
schedule:
- cron: ‘0 0 * * 0’ # Weekly rebuild
push:
paths:
- ‘lang/golang/**’
jobs:
prebuild:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup SDK
uses: ./.github/actions/your-sdk-setup-action
with:
model: gl-mt3000 # Use your most common target
- name: Build Golang IPK
run: |
SDK_PATH="/tmp/openwrt-sdk/..." # Your SDK path logic
make -C \(SDK_PATH package/lang/golang/compile V=s -j\)(nproc)
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: prebuilt-golang
path: ${{ SDK_PATH }}/bin/packages/**/golang*.ipk
- Modify Your Main Workflow:
-
name: Get Prebuilt Golang
uses: actions/download-artifact@v3
with:
name: prebuilt-golang
path: ${{ SDK_PATH }}/bin/packages/ -
name: Install Prebuilt Golang
run: |
opkg install ${{ SDK_PATH }}/bin/packages//golang.ipk
shell: bash
Remove these from your current workflow:
- The entire “Copy golang sources” section
- make package/lang/golang/compile
- Optimize Docker Cache (Even Better Approach):
FROM openwrt-sdk-base AS builder
Build golang once
RUN make package/lang/golang/compile
FROM openwrt-sdk-base AS runtime
COPY –from=builder /sdk/bin/packages/ /sdk/bin/packages/
- Implement Local Cache (Alternative):
- name: Cache Golang
uses: actions/cache@v3
with:
path: |
${{ SDK_PATH }}/build_dir/target-/golang
\({{ SDK_PATH }}/staging_dir/target-*/golang* key: golang-\){{ hashFiles(‘lang/golang/*’) }}
Expected Time Savings:
StepOriginal TimeOptimized TimeGolang Compilation8-10 mins0-30 secsDependency Resolution2-3 mins0-15 secsTotal Savings10 mins1 min
Verification Steps:
Add debug output after installation:
- name: Verify Golang Installation
run: |
ls -la ${{ SDK_PATH }}/staging_dir/target-/bin/go
file ${{ SDK_PATH }}/staging_dir/target-/bin/go
\({{ SDK_PATH }}/staging_dir/target-*/bin/go version Monitor build logs for: Checking 'golang'... already installed Skipping package golang dependencies Important Considerations: Version Pinning: Add a hash check in your workflow: - name: Verify Package Integrity run: | echo "golang_checksum=\)(sha256sum bin/packages//golang.ipk)“ >> \(GITHUB_OUTPUT shell: bash Cross-architecture Support: Store separate packages for each target: # In prebuild job ARCH_SUFFIX=\)(echo \(TARGET | md5sum | cut -c1-6) mv golang*.ipk golang-\)ARCH_SUFFIX.ipk
This optimization should reduce your build times by 80-90% while maintaining build reproducibility.
Write a comment