Skip to content

Commit a313b3e

Browse files
committed
fix: clean build context and support no-cache builds to avoid stale files
1 parent 6f0e847 commit a313b3e

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

core/genesis.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,14 @@ func SetupGenesisBlock(
182182
return newcfg, common.Hash{}, err
183183
}
184184

185-
// Use the attached extras pointer to ensure upgrade bytes round-trip correctly.
186-
extra := params.GetExtra(newcfg)
187-
storedcfg := customrawdb.ReadChainConfig(db, stored, extra)
185+
// Read stored config into a local extras copy to avoid mutating shared extras concurrently.
186+
extraCopy := *params.GetExtra(newcfg)
187+
storedcfg := customrawdb.ReadChainConfig(db, stored, &extraCopy)
188188
// If there is no previously stored chain config, write the chain config to disk.
189189
if storedcfg == nil {
190190
// Note: this can happen since we did not previously write the genesis block and chain config in the same batch.
191191
log.Warn("Found genesis block without chain config")
192-
customrawdb.WriteChainConfig(db, stored, newcfg, *extra)
192+
customrawdb.WriteChainConfig(db, stored, newcfg, *params.GetExtra(newcfg))
193193
return newcfg, stored, nil
194194
}
195195

@@ -228,7 +228,7 @@ func SetupGenesisBlock(
228228
}
229229
// Required to write the chain config to disk to ensure both the chain config and upgrade bytes are persisted to disk.
230230
// Note: this intentionally removes an extra check from upstream.
231-
customrawdb.WriteChainConfig(db, stored, newcfg, *extra)
231+
customrawdb.WriteChainConfig(db, stored, newcfg, *params.GetExtra(newcfg))
232232
return newcfg, stored, nil
233233
}
234234

scripts/build_docker_image.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
set -euo pipefail
44

5+
# If set, ensure a clean git workspace before building to avoid stray files in context
6+
if [[ -n "${CLEAN_CONTEXT:-}" ]]; then
7+
echo "Cleaning build context (git clean -fdx)"
8+
git -C "$(dirname "$0")/.." clean -fdx
9+
fi
10+
11+
# If set, disable build cache for docker buildx
12+
if [[ -n "${NO_CACHE:-}" ]]; then
13+
DOCKER_NO_CACHE="--no-cache"
14+
else
15+
DOCKER_NO_CACHE=""
16+
fi
17+
518
# If set to non-empty, prompts the building of a multi-arch image when the image
619
# name indicates use of a registry.
720
#
@@ -34,7 +47,7 @@ ALLOW_TAG_LATEST="${ALLOW_TAG_LATEST:-}"
3447
# simplifies creation of multi-arch images.
3548
#
3649
# Reference: https://docs.docker.com/build/buildkit/
37-
DOCKER_CMD="docker buildx build"
50+
DOCKER_CMD="docker buildx build ${DOCKER_NO_CACHE}"
3851
ispush=0
3952
if [[ -n "${PUBLISH}" ]]; then
4053
echo "Pushing $IMAGE_NAME:$BUILD_IMAGE_ID"

scripts/tests.build_docker_image.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ build_and_test() {
3636
VM_ID=$"${vm_id}" \
3737
IMAGE_NAME="${imagename}" \
3838
AVALANCHEGO_LOCAL_IMAGE_NAME="${avalanchego_local_image_name}" \
39+
CLEAN_CONTEXT=1 \
40+
NO_CACHE=1 \
3941
./scripts/build_docker_image.sh
4042

4143
echo "listing images"

0 commit comments

Comments
 (0)