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:
@@ -223,10 +223,22 @@ Steps:
|
||||
manifest values); remove (database, Authelia client, image and catalog
|
||||
entry gone)
|
||||
- [ ] David: sign in to `https://trial-app.dev.fedcom.net/` in a browser
|
||||
2. [ ] Publishing: a Gitea Actions workflow in new apps that builds the image
|
||||
on a version tag and pushes it to the repository's Gitea registry; and
|
||||
`coreapp publish` for developers without a runner. Pin the image by
|
||||
digest in what the Core installs? Private registries need a pull token
|
||||
2. Publishing (2026-12-03): `coreapp publish` builds the image, pushes
|
||||
`image:version` to the registry in `coreapp.toml`, never replacing a
|
||||
published version, and tags the commit `v<version>`; new apps also get
|
||||
`.gitea/workflows/publish.yml`, which does the same on a `v*` tag.
|
||||
Federated's Gitea is 1.27.2 with its container registry on the same
|
||||
host; the Core's own `gitearunner` registers with the Core's Gitea only,
|
||||
so whether developers on gitea.federated.computer have a runner that can
|
||||
use Docker is unknown. Tested against a local registry. `docker
|
||||
manifest inspect` reported "no such manifest" for an image that existed,
|
||||
so the check uses `docker buildx imagetools inspect`, and any error but
|
||||
"not found" stops the publish
|
||||
- [ ] David: publish a test app to gitea.federated.computer
|
||||
(`docker login` with a `write:package` token)
|
||||
- [ ] Run the workflow on a repository with a runner
|
||||
- [ ] Pin the image by digest in what the Core installs? Private
|
||||
packages need a pull token on the Core
|
||||
3. [ ] Install from a URL on the Core: `coreapps install <repo-url>[@tag]`
|
||||
(git clone at the tag, read `coreapp.toml` and `icon.png` only, pull the
|
||||
image). Show the source and what the app needs before installing
|
||||
|
||||
@@ -83,10 +83,17 @@ each new app explains the files and the settings it gets.
|
||||
| `coreapp check` | It answers at `https://<name>.<domain><health>` with a valid certificate |
|
||||
| `coreapp status` / `logs [-f]` / `shell [command]` | Its container, its log, a shell in it (or one command, without a terminal) |
|
||||
| `coreapp list` | The apps on the Core installed this way |
|
||||
| `coreapp publish [--platform <list>]` | Build the release image, push it to the registry in `coreapp.toml` (`image:version`, never replacing a published version) and tag the commit `v<version>` |
|
||||
| `coreapp remove` | Uninstall it from the Core, with its database and sign-in client (asks first) |
|
||||
|
||||
`COREAPP_VM` picks the VM (default `coreserver`).
|
||||
|
||||
To publish, set `image` to your registry (for Gitea,
|
||||
`<gitea-host>/<owner>/<repo>`), `docker login` to it once, commit, and run
|
||||
`coreapp publish`. New apps also have a Gitea Actions workflow
|
||||
(`.gitea/workflows/publish.yml`) that does the same when a `v*` tag is
|
||||
pushed, for repositories with a runner that can use Docker.
|
||||
|
||||
Installing and removing go through the Core's own `installapp` and
|
||||
`uninstallapp`, so the app shows up in Superpanel. The installer gives apps
|
||||
no `MONITOR` line, so they aren't added to Federated's external monitoring.
|
||||
|
||||
@@ -182,8 +182,9 @@ The Core's own scripts trace secrets, so their output goes to
|
||||
|
||||
1. `cd $(mktemp -d) && coreapp new hello`: `./hello` has `coreapp.toml`,
|
||||
`Dockerfile`, `.dockerignore`, `icon.png`, `www/`, `README.md` and
|
||||
nothing else, with no `{{...}}` left (`grep -r '{{' hello` prints
|
||||
nothing). `coreapp new hello` again refuses; so does `coreapp new x-`.
|
||||
`.gitea/workflows/publish.yml`, and nothing else, with no placeholder
|
||||
left (`grep -r '{{[A-Z]' hello` prints nothing; the workflow's
|
||||
`${{ ... }}` are Gitea's). `coreapp new hello` again refuses; so does `coreapp new x-`.
|
||||
2. `cd hello && coreapp deploy`: updates `/opt/coreapps` on the Core,
|
||||
builds, copies the image, prints `Installing hello at 192.168.5.x`
|
||||
(the first free address there) and `Installed: https://hello.<domain>/`.
|
||||
@@ -290,3 +291,37 @@ again (they're read from its `DEPENDS`), Authelia not restarted; `.coreapp`
|
||||
then says which needs it has. Apps with an address outside 192.168.5.0/24
|
||||
get a new one on their next update (the container moves; the app keeps
|
||||
working), and apps with sign-in get their client copy.
|
||||
|
||||
## Publishing (coreapp publish)
|
||||
|
||||
With a throwaway registry on the workstation
|
||||
(`docker run -d --rm --name coreapp-test-registry -p 127.0.0.1:5000:5000 registry:2`;
|
||||
`docker stop coreapp-test-registry` afterwards removes it) and an app in a git
|
||||
repository with an `https://` origin:
|
||||
|
||||
1. With `image = "localhost/coreapp/..."`: refused, suggesting an image
|
||||
from the remote (`https://host/Owner/Repo.git` gives
|
||||
`host/owner/repo`).
|
||||
2. With `image = "localhost:5000/test/<name>"` and an uncommitted change:
|
||||
refused.
|
||||
3. Committed: builds, pushes, prints the digest, tags the commit
|
||||
`v<version>` (annotated) and prints the push commands. The registry
|
||||
lists the tag (`curl -s http://127.0.0.1:5000/v2/test/<name>/tags/list`);
|
||||
the image has the `org.opencontainers.image.*` labels (version,
|
||||
revision, title, source).
|
||||
4. Again: "already published", nothing pushed.
|
||||
5. A new commit without raising `version`: "The tag v<version> already
|
||||
exists on another commit".
|
||||
6. Raise `version`, commit, publish: the new tag is pushed alongside.
|
||||
7. Registry stopped: "Couldn't check ..." with the error, exit 1.
|
||||
|
||||
Against a real Gitea (needs the user's account): `docker login <gitea-host>`
|
||||
with a token that has `write:package`, `image = "<gitea-host>/<owner>/<repo>"`,
|
||||
`coreapp publish`: the package shows under the owner's Packages, linked to
|
||||
the repository. A private owner's packages need a login to pull.
|
||||
|
||||
The workflow (`.gitea/workflows/publish.yml`), on a repository with an
|
||||
Actions runner that can use Docker and the secrets `REGISTRY_USER` and
|
||||
`REGISTRY_TOKEN`: pushing tag `v<version>` publishes `image:version`; a tag
|
||||
that doesn't match `version`, a `localhost/` image, or a version already
|
||||
published fails the job with a message.
|
||||
|
||||
+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
|
||||
|
||||
@@ -270,6 +270,35 @@ The installer's own log (the Core's install scripts) is on the Core in
|
||||
look at the end of it with `coreapp-vm ssh tail -n 40 /federated/logs/coreapps/<name>-install.log`
|
||||
only when a deploy fails in the installer itself.
|
||||
|
||||
### 5. Publishing (when the user asks for a release)
|
||||
|
||||
A published app is a tagged commit in its repository plus its image in a
|
||||
registry, from which any Core can install it. Only publish when the user
|
||||
asks: it pushes to their registry and tags their repository.
|
||||
|
||||
1. Set `image` in `coreapp.toml` to the registry: for an app on a Gitea
|
||||
server, `<gitea-host>/<owner>/<repo>` in lowercase (Gitea's container
|
||||
registry is on the same host). `coreapp publish` suggests one from the
|
||||
git remote. `coreapp deploy` keeps working with that name.
|
||||
2. Raise `version` if this version was published before (published
|
||||
versions are never replaced).
|
||||
3. Commit everything; `coreapp publish` refuses uncommitted changes.
|
||||
4. `coreapp publish` builds the image for linux/amd64 (add
|
||||
`--platform linux/amd64,linux/arm64` for ARM Cores too), pushes
|
||||
`image:version`, and tags the commit `v<version>`. It needs
|
||||
`docker login <registry>` first; that's the user's to do (for Gitea,
|
||||
with a token that has the `write:package` scope).
|
||||
5. The user pushes the commit and tag: `git push && git push origin v<version>`.
|
||||
|
||||
New apps also have `.gitea/workflows/publish.yml`, which does the same on
|
||||
the Gitea server when a `v*` tag is pushed, if the repository has an
|
||||
Actions runner that can use Docker and the secrets `REGISTRY_USER` and
|
||||
`REGISTRY_TOKEN`. When porting an existing app, copy it from a new app
|
||||
(`coreapp new x`) if the user wants it.
|
||||
|
||||
Installing a published app on a Core from its repository URL isn't
|
||||
available yet; for now, apps are installed with `coreapp deploy`.
|
||||
|
||||
## Reporting back
|
||||
|
||||
When you're done, tell the user:
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
# Publishes the app when a version tag (v0.1.0, ...) is pushed: builds the
|
||||
# image from that commit and pushes it as image:version (from coreapp.toml).
|
||||
# The same as `coreapp publish`, for repositories with a Gitea Actions
|
||||
# runner whose jobs can use Docker.
|
||||
#
|
||||
# Needs two secrets in the repository (Settings > Actions > Secrets):
|
||||
# REGISTRY_USER the Gitea user that owns the token
|
||||
# REGISTRY_TOKEN a Gitea token with the write:package scope
|
||||
name: Publish
|
||||
|
||||
on:
|
||||
push:
|
||||
tags: ["v*"]
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Read coreapp.toml
|
||||
id: app
|
||||
run: |
|
||||
python3 - >> "$GITHUB_OUTPUT" <<'PY'
|
||||
import tomllib
|
||||
with open("coreapp.toml", "rb") as f:
|
||||
m = tomllib.load(f)
|
||||
print(f"image={m['image']}")
|
||||
print(f"version={m['version']}")
|
||||
print(f"title={m['title']}")
|
||||
PY
|
||||
|
||||
- name: Check the tag and the image name
|
||||
env:
|
||||
IMAGE: ${{ steps.app.outputs.image }}
|
||||
VERSION: ${{ steps.app.outputs.version }}
|
||||
run: |
|
||||
if [ "$GITHUB_REF_NAME" != "v$VERSION" ]; then
|
||||
echo "The tag $GITHUB_REF_NAME doesn't match version = \"$VERSION\" in coreapp.toml."
|
||||
exit 1
|
||||
fi
|
||||
case "$IMAGE" in localhost/*)
|
||||
echo "image = \"$IMAGE\" in coreapp.toml is a local name; set it to the registry, e.g. gitea.example.com/owner/app."
|
||||
exit 1 ;;
|
||||
esac
|
||||
|
||||
- name: Log in to the registry
|
||||
env:
|
||||
IMAGE: ${{ steps.app.outputs.image }}
|
||||
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
|
||||
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||
run: echo "$REGISTRY_TOKEN" | docker login "${IMAGE%%/*}" -u "$REGISTRY_USER" --password-stdin
|
||||
|
||||
- name: Build and push
|
||||
env:
|
||||
IMAGE: ${{ steps.app.outputs.image }}
|
||||
VERSION: ${{ steps.app.outputs.version }}
|
||||
TITLE: ${{ steps.app.outputs.title }}
|
||||
run: |
|
||||
# Never replace a published version: Cores may have installed it
|
||||
# (only "not found" means it isn't there; any other error stops)
|
||||
if check="$(docker buildx imagetools inspect "$IMAGE:$VERSION" 2>&1)"; then
|
||||
echo "$IMAGE:$VERSION is already published. Raise version in coreapp.toml."
|
||||
exit 1
|
||||
fi
|
||||
case "$check" in
|
||||
*"not found"*|*"manifest unknown"*) ;;
|
||||
*) echo "Couldn't check the registry: $check"; exit 1 ;;
|
||||
esac
|
||||
docker build --platform linux/amd64 \
|
||||
--label "org.opencontainers.image.version=$VERSION" \
|
||||
--label "org.opencontainers.image.revision=$GITHUB_SHA" \
|
||||
--label "org.opencontainers.image.title=$TITLE" \
|
||||
--label "org.opencontainers.image.source=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \
|
||||
-t "$IMAGE:$VERSION" .
|
||||
docker push "$IMAGE:$VERSION"
|
||||
Reference in New Issue
Block a user