Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git

Upgrades libraries, upgrades and migrates container

AuthorDaveJarvis <email>
Date2023-09-18 19:06:43 GMT-0700
Commitf3bc5df305e2c5f3dfceeba86303eb4e54b72d9a
Parent615af21
Delta45 lines added, 58 lines removed, 13-line decrease
src/main/resources/com/keenwrite/messages.properties
Wizard.typesetter.name=ConTeXt
Wizard.typesetter.container.name=Podman
-Wizard.typesetter.container.version=4.5.1
-Wizard.typesetter.container.checksum=883c9901d1eedb3a130256574afa270656e4d322dce0bb880808d9d7776eff8a
-Wizard.typesetter.themes.version=1.8.3
-Wizard.typesetter.themes.checksum=983b8d3c4051c6c002b8111ea786ebc83d5496ab5f8d734e96413c59304b2a75
+Wizard.typesetter.container.version=4.6.2
+Wizard.typesetter.container.checksum=a51acef00b17cce83dd4d364817af32dd5e541db8d2d13063ae73742744ba3ad
+Wizard.typesetter.container.image.name=typesetter
+Wizard.typesetter.container.image.version=3.0.1
+Wizard.typesetter.container.image.tag=${Wizard.typesetter.container.image.name}:${Wizard.typesetter.container.image.version}
+Wizard.typesetter.container.image.url=https://repository.keenwrite.com/containers/${Wizard.typesetter.container.image.tag}
+Wizard.typesetter.themes.version=1.8.4
+Wizard.typesetter.themes.checksum=b30dd800df89c1d06b2446469e62c12252434946f950a874e1ca225719ba4efc
Wizard.container.install.command=Installing container using: ''{0}''
Wizard.typesetter.all.5.download.themes.header=Download ${Wizard.typesetter.name} themes
Wizard.typesetter.all.5.download.themes.download.link.lbl=repository
-Wizard.typesetter.all.5.download.themes.download.link.url=https://github.com/DaveJarvis/keenwrite-themes/releases/download/${Wizard.typesetter.themes.version}/theme-pack.zip
+Wizard.typesetter.all.5.download.themes.download.link.url=https://gitlab.com/DaveJarvis/keenwrite-themes/-/releases/${Wizard.typesetter.themes.version}/downloads/theme-pack.zip
Wizard.typesetter.all.5.download.themes.paths=Downloading {0} into {1}.
Wizard.typesetter.all.5.download.themes.status.bytes=Downloaded {0} bytes (size unknown).
src/main/java/com/keenwrite/typesetting/containerization/Podman.java
package com.keenwrite.typesetting.containerization;
+import com.keenwrite.Messages;
import com.keenwrite.io.CommandNotFoundException;
import com.keenwrite.io.SysFile;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.LinkedList;
import java.util.List;
-import static com.keenwrite.Bootstrap.CONTAINER_VERSION;
import static com.keenwrite.events.StatusEvent.clue;
import static com.keenwrite.io.SysFile.toFile;
);
private static final SysFile MANAGER = new SysFile( BINARY );
-
- public static final String CONTAINER_SHORTNAME = "typesetter";
- public static final String CONTAINER_NAME =
- format( "%s:%s", CONTAINER_SHORTNAME, CONTAINER_VERSION );
private final List<String> mMountPoints = new LinkedList<>();
@Override
- public void pull( final StreamProcessor processor, final String name )
+ public void load( final StreamProcessor processor )
throws CommandNotFoundException {
- podman( processor, "pull", "ghcr.io/davejarvis/" + name );
+ final var url = Messages.get( "Wizard.typesetter.container.image.url" );
+
+ podman( processor, "load", "-i", url );
}
final StreamProcessor processor,
final String... args ) throws CommandNotFoundException {
+ final var tag = Messages.get( "Wizard.typesetter.container.image.tag" );
+
final var options = new LinkedList<String>();
options.add( "run" );
options.add( "--rm" );
options.add( "--network=host" );
options.addAll( mMountPoints );
options.add( "-t" );
- options.add( CONTAINER_NAME );
+ options.add( tag );
options.add( "/bin/sh" );
options.add( "-lc" );
container/manage.sh
source ../scripts/build-template
-readonly BUILD_DIR=build
-readonly PROPERTIES="${SCRIPT_DIR}/../src/main/resources/bootstrap.properties"
+# Reads the value of a property from a properties file.
+#
+# $1 - The key name to obtain.
+function property {
+ grep "^${1}" "${PROPERTIES}" | cut -d'=' -f2
+}
-# Read the properties file to get the container version.
-while IFS='=' read -r key value
-do
- key=$(echo $key | tr '.' '_')
- eval ${key}=\${value}
-done < "${PROPERTIES}"
+readonly BUILD_DIR=build
+readonly PROPERTIES="${SCRIPT_DIR}/../src/main/resources/com/keenwrite/messages.properties"
readonly CONTAINER_EXE=podman
-readonly CONTAINER_SHORTNAME=typesetter
-readonly CONTAINER_VERSION=${container_version}
+readonly CONTAINER_SHORTNAME=$(property Wizard.typesetter.container.image.name)
+readonly CONTAINER_VERSION=$(property Wizard.typesetter.container.image.version)
readonly CONTAINER_NETWORK=host
-readonly CONTAINER_FILE="${CONTAINER_SHORTNAME}"
+readonly CONTAINER_FILE="${CONTAINER_SHORTNAME}-${CONTAINER_VERSION}"
readonly CONTAINER_ARCHIVE_FILE="${CONTAINER_FILE}.tar"
readonly CONTAINER_ARCHIVE_PATH="${BUILD_DIR}/${CONTAINER_ARCHIVE_FILE}"
readonly CONTAINER_COMPRESSED_FILE="${CONTAINER_ARCHIVE_FILE}.gz"
readonly CONTAINER_COMPRESSED_PATH="${BUILD_DIR}/${CONTAINER_ARCHIVE_FILE}.gz"
+readonly CONTAINER_IMAGE_FILE="${BUILD_DIR}/${CONTAINER_FILE}"
readonly CONTAINER_DIR_SOURCE="/root/source"
readonly CONTAINER_DIR_TARGET="/root/target"
readonly CONTAINER_DIR_IMAGES="/root/images"
readonly CONTAINER_DIR_FONTS="/root/fonts"
-readonly CONTAINER_REPO=ghcr.io
ARG_CONTAINER_NAME="${CONTAINER_SHORTNAME}:${CONTAINER_VERSION}"
ARG_CONTAINER_COMMAND="context --version"
ARG_MOUNTPOINT_SOURCE=""
ARG_MOUNTPOINT_TARGET="."
ARG_MOUNTPOINT_IMAGES=""
ARG_MOUNTPOINT_FONTS="${HOME}/.fonts"
-ARG_ACCESS_TOKEN=""
DEPENDENCIES=(
"i,images,Set mount point for image files (to typeset)"
"f,fonts,Set mount point for font files (during typesetting)"
- "k,token,Set personal access token (to publish)"
"l,load,Load container (${CONTAINER_COMPRESSED_PATH})"
- "p,publish,Publish the container (after logging in)"
+ "p,publish,Publish the container"
"r,run,Run a command in the container (\"${ARG_CONTAINER_COMMAND}\")"
- "v,version,Set container version to publish (${CONTAINER_VERSION})"
"x,export,Save container (${CONTAINER_COMPRESSED_PATH})"
)
# Show what commands are run while building, but not the commands' output.
${CONTAINER_EXE} build \
- --network=${CONTAINER_NETWORK} \
+ --network="${CONTAINER_NETWORK}" \
--squash \
- -t ${ARG_CONTAINER_NAME} . | \
+ -t "${ARG_CONTAINER_NAME}" . | \
grep ^STEP
}
# ---------------------------------------------------------------------------
# Publishes the container to the repository.
# ---------------------------------------------------------------------------
utile_publish() {
- local -r username=$(git config user.name | tr '[A-Z]' '[a-z]')
- local -r repo="${CONTAINER_REPO}/${username}/${ARG_CONTAINER_NAME}"
-
- if [ ! -z ${ARG_ACCESS_TOKEN} ]; then
- echo ${ARG_ACCESS_TOKEN} | \
- ${CONTAINER_EXE} login ghcr.io -u $(git config user.name) --password-stdin
-
- $log "Tagging"
-
- ${CONTAINER_EXE} tag ${ARG_CONTAINER_NAME} ${repo}
+ local -r TOKEN_FILE="token.txt"
- $log "Pushing ${ARG_CONTAINER_NAME} to ${CONTAINER_REPO}"
+ if [[ -f "${TOKEN_FILE}" ]]; then
+ local -r repository=$(cat ${TOKEN_FILE})
+ local -r remote_file="${CONTAINER_SHORTNAME}:${CONTAINER_VERSION}"
+ local -r remote_path="${repository}/${remote_file}"
- ${CONTAINER_EXE} push ${repo}
+ $log "Publishing to ${remote_path}"
- $log "Published ${ARG_CONTAINER_NAME} to ${CONTAINER_REPO}"
+ # Path to the repository.
+ scp -q "${CONTAINER_IMAGE_FILE}" "${remote_path}"
else
- error "Provide a personal access token (-k TOKEN) to publish."
+ error "Create ${TOKEN_FILE} with publish credentials"
fi
}
gzip "${CONTAINER_ARCHIVE_PATH}"
- $log "Saved ${CONTAINER_SHORTNAME} image"
+ $log "Renaming to ${CONTAINER_IMAGE_FILE}"
+ mv "${CONTAINER_COMPRESSED_PATH}" "${CONTAINER_IMAGE_FILE}"
+
+ $log "Saved ${CONTAINER_IMAGE_FILE} image"
fi
}
-d|--delete)
do_delete=utile_delete
- ;;
- -k|--token)
- if [ ! -z "${2+x}" ]; then
- ARG_ACCESS_TOKEN="$2"
- consume=2
- fi
;;
-l|--load)
if [ ! -z "${2+x}" ]; then
ARG_MOUNTPOINT_SOURCE="$2"
- consume=2
- fi
- ;;
- -v|--version)
- if [ ! -z "${2+x}" ]; then
- ARG_CONTAINER_NAME="${CONTAINER_SHORTNAME}:$2"
consume=2
fi