Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

implement ch-image modify #1408

Merged
merged 71 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
e8b04c9
draft docs [skip ci]
reidpr Jul 9, 2022
2e1da45
attempt to merge
lucaudill Feb 14, 2024
83beda8
add proper formatting [skip ci]
lucaudill Feb 14, 2024
244d174
interactive modify [skip ci]
lucaudill Feb 26, 2024
1ae7c94
Merge branch 'master' into modify_1400
lucaudill Feb 26, 2024
580b6ec
move modify function, other additions (buggy) [skip ci]
lucaudill Mar 14, 2024
e843576
clean stuff up a bit?
lucaudill Mar 19, 2024
d05460e
add (prototype) completion [skip ci]
lucaudill Mar 19, 2024
1df874f
don't enforce different out image [skip ci]
lucaudill Mar 28, 2024
50f917f
standardize ch-run exit codes, make sure out image is different than …
lucaudill Apr 4, 2024
2f43bc9
fix a bug?
lucaudill Apr 4, 2024
491ce01
update some return codes in CI
lucaudill Apr 4, 2024
6f8014e
update test suite
lucaudill Apr 22, 2024
4996b4e
update more exit statuses
lucaudill Apr 22, 2024
feee043
Merge branch 'master' into modify_1400
lucaudill Apr 22, 2024
e641935
wtf
lucaudill Apr 23, 2024
a0867d4
Merge branch 'modify_1400' of github.com:hpc/charliecloud into modify…
lucaudill Apr 23, 2024
151592f
enable CI ssh
lucaudill Apr 24, 2024
e0bc574
run ci
lucaudill Apr 24, 2024
7d6f66e
oops
lucaudill Apr 24, 2024
2c8b2f7
CI debugging
lucaudill Apr 25, 2024
731cfe8
CI debugging again
lucaudill Apr 25, 2024
fd45f64
CI debugging again pt 2
lucaudill Apr 25, 2024
05dac9b
fix a CI bug
lucaudill Apr 25, 2024
00e2ec6
more ci
lucaudill Apr 25, 2024
de7d63c
uggh
lucaudill Apr 25, 2024
f7b87e5
lets try this
lucaudill Apr 25, 2024
4b84644
fix disabled cache bug
lucaudill Apr 25, 2024
1afc853
update docs [skip ci]
lucaudill Apr 26, 2024
c6ae8a9
weird docker message?
lucaudill Apr 29, 2024
4e61c06
some cleanup [skip ci]
lucaudill Apr 30, 2024
9d74d19
put CI exit statuses in one place
lucaudill May 1, 2024
579ec81
ignore seemingly erroneous SC error
lucaudill May 2, 2024
b37232b
update exit codes and docs
lucaudill May 2, 2024
3742a28
oops 🤦
lucaudill May 6, 2024
6e0ff69
tidy docs [skip ci]
reidpr May 10, 2024
26ce9e6
work on suggestions
lucaudill May 21, 2024
dbbf74d
more work on non-interactive script case
lucaudill Jun 4, 2024
8cb7975
try to debug CI
lucaudill Jun 4, 2024
b859089
hopefully this works
lucaudill Jun 5, 2024
54c2ee8
back to how it used to work?
lucaudill Jun 5, 2024
bb0283e
more interactive shell troubles
lucaudill Jun 5, 2024
6bc35a9
skip mysteriously failing test for now
lucaudill Jun 6, 2024
8a97d8d
work on some suggestions
lucaudill Jun 7, 2024
5be8c3e
more RPM issues?
lucaudill Jun 7, 2024
c53a820
oops, misread failure
lucaudill Jun 7, 2024
1dcbb4d
what happens when I do this
lucaudill Jun 7, 2024
3314546
try removing hidden ci opt
lucaudill Jun 10, 2024
6ec4b26
fully remove automated ci option
lucaudill Jun 10, 2024
b6da358
hopefully this also works in CI
lucaudill Jun 10, 2024
2b96ecc
fix syntax error
lucaudill Jun 10, 2024
ed46d89
check for empty string instead of None
lucaudill Jun 10, 2024
fc5c89a
update comment [skip ci]
lucaudill Jun 11, 2024
a9b1e23
Merge branch 'master' into modify_1400
lucaudill Jun 21, 2024
dc5ed4d
fix interactive case
lucaudill Jun 21, 2024
1593009
Merge branch 'modify_1400' of github.com:hpc/charliecloud into modify…
lucaudill Jun 21, 2024
7c320e7
create new Python module
lucaudill Jul 5, 2024
d3b06fb
add new module to makefile
lucaudill Jul 5, 2024
ce2a620
update fedora spec
lucaudill Jul 5, 2024
7f17900
a few minor suggestions
lucaudill Jul 5, 2024
8d0befc
more suggestions, move some build cli stuff around
lucaudill Jul 15, 2024
1b65df9
fix CI tty error
lucaudill Jul 15, 2024
d4f90f3
add cache validation test
lucaudill Jul 15, 2024
09f78f2
add cache validation for interactive modify
lucaudill Jul 16, 2024
681a39c
more suggestions
lucaudill Jul 18, 2024
2cd6149
fix CI
lucaudill Jul 18, 2024
20e2d91
even more suggestions
lucaudill Jul 19, 2024
32efbe4
couple more suggestions
lucaudill Jul 23, 2024
f4b1ba7
docs + comments
lucaudill Jul 24, 2024
62fe3e2
comment on log level stuff
lucaudill Jul 24, 2024
621b19a
some cleanup
lucaudill Jul 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/ch-checkns.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void fatal_(const char *file, int line, int errno_, const char *str)
char *url = "https://github.com/hpc/charliecloud/blob/master/bin/ch-checkns.c";
printf("error: %s: %d: %s\n", file, line, str);
printf("errno: %d\nsee: %s\n", errno_, url);
exit(1);
exit(ERR_CHRUN);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should call it EXIT_CHRUN or EXIT_MISC_FAIL instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking more about this I do think we want something about exiting rather than errors.

}

int main(int argc, char *argv[])
Expand Down
20 changes: 14 additions & 6 deletions bin/ch-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,16 @@ _ch_convert_complete () {
_image_build_opts="-b --bind --build-arg -f --file --force
--force-cmd -n --dry-run --parse-only -t --tag"

_image_modify_opts="-c -S --shell"

_image_common_opts="-a --arch --always-download --auth --break
--cache --cache-large --dependencies -h --help
--no-cache --no-lock --no-xattrs --profile
--rebuild --password-many -q --quiet -s --storage
--tls-no-verify -v --verbose --version --xattrs"

_image_subcommands="build build-cache delete gestalt
import list pull push reset undelete"
_image_subcommands="build build-cache delete gestalt import
list modify pull push reset undelete"

# archs taken from ARCH_MAP in charliecloud.py
_archs="amd64 arm/v5 arm/v6 arm/v7 arm64/v8 386 mips64le ppc64le s390x"
Expand Down Expand Up @@ -374,20 +376,26 @@ _ch_image_complete () {
build-cache)
COMPREPLY=( $(compgen -W "--reset --gc --tree --dot" -- "$cur") )
;;
delete|list)
if [[ "$sub_cmd" == "list" ]]; then
delete|list|modify)
case "$sub_cmd" in
list)
if [[ "$prev" == "--undeletable" || "$prev" == "--undeleteable" || "$prev" == "-u" ]]; then
COMPREPLY=( $(compgen -W "$(_ch_undelete_list "$strg_dir")" -- "$cur") )
return 0
fi
extras+="$extras -l --long -u --undeletable"
extras="$extras -l --long -u --undeletable"
# If “cur” starts with “--undelete,” add “--undeleteable” (the less
# correct version of “--undeletable”) to the list of possible
# completions.
if [[ ${cur::10} == "--undelete" ]]; then
extras="$extras --undeleteable"
fi
fi
;;
modify)
# FIXME: Implement
extras="$extras $_image_modify_opts"
;;
esac
COMPREPLY=( $(compgen -W "$(_ch_list_images "$strg_dir") $extras" -- "$cur") )
__ltrim_colon_completions "$cur"
;;
Expand Down
11 changes: 11 additions & 0 deletions bin/ch-image.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import charliecloud as ch
import build
import build_cache as bu
import filesystem as fs
import image as im
import misc
import pull
import push
Expand Down Expand Up @@ -278,6 +279,16 @@ def main():
sp.add_argument("image_ref", metavar="IMAGE_REF", nargs="?",
help="print details of this image only")

# modify
sp = ap.add_parser("modify", "foo")
add_opts(sp, build.modify, deps_check=True, stog_init=True)
sp.add_argument("-c", metavar="CMD", action="append", default=[], nargs=1, help="foo")
sp.add_argument("-S", "--shell", metavar="shell", help="foo")
sp.add_argument("image_ref", metavar="IMAGE_REF", help="image to modify")
sp.add_argument("out_image", metavar="OUT_IMAGE", help="destination of modified image")
# Optional positional argument? https://stackoverflow.com/a/4480202
lucaudill marked this conversation as resolved.
Show resolved Hide resolved
sp.add_argument("script", metavar="SCRIPT", help="foo", nargs='?')

# pull
sp = ap.add_parser("pull",
"copy image from remote repository to local filesystem")
Expand Down
16 changes: 8 additions & 8 deletions bin/ch-run.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ int main(int argc, char *argv[])

if (arg_next >= argc - 1) {
printf("usage: ch-run [OPTION...] IMAGE -- COMMAND [ARG...]\n");
FATAL("IMAGE and/or COMMAND not specified");
FATAL(0, "IMAGE and/or COMMAND not specified");
}
args.c.img_ref = argv[arg_next++];
args.c.newroot = realpath_(args.c.newroot, true);
Expand All @@ -210,11 +210,11 @@ int main(int argc, char *argv[])
break;
case IMG_SQUASH:
#ifndef HAVE_LIBSQUASHFUSE
FATAL("this ch-run does not support internal SquashFS mounts");
FATAL(0, "this ch-run does not support internal SquashFS mounts");
#endif
break;
case IMG_NONE:
FATAL("unknown image type: %s", args.c.img_ref);
FATAL(0, "unknown image type: %s", args.c.img_ref);
break;
}

Expand Down Expand Up @@ -445,7 +445,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
#ifdef HAVE_FNM_EXTMATCH
exit(0);
#else
exit(1);
exit(ERR_CHRUN);
#endif
} else if (!strcmp(arg, "overlayfs")) {
#ifdef HAVE_OVERLAYFS
Expand All @@ -457,13 +457,13 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
#ifdef HAVE_SECCOMP
exit(0);
#else
exit(1);
exit(ERR_CHRUN);
#endif
} else if (!strcmp(arg, "squash")) {
#ifdef HAVE_LIBSQUASHFUSE
exit(0);
#else
exit(1);
exit(ERR_CHRUN);
#endif
} else if (!strcmp(arg, "tmpfs-xattrs")) {
#ifdef HAVE_TMPFS_XATTRS
Expand All @@ -473,7 +473,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
#endif
}
else
FATAL("unknown feature: %s", arg);
FATAL(0, "unknown feature: %s", arg);
break;
case -12: // --home
Tf (args->c.host_home = getenv("HOME"), "--home failed: $HOME not set");
Expand Down Expand Up @@ -504,7 +504,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
else if (!strcmp(arg, "log-fail"))
test_logging(true);
else
FATAL("invalid --test argument: %s; see source code", arg);
FATAL(0, "invalid --test argument: %s; see source code", arg);
break;
case 'b': { // --bind
char *src, *dst;
Expand Down
7 changes: 4 additions & 3 deletions bin/ch_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ void bind_mount(const char *src, const char *dst, enum bind_dep dep,
if (!path_exists(dst_full, NULL, true))
switch (dep) {
case BD_REQUIRED:
FATAL("can't bind: destination not found: %s", dst_full);
FATAL(0, "can't bind: destination not found: %s", dst_full);
break;
case BD_OPTIONAL:
return;
Expand Down Expand Up @@ -421,7 +421,7 @@ enum img_type image_type(const char *ref, const char *storage_dir)
return IMG_SQUASH;

// Well now we’re stumped.
FATAL("unknown image type: %s", ref);
FATAL(0, "unknown image type: %s", ref);
}

char *img_name2path(const char *name, const char *storage_dir)
Expand Down Expand Up @@ -567,7 +567,8 @@ void run_user_command(char *argv[], const char *initial_dir)
if (verbose < LL_STDERR)
T_ (freopen("/dev/null", "w", stderr));
execvp(argv[0], argv); // only returns if error
Tf (0, "can't execve(2): %s", argv[0]);
ERROR(errno, "can't execve(2): %s", argv[0]);
exit(ERR_CMD);
}

/* Set up the fake-syscall seccomp(2) filter. This computes and installs a
Expand Down
6 changes: 3 additions & 3 deletions bin/ch_fuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ int sq_loop(void)

// Clean up zombie child if exit signal was SIGCHLD.
if (!sigchld_received)
exit_code = 0;
exit_code = ERR_SQUASH;
else {
Tf (wait(&child_status) >= 0, "can't wait for child");
if (WIFEXITED(child_status)) {
Expand All @@ -203,7 +203,7 @@ int sq_loop(void)
//
// [1]: https://codereview.stackexchange.com/a/109349
// [2]: https://man7.org/linux/man-pages/man2/wait.2.html
exit_code = 1;
exit_code = 128 + WTERMSIG(child_status);
VERBOSE("child terminated by signal %d", WTERMSIG(child_status))
}
}
Expand Down Expand Up @@ -254,7 +254,7 @@ void sq_mount(const char *img_path, char *mountpt)
&OPS, sizeof(OPS), sq.ll)) {
break; // success
} else if (i <= 0) {
FATAL("too many FUSE errors; giving up");
FATAL(0, "too many FUSE errors; giving up");
} else {
WARNING("FUSE error mounting SquashFS; will retry");
sleep(1);
Expand Down
14 changes: 12 additions & 2 deletions bin/ch_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ void test_logging(bool fail) {
INFO("info");
WARNING("warning");
if (fail)
FATAL("the program failed inexplicably (\"log-fail\" specified)");
FATAL(0, "the program failed inexplicably (\"log-fail\" specified)");
exit(0);
}

Expand Down Expand Up @@ -586,6 +586,16 @@ void msg(enum log_level level, const char *file, int line, int errno_,
va_end(ap);
}

void msg_error(const char *file, int line, int errno_,
const char *fmt, ...)
{
va_list ap;

va_start(ap, fmt);
msgv(LL_FATAL, file, line, errno_, fmt, ap);
reidpr marked this conversation as resolved.
Show resolved Hide resolved
va_end(ap);
}

noreturn void msg_fatal(const char *file, int line, int errno_,
const char *fmt, ...)
{
Expand All @@ -595,7 +605,7 @@ noreturn void msg_fatal(const char *file, int line, int errno_,
msgv(LL_FATAL, file, line, errno_, fmt, ap);
va_end(ap);

exit(EXIT_FAILURE);
exit(ERR_CHRUN);
lucaudill marked this conversation as resolved.
Show resolved Hide resolved
}

/* va_list form of msg(). */
Expand Down
20 changes: 14 additions & 6 deletions bin/ch_misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
don’t need to worry about running out of room. */
#define WARNINGS_SIZE (4*1024)

/* Exit codes (see also: test/common.bash, lib/build.py). */
#define ERR_CHRUN 31
#define ERR_CMD 49
#define ERR_SQUASH 84

/* Test some value, and if it's not what we expect, exit with a fatal error.
These are macros so we have access to the file and line number.

Expand Down Expand Up @@ -66,12 +71,13 @@
#define Zf(x, ...) if (x) msg_fatal(__FILE__, __LINE__, errno, __VA_ARGS__)
#define Ze(x, ...) if (x) msg_fatal(__FILE__, __LINE__, 0, __VA_ARGS__)

#define FATAL(...) msg_fatal( __FILE__, __LINE__, 0, __VA_ARGS__);
#define WARNING(...) msg(LL_WARNING, __FILE__, __LINE__, 0, __VA_ARGS__);
#define INFO(...) msg(LL_INFO, __FILE__, __LINE__, 0, __VA_ARGS__);
#define VERBOSE(...) msg(LL_VERBOSE, __FILE__, __LINE__, 0, __VA_ARGS__);
#define DEBUG(...) msg(LL_DEBUG, __FILE__, __LINE__, 0, __VA_ARGS__);
#define TRACE(...) msg(LL_TRACE, __FILE__, __LINE__, 0, __VA_ARGS__);
#define FATAL(e, ...) msg_fatal( __FILE__, __LINE__, e, __VA_ARGS__);
#define ERROR(e, ...) msg_error( __FILE__, __LINE__, e, __VA_ARGS__);
#define WARNING(...) msg(LL_WARNING, __FILE__, __LINE__, 0, __VA_ARGS__);
#define INFO(...) msg(LL_INFO, __FILE__, __LINE__, 0, __VA_ARGS__);
#define VERBOSE(...) msg(LL_VERBOSE, __FILE__, __LINE__, 0, __VA_ARGS__);
#define DEBUG(...) msg(LL_DEBUG, __FILE__, __LINE__, 0, __VA_ARGS__);
#define TRACE(...) msg(LL_TRACE, __FILE__, __LINE__, 0, __VA_ARGS__);


/** Types **/
Expand Down Expand Up @@ -134,6 +140,8 @@ void mkdirs(const char *base, const char *path, char **denylist,
const char *scratch);
void msg(enum log_level level, const char *file, int line, int errno_,
const char *fmt, ...);
void msg_error(const char *file, int line, int errno_,
const char *fmt, ...);
noreturn void msg_fatal(const char *file, int line, int errno_,
const char *fmt, ...);
bool path_exists(const char *path, struct stat *statbuf, bool follow_symlink);
Expand Down
Loading