46 lines
1.6 KiB
Bash
Executable File
46 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -Eeuo pipefail
|
|
|
|
env_file="${1:-compose/.env}"
|
|
source_directory="${2:-/srv/ai-soulmate/sources/ai-soulmate-server}"
|
|
|
|
for required_command in docker git sed; do
|
|
if ! command -v "$required_command" >/dev/null 2>&1; then
|
|
printf 'Required command is unavailable: %s\n' "$required_command" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
if [[ ! -r "$env_file" ]]; then
|
|
printf 'Environment file not found: %s\n' "$env_file" >&2
|
|
exit 1
|
|
fi
|
|
if [[ ! -r "$source_directory/backend/Dockerfile" ]]; then
|
|
printf 'Backend Dockerfile not found under: %s\n' "$source_directory" >&2
|
|
exit 1
|
|
fi
|
|
|
|
source_branch="$(git -C "$source_directory" branch --show-current)"
|
|
source_commit="$(git -C "$source_directory" rev-parse HEAD)"
|
|
source_short_commit="${source_commit:0:12}"
|
|
image="$(sed -n 's/^BACKEND_IMAGE=//p' "$env_file" | head -n 1)"
|
|
if [[ "$source_branch" != "local-deployment" ]]; then
|
|
printf 'Expected source branch local-deployment, found: %s\n' "$source_branch" >&2
|
|
exit 1
|
|
fi
|
|
if [[ -n "$(git -C "$source_directory" status --short --untracked-files=no)" ]]; then
|
|
printf 'Tracked source changes are present; refusing to build an uncommitted image.\n' >&2
|
|
exit 1
|
|
fi
|
|
if [[ "$image" != "ai-soulmate-backend:${source_short_commit}" ]]; then
|
|
printf 'BACKEND_IMAGE does not match source commit; rerun configure-backend-env.sh.\n' >&2
|
|
exit 1
|
|
fi
|
|
|
|
docker build \
|
|
--label "org.opencontainers.image.revision=${source_commit}" \
|
|
--tag "$image" \
|
|
"$source_directory/backend"
|
|
|
|
docker image inspect "$image" \
|
|
--format 'Backend image built: {{index .RepoTags 0}} id={{.Id}} size={{.Size}}'
|