Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Ship Cat container manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wizards
Ship Cat container manager
Commits
878335e2
Commit
878335e2
authored
1 year ago
by
Martin Mareš
Browse files
Options
Downloads
Patches
Plain Diff
create -> update
parent
04cf30b9
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
TODO
+0
-3
0 additions, 3 deletions
TODO
shipcat/main.py
+32
-25
32 additions, 25 deletions
shipcat/main.py
with
32 additions
and
28 deletions
TODO
+
0
−
3
View file @
878335e2
- more colors
- "shc CONTAINER start" vs. "shc CONTAINER shell"
Albireo cleanup:
Albireo cleanup:
- prerouting rule
- prerouting rule
- containers
- containers
This diff is collapsed.
Click to expand it.
shipcat/main.py
+
32
−
25
View file @
878335e2
...
@@ -11,13 +11,13 @@ import sys
...
@@ -11,13 +11,13 @@ import sys
from
typing
import
List
,
Optional
from
typing
import
List
,
Optional
from
shipcat.config
import
GlobalConfig
,
ContainerConfig
,
ConfigError
from
shipcat.config
import
GlobalConfig
,
ContainerConfig
,
ConfigError
from
shipcat.util
import
die
,
verbose
,
set_verbose
,
run_command
from
shipcat.util
import
die
,
progress
,
verbose
,
set_verbose
,
run_command
config
:
GlobalConfig
config
:
GlobalConfig
def
progress
(
msg
:
str
)
->
None
:
def
trace
(
msg
:
str
)
->
None
:
print
(
msg
,
file
=
sys
.
stderr
,
end
=
""
,
flush
=
True
)
print
(
msg
,
file
=
sys
.
stderr
,
end
=
""
,
flush
=
True
)
...
@@ -107,68 +107,68 @@ def cmd_init(args: argparse.Namespace) -> None:
...
@@ -107,68 +107,68 @@ def cmd_init(args: argparse.Namespace) -> None:
name
=
args
.
name
name
=
args
.
name
cc
=
setup_container
(
args
,
True
)
cc
=
setup_container
(
args
,
True
)
progress
(
f
'
User
{
cc
.
user_name
}
:
'
)
trace
(
f
'
User
{
cc
.
user_name
}
:
'
)
try
:
try
:
pwd
=
getpwnam
(
cc
.
user_name
)
pwd
=
getpwnam
(
cc
.
user_name
)
progress
(
'
already exists
\n
'
)
trace
(
'
already exists
\n
'
)
except
KeyError
:
except
KeyError
:
progress
(
'
creating
\n
'
)
trace
(
'
creating
\n
'
)
run_command
(
run_command
(
[
'
adduser
'
,
'
--system
'
,
'
--group
'
,
'
--gecos
'
,
f
'
Container
{
name
}
'
,
'
--disabled-password
'
,
cc
.
user_name
]
[
'
adduser
'
,
'
--system
'
,
'
--group
'
,
'
--gecos
'
,
f
'
Container
{
name
}
'
,
'
--disabled-password
'
,
cc
.
user_name
]
)
)
pwd
=
getpwnam
(
cc
.
user_name
)
pwd
=
getpwnam
(
cc
.
user_name
)
uid
=
pwd
.
pw_uid
uid
=
pwd
.
pw_uid
progress
(
'
Subuid range:
'
)
trace
(
'
Subuid range:
'
)
subuids
=
SubIds
(
'
/etc/subuid
'
)
subuids
=
SubIds
(
'
/etc/subuid
'
)
sur
=
subuids
.
find_range
(
uid
,
cc
.
user_name
,
65536
)
sur
=
subuids
.
find_range
(
uid
,
cc
.
user_name
,
65536
)
if
sur
is
not
None
:
if
sur
is
not
None
:
progress
(
'
already exists
\n
'
)
trace
(
'
already exists
\n
'
)
else
:
else
:
progress
(
'
allocating
\n
'
)
trace
(
'
allocating
\n
'
)
sur
=
subuids
.
alloc_range
(
cc
.
user_name
,
65536
)
sur
=
subuids
.
alloc_range
(
cc
.
user_name
,
65536
)
run_command
(
run_command
(
[
'
usermod
'
,
'
--add-subuids
'
,
f
'
{
sur
.
first
}
-
{
sur
.
first
+
sur
.
count
-
1
}
'
,
cc
.
user_name
]
[
'
usermod
'
,
'
--add-subuids
'
,
f
'
{
sur
.
first
}
-
{
sur
.
first
+
sur
.
count
-
1
}
'
,
cc
.
user_name
]
)
)
progress
(
'
Subgid range:
'
)
trace
(
'
Subgid range:
'
)
subgids
=
SubIds
(
'
/etc/subgid
'
)
subgids
=
SubIds
(
'
/etc/subgid
'
)
sgr
=
subgids
.
find_range
(
uid
,
cc
.
user_name
,
65536
)
sgr
=
subgids
.
find_range
(
uid
,
cc
.
user_name
,
65536
)
if
sgr
is
not
None
:
if
sgr
is
not
None
:
progress
(
'
already exists
\n
'
)
trace
(
'
already exists
\n
'
)
else
:
else
:
progress
(
'
allocating
\n
'
)
trace
(
'
allocating
\n
'
)
sgr
=
subgids
.
alloc_range
(
cc
.
user_name
,
65536
)
sgr
=
subgids
.
alloc_range
(
cc
.
user_name
,
65536
)
run_command
(
run_command
(
[
'
usermod
'
,
'
--add-subgids
'
,
f
'
{
sgr
.
first
}
-
{
sgr
.
first
+
sgr
.
count
-
1
}
'
,
cc
.
user_name
]
[
'
usermod
'
,
'
--add-subgids
'
,
f
'
{
sgr
.
first
}
-
{
sgr
.
first
+
sgr
.
count
-
1
}
'
,
cc
.
user_name
]
)
)
progress
(
f
'
Using user
{
cc
.
user_name
}
, uid
{
uid
}
, subuids
{
sur
.
first
}
+
{
sur
.
count
}
, subgids
{
sgr
.
first
}
+
{
sgr
.
count
}
\n
'
)
trace
(
f
'
Using user
{
cc
.
user_name
}
, uid
{
uid
}
, subuids
{
sur
.
first
}
+
{
sur
.
count
}
, subgids
{
sgr
.
first
}
+
{
sgr
.
count
}
\n
'
)
root_path
=
cc
.
root_path
root_path
=
cc
.
root_path
progress
(
f
'
Container directory
{
root_path
}
:
'
)
trace
(
f
'
Container directory
{
root_path
}
:
'
)
if
root_path
.
is_dir
():
if
root_path
.
is_dir
():
progress
(
'
already exists
\n
'
)
trace
(
'
already exists
\n
'
)
else
:
else
:
root_path
.
mkdir
(
mode
=
0o750
,
exist_ok
=
True
)
root_path
.
mkdir
(
mode
=
0o750
,
exist_ok
=
True
)
os
.
chown
(
root_path
,
0
,
sgr
.
first
)
os
.
chown
(
root_path
,
0
,
sgr
.
first
)
progress
(
'
created
\n
'
)
trace
(
'
created
\n
'
)
data_path
=
cc
.
data_path
data_path
=
cc
.
data_path
progress
(
f
'
Data directory
{
data_path
}
:
'
)
trace
(
f
'
Data directory
{
data_path
}
:
'
)
if
data_path
.
is_dir
():
if
data_path
.
is_dir
():
progress
(
'
already exists
\n
'
)
trace
(
'
already exists
\n
'
)
else
:
else
:
data_path
.
mkdir
(
mode
=
0o755
,
exist_ok
=
True
)
data_path
.
mkdir
(
mode
=
0o755
,
exist_ok
=
True
)
os
.
chown
(
data_path
,
sur
.
first
,
sgr
.
first
)
os
.
chown
(
data_path
,
sur
.
first
,
sgr
.
first
)
progress
(
'
created
\n
'
)
trace
(
'
created
\n
'
)
progress
(
'
IP address:
'
)
trace
(
'
IP address:
'
)
try
:
try
:
ip
=
socket
.
gethostbyname
(
name
)
ip
=
socket
.
gethostbyname
(
name
)
except
OSError
as
e
:
except
OSError
as
e
:
die
(
str
(
e
))
die
(
str
(
e
))
progress
(
f
'
{
ip
}
\n
'
)
trace
(
f
'
{
ip
}
\n
'
)
def
service_action
(
cc
:
ContainerConfig
,
action
:
str
)
->
None
:
def
service_action
(
cc
:
ContainerConfig
,
action
:
str
)
->
None
:
...
@@ -177,16 +177,23 @@ def service_action(cc: ContainerConfig, action: str) -> None:
...
@@ -177,16 +177,23 @@ def service_action(cc: ContainerConfig, action: str) -> None:
)
)
def
cmd_
cre
ate
(
args
:
argparse
.
Namespace
)
->
None
:
def
cmd_
upd
ate
(
args
:
argparse
.
Namespace
)
->
None
:
cc
=
setup_container
(
args
,
False
)
cc
=
setup_container
(
args
,
False
)
progress
(
'
Pulling new image
'
)
run_command
(
run_command
(
[
'
podman
'
,
'
pull
'
,
cc
.
image
]
[
'
podman
'
,
'
pull
'
,
cc
.
image
]
)
)
progress
(
'
Stopping container
'
)
service_action
(
cc
,
'
stop
'
)
service_action
(
cc
,
'
stop
'
)
progress
(
'
Creating container
'
)
create_container
(
cc
)
create_container
(
cc
)
progress
(
'
Starting container
'
)
service_action
(
cc
,
'
start
'
)
def
create_container
(
cc
:
ContainerConfig
)
->
None
:
def
create_container
(
cc
:
ContainerConfig
)
->
None
:
ip
=
socket
.
gethostbyname
(
cc
.
name
)
ip
=
socket
.
gethostbyname
(
cc
.
name
)
...
@@ -343,9 +350,6 @@ def main() -> None:
...
@@ -343,9 +350,6 @@ def main() -> None:
parser
.
add_argument
(
'
--verbose
'
,
'
-v
'
,
default
=
False
,
action
=
'
store_true
'
,
help
=
'
be chatty and explain what is going on
'
)
parser
.
add_argument
(
'
--verbose
'
,
'
-v
'
,
default
=
False
,
action
=
'
store_true
'
,
help
=
'
be chatty and explain what is going on
'
)
subparsers
=
parser
.
add_subparsers
(
help
=
'
action to perform
'
,
dest
=
'
action
'
,
required
=
True
,
metavar
=
'
ACTION
'
)
subparsers
=
parser
.
add_subparsers
(
help
=
'
action to perform
'
,
dest
=
'
action
'
,
required
=
True
,
metavar
=
'
ACTION
'
)
create_parser
=
subparsers
.
add_parser
(
'
create
'
,
help
=
'
create a container from an image
'
,
description
=
'
Create a container from an image.
'
)
create_parser
.
add_argument
(
'
name
'
,
help
=
'
name of the container
'
)
create_parser
=
subparsers
.
add_parser
(
'
disable
'
,
help
=
'
disable automatic startup of a container
'
,
description
=
'
Disable automatic startup of a container.
'
)
create_parser
=
subparsers
.
add_parser
(
'
disable
'
,
help
=
'
disable automatic startup of a container
'
,
description
=
'
Disable automatic startup of a container.
'
)
create_parser
.
add_argument
(
'
name
'
,
help
=
'
name of the container
'
)
create_parser
.
add_argument
(
'
name
'
,
help
=
'
name of the container
'
)
...
@@ -385,10 +389,12 @@ def main() -> None:
...
@@ -385,10 +389,12 @@ def main() -> None:
stop_parser
=
subparsers
.
add_parser
(
'
stop
'
,
help
=
'
stop a container
'
,
description
=
'
Stop a container
'
)
stop_parser
=
subparsers
.
add_parser
(
'
stop
'
,
help
=
'
stop a container
'
,
description
=
'
Stop a container
'
)
stop_parser
.
add_argument
(
'
name
'
,
help
=
'
name of the container
'
)
stop_parser
.
add_argument
(
'
name
'
,
help
=
'
name of the container
'
)
update_parser
=
subparsers
.
add_parser
(
'
update
'
,
help
=
'
update a container from an image
'
,
description
=
'
Update a container from an image and start it.
'
)
update_parser
.
add_argument
(
'
name
'
,
help
=
'
name of the container
'
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
actions
=
{
actions
=
{
'
create
'
:
cmd_create
,
'
disable
'
:
cmd_disable
,
'
disable
'
:
cmd_disable
,
'
enable
'
:
cmd_enable
,
'
enable
'
:
cmd_enable
,
'
exec
'
:
cmd_exec
,
'
exec
'
:
cmd_exec
,
...
@@ -399,6 +405,7 @@ def main() -> None:
...
@@ -399,6 +405,7 @@ def main() -> None:
'
start
'
:
cmd_start
,
'
start
'
:
cmd_start
,
'
status
'
:
cmd_status
,
'
status
'
:
cmd_status
,
'
stop
'
:
cmd_stop
,
'
stop
'
:
cmd_stop
,
'
update
'
:
cmd_update
,
}
}
global
config
global
config
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment