fix(deploy): ensure correct git metadata and source code in builds
- Change to repo directory before collecting git commit metadata - Run docker build from repo directory to use correct source code - Run docker compose commands from repo directory - This ensures deployed commit hash matches actual code deployed This was causing deployments to report wrong commit hashes and use old code. Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
388c564ccf
commit
bb39088f81
@ -258,12 +258,16 @@ BYTELYST_BRANCH=
|
||||
BYTELYST_BUILT_AT=
|
||||
BYTELYST_COMMIT_AUTHOR=
|
||||
BYTELYST_COMMIT_MESSAGE=
|
||||
|
||||
# Change to repo directory to collect correct git metadata
|
||||
cd "$REPO_DIR"
|
||||
BYTELYST_COMMIT_SHA=$(git rev-parse --short HEAD 2>/dev/null || echo unknown)
|
||||
BYTELYST_COMMIT_SHA_FULL=$(git rev-parse HEAD 2>/dev/null || echo unknown)
|
||||
BYTELYST_BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo unknown)
|
||||
BYTELYST_BUILT_AT=$(date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||
BYTELYST_COMMIT_AUTHOR=$(git log -1 --pretty=format:'%an' 2>/dev/null || echo unknown)
|
||||
BYTELYST_COMMIT_MESSAGE=$(git log -1 --pretty=format:'%s' 2>/dev/null | head -c 200 || echo unknown)
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
build_image() {
|
||||
local dockerfile="$1"
|
||||
@ -272,7 +276,8 @@ build_image() {
|
||||
if [ "$NO_CACHE" = true ]; then
|
||||
cache_flag="--no-cache"
|
||||
fi
|
||||
docker build --network host $cache_flag \
|
||||
# Build from repo directory to ensure correct source code is used
|
||||
(cd "$REPO_DIR" && docker build --network host $cache_flag \
|
||||
--build-arg "GITEA_NPM_TOKEN=${GITEA_NPM_TOKEN}" \
|
||||
--build-arg "BYTELYST_COMMIT_SHA=${BYTELYST_COMMIT_SHA}" \
|
||||
--build-arg "BYTELYST_COMMIT_SHA_FULL=${BYTELYST_COMMIT_SHA_FULL}" \
|
||||
@ -281,7 +286,7 @@ build_image() {
|
||||
--build-arg "BYTELYST_COMMIT_AUTHOR=${BYTELYST_COMMIT_AUTHOR}" \
|
||||
--build-arg "BYTELYST_COMMIT_MESSAGE=${BYTELYST_COMMIT_MESSAGE}" \
|
||||
--build-arg "BYTELYST_DOCKER_IMAGE=${tag}" \
|
||||
-f "$dockerfile" -t "$tag" .
|
||||
-f "$dockerfile" -t "$tag" .) || fail "Docker build failed for $dockerfile"
|
||||
}
|
||||
|
||||
build_image backend/Dockerfile invttrdg-backend:latest || fail "Backend build failed"
|
||||
@ -289,9 +294,11 @@ build_image web/Dockerfile invttrdg-web:latest || fail "Web build failed"
|
||||
|
||||
log "Starting services..."
|
||||
# Stop and remove existing containers to ensure fresh deployment
|
||||
cd "$REPO_DIR"
|
||||
docker compose down || true
|
||||
# Start services with force-recreate to ensure new images are used
|
||||
docker compose up -d --force-recreate || fail "Docker compose up failed"
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
ok "Deployment completed"
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user