Build a CLI container

This commit is contained in:
David Boreham 2023-01-06 15:57:14 -07:00
parent 318d70020e
commit 82755a27f2
7 changed files with 15 additions and 10 deletions

View File

@ -66,8 +66,9 @@ def command(ctx, include, exclude):
# TODO: make this configurable
container_build_env = {
"CERC_NPM_URL": "http://host.docker.internal:3000/api/packages/cerc-io/npm/",
"CERC_NPM_AUTH_TOKEN": os.environ["CERC_NPM_AUTH_TOKEN"]
"CERC_NPM_URL": "http://gitea.local:3000/api/packages/cerc-io/npm/",
"CERC_NPM_AUTH_TOKEN": os.environ["CERC_NPM_AUTH_TOKEN"],
"CERC_REPO_BASE_DIR": dev_root_path
}
def process_container(container):
@ -91,7 +92,7 @@ def command(ctx, include, exclude):
if not dry_run:
if verbose:
print(f"Executing: {build_command}")
build_result = subprocess.run(build_command, shell=True, env={'CERC_REPO_BASE_DIR': dev_root_path})
build_result = subprocess.run(build_command, shell=True, env=container_build_env)
# TODO: check result in build_result.returncode
print(f"Result is: {build_result}")
else:

View File

@ -62,7 +62,7 @@ def command(ctx, include, exclude):
repo_dir = package
repo_full_path = os.path.join(dev_root_path, repo_dir)
# TODO: make the npm registry url configurable.
build_command = ["sh", "-c", "cd /workspace && build-npm-package-local-dependencies.sh http://host.docker.internal:3000/api/packages/cerc-io/npm/"]
build_command = ["sh", "-c", "cd /workspace && build-npm-package-local-dependencies.sh http://gitea.local:3000/api/packages/cerc-io/npm/"]
if not dry_run:
if verbose:
print(f"Executing: {build_command}")
@ -73,7 +73,7 @@ def command(ctx, include, exclude):
tty=True,
user=f"{os.getuid()}:{os.getgid()}",
envs=envs,
add_hosts=[("host.docker.internal", "host-gateway")],
add_hosts=[("gitea.local", "host-gateway")],
volumes=[(repo_full_path, "/workspace")],
command=build_command
)

View File

@ -10,8 +10,8 @@ it is possible to build packages manually by invoking `docker run` , for example
```
$ docker run --rm -it --add-host host.docker.internal:host-gateway \
$ docker run --rm -it --add-host gitea.local:host-gateway \
-v ${HOME}/cerc/laconic-registry-cli:/workspace cerc/builder-js \
sh -c 'cd /workspace && CERC_NPM_AUTH_TOKEN=6613572a28ebebaee20ccd90064251fa8c2b94f6 \
build-npm-package-local-dependencies.sh http://host.docker.internal:3000/api/packages/cerc-io/npm/ 0.1.8'
build-npm-package-local-dependencies.sh http://gitea.local:3000/api/packages/cerc-io/npm/ 0.1.8'
```

View File

@ -25,7 +25,7 @@ npm config set @cerc-io:registry ${local_npm_registry_url}
npm config set -- ${local_npm_registry_url}:_authToken ${CERC_NPM_AUTH_TOKEN}
# First check if the version of this package we're trying to build already exists in the registry
package_exists=$( yarn info --json ${package_name}@${package_publish_version} | jq -r .data.dist.tarball )
if [[ -n "$package_exists" ]]; then
if [[ ! -z "$package_exists" && "$package_exists" != "null" ]]; then
echo "${package_publish_version} of ${package_name} already exists in the registry, skipping build"
exit 0
fi

View File

@ -26,7 +26,8 @@ package_tarball=$(echo $yarn_info_output | jq -r .data.dist.tarball)
# so we need to check if that has happened and fix the URL if so.
if ! [[ "${package_tarball}" =~ ^${local_npm_registry_url}.* ]]; then
# HACK: I've hard-wired the host names below. Replace with proper implementation
package_tarball=$( echo ${package_tarball} | sed -e 's/localhost/host.docker.internal/g' )
# TODO: remove the hack when proven no longer necessary
package_tarball=$( echo ${package_tarball} | sed -e 's/localhost/gitea.local/g' )
fi
package_integrity=$(echo $yarn_info_output | jq -r .data.dist.integrity)
package_shasum=$(echo $yarn_info_output | jq -r .data.dist.shasum)

View File

@ -48,6 +48,9 @@ RUN npm config set @lirewine:registry ${CERC_NPM_URL} \
# TODO: the image at this point could be made a base image for several different CLI images
# that install different Node-based CLI commands
# DEBUG, remove
RUN yarn info @cerc-io/laconic-registry-cli
# Globally install the cli package
RUN yarn global add @cerc-io/laconic-registry-cli

View File

@ -5,5 +5,5 @@
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
docker build -t cerc/laconic-registry-cli:local -f ${SCRIPT_DIR}/Dockerfile \
--add-host host.docker.internal:host-gateway \
--add-host gitea.local:host-gateway \
--build-arg CERC_NPM_AUTH_TOKEN --build-arg CERC_NPM_URL ${SCRIPT_DIR}