coreapp publish, and a Gitea Actions workflow in new apps
coreapp publish builds the release image, pushes image:version to the registry named in coreapp.toml and tags the commit v<version>. It refuses local-only image names (suggesting one from the git remote), uncommitted changes, a version already published and a tag already on another commit. The existence check uses docker buildx imagetools inspect: docker manifest inspect reported "no such manifest" for an image that existed. Any error but "not found" stops the publish. New apps get .gitea/workflows/publish.yml, which does the same on a v* tag, for repositories with a runner that can use Docker (secrets REGISTRY_USER and REGISTRY_TOKEN). Untested: needs a runner. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+104
-1
@@ -15,6 +15,9 @@
|
||||
# coreapp shell [command] a shell in its container, or run one command there
|
||||
# coreapp remove uninstall it from the Core (asks first)
|
||||
# coreapp list the apps on the Core installed this way
|
||||
# coreapp publish [--platform <list>]
|
||||
# build the release image and push it to the
|
||||
# registry in coreapp.toml, and tag the commit
|
||||
#
|
||||
# Run everything but `new` and `list` in the app's folder (the one with
|
||||
# coreapp.toml). COREAPP_VM picks the VM (default coreserver).
|
||||
@@ -79,6 +82,12 @@ core_domain() {
|
||||
# From coreapp.toml, as checked by the installer
|
||||
NAME="" TITLE="" VERSION="" IMAGE="" PORT="" HEALTH="" NEEDS=""
|
||||
load_app() {
|
||||
load_manifest
|
||||
init_core
|
||||
}
|
||||
|
||||
# coreapp.toml's values, checked by the installer (no Core needed)
|
||||
load_manifest() {
|
||||
local values key value
|
||||
[[ -f coreapp.toml ]] \
|
||||
|| die "No app here: run this in an app's folder (one with coreapp.toml), or make one with coreapp new <name>."
|
||||
@@ -94,7 +103,6 @@ load_app() {
|
||||
needs) NEEDS="$value" ;;
|
||||
esac
|
||||
done <<< "$values"
|
||||
init_core
|
||||
}
|
||||
|
||||
image() { echo "$IMAGE:$VERSION"; }
|
||||
@@ -311,6 +319,100 @@ cmd_list() {
|
||||
core "$REMOTE_INSTALLER/coreapps list"
|
||||
}
|
||||
|
||||
# --- publish ----------------------------------------------------------------
|
||||
|
||||
# A registry image name from the repository's git remote, as a suggestion:
|
||||
# https://host/Owner/Repo.git or git@host:Owner/Repo.git -> host/owner/repo
|
||||
image_from_remote() {
|
||||
local url host path
|
||||
url="$(git remote get-url origin 2> /dev/null)" || return 1
|
||||
case "$url" in
|
||||
https://*) url="${url#https://}"; host="${url%%/*}"; path="${url#*/}" ;;
|
||||
ssh://*) url="${url#ssh://}"; url="${url#*@}"; host="${url%%/*}"; host="${host%%:*}"; path="${url#*/}" ;;
|
||||
*@*:*) url="${url#*@}"; host="${url%%:*}"; path="${url#*:}" ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
path="${path%.git}"
|
||||
[[ "$path" == */* ]] || return 1
|
||||
echo "$host/${path,,}"
|
||||
}
|
||||
|
||||
cmd_publish() {
|
||||
local platform=linux/amd64 ref tag registry source="" commit check digest suggestion
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--platform) platform="${2:?--platform needs a value, e.g. linux/amd64,linux/arm64}"; shift ;;
|
||||
*) die "Usage: coreapp publish [--platform linux/amd64[,linux/arm64]]" ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
load_manifest
|
||||
ref="$(image)"
|
||||
tag="v$VERSION"
|
||||
registry="${IMAGE%%/*}"
|
||||
|
||||
if [[ "$IMAGE" == localhost/* ]]; then
|
||||
suggestion="$(image_from_remote || true)"
|
||||
if [[ -n "$suggestion" ]]; then
|
||||
suggestion=", e.g. image = \"$suggestion\" (from the git remote)"
|
||||
fi
|
||||
die "image = \"$IMAGE\" in coreapp.toml only exists where coreapp deploy copies it.
|
||||
To publish, set image to your registry$suggestion.
|
||||
coreapp deploy keeps working with that name."
|
||||
fi
|
||||
|
||||
# A release is a commit: the image is built from it, and the Core installs
|
||||
# the app from the repository at its tag
|
||||
git rev-parse --is-inside-work-tree > /dev/null 2>&1 \
|
||||
|| die "This folder isn't a git repository. A published app is one (its tag is the release)."
|
||||
[[ -z "$(git status --porcelain)" ]] \
|
||||
|| die "There are uncommitted changes (git status). Commit them first, so the release matches a commit."
|
||||
commit="$(git rev-parse HEAD)"
|
||||
if git rev-parse -q --verify "refs/tags/$tag" > /dev/null; then
|
||||
[[ "$(git rev-parse "$tag^{commit}")" == "$commit" ]] \
|
||||
|| die "The tag $tag already exists on another commit. Raise version in coreapp.toml for a new release."
|
||||
fi
|
||||
case "$(git remote get-url origin 2> /dev/null || true)" in
|
||||
https://*) source="$(git remote get-url origin)"; source="${source%.git}" ;;
|
||||
esac
|
||||
|
||||
# Never replace a published version: Cores may have installed it
|
||||
echo "Checking $registry for $ref..."
|
||||
# (Only "not found" means it isn't there; any other error stops here)
|
||||
if check="$(docker buildx imagetools inspect "$ref" 2>&1)"; then
|
||||
die "$ref is already published. Raise version in coreapp.toml for a new release."
|
||||
fi
|
||||
case "$check" in
|
||||
*"not found"* | *"manifest unknown"*) ;;
|
||||
*unauthorized* | *denied* | *"authentication required"* | *401* | *403*)
|
||||
die "$registry wants you to log in first: docker login $registry
|
||||
(For Gitea, use a token with the write:package scope as the password.)" ;;
|
||||
*) die "Couldn't check $registry for $ref: $check" ;;
|
||||
esac
|
||||
|
||||
echo "Building $ref for $platform..."
|
||||
local labels=(--label "org.opencontainers.image.version=$VERSION"
|
||||
--label "org.opencontainers.image.revision=$commit"
|
||||
--label "org.opencontainers.image.title=$TITLE")
|
||||
[[ -n "$source" ]] && labels+=(--label "org.opencontainers.image.source=$source")
|
||||
if [[ "$platform" == *,* ]]; then
|
||||
# Several platforms at once can only be pushed straight from buildx
|
||||
docker buildx build --platform "$platform" "${labels[@]}" -t "$ref" --push . \
|
||||
|| die "Building or pushing failed (above). Several platforms need a buildx builder that supports them: docker buildx create --use"
|
||||
else
|
||||
docker build -q --platform "$platform" "${labels[@]}" -t "$ref" . > /dev/null
|
||||
echo "Pushing it..."
|
||||
docker push -q "$ref" > /dev/null \
|
||||
|| die "Pushing failed. Log in first if you haven't: docker login $registry"
|
||||
fi
|
||||
digest="$(docker buildx imagetools inspect "$ref" --format '{{.Manifest.Digest}}' 2> /dev/null || true)"
|
||||
|
||||
git rev-parse -q --verify "refs/tags/$tag" > /dev/null || git tag -a "$tag" -m "${TITLE} $VERSION"
|
||||
echo "Published $ref${digest:+ ($digest)}."
|
||||
echo "Tagged this commit $tag. Push the commit and the tag, so the release is in the repository:"
|
||||
echo " git push && git push origin $tag"
|
||||
}
|
||||
|
||||
cmd="${1:-help}"
|
||||
[[ $# -gt 0 ]] && shift
|
||||
case "$cmd" in
|
||||
@@ -322,6 +424,7 @@ case "$cmd" in
|
||||
shell) cmd_shell "$@" ;;
|
||||
remove | rm) cmd_remove ;;
|
||||
list | ls) cmd_list ;;
|
||||
publish) cmd_publish "$@" ;;
|
||||
help | -h | --help) usage ;;
|
||||
*) usage >&2; exit 1 ;;
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user