Skip to content

Commit 151c0d4

Browse files
committed
Deploy with podman and podman-compose
Signed-off-by: Song Tang <[email protected]>
1 parent d0934b2 commit 151c0d4

File tree

6 files changed

+310
-20
lines changed

6 files changed

+310
-20
lines changed

make/common.sh

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/bash
22
#docker version: 20.10.10+
33
#docker-compose version: 1.18.0+
4+
#podman version: 4.9.3+
5+
#podman-compose version: 1.0.6+
46
#golang version: 1.12.0+
57

68
set +e
@@ -75,13 +77,42 @@ function check_golang {
7577
fi
7678
}
7779

78-
function check_docker {
80+
function check_docker {
7981
if ! docker --version &> /dev/null
8082
then
81-
error "Need to install docker(20.10.10+) first and run this script again."
83+
error "Need to install docker(20.10.10+) or podman(4.9.3+) first and run this script again."
8284
exit 1
8385
fi
8486

87+
# either docker is podman
88+
if docker --version 2>&1 | grep -qi podman; then
89+
note "Detected Podman as the Docker CLI."
90+
# Check Podman version
91+
# capture major, minor and patch (e.g. 4.9.3)
92+
if [[ $(podman --version) =~ (([0-9]+)\.([0-9]+)\.([0-9]+)([\.0-9]*)) ]]
93+
then
94+
podman_version=${BASH_REMATCH[1]}
95+
podman_version_part1=${BASH_REMATCH[2]}
96+
podman_version_part2=${BASH_REMATCH[3]}
97+
podman_version_part3=${BASH_REMATCH[4]}
98+
99+
note "Podman version: $podman_version"
100+
# the version of Podman does not meet the requirement 4.9.3+
101+
if [ "$podman_version_part1" -lt 4 ] || \
102+
([ "$podman_version_part1" -eq 4 ] && [ "$podman_version_part2" -lt 9 ]) || \
103+
([ "$podman_version_part1" -eq 4 ] && [ "$podman_version_part2" -eq 9 ] && [ "$podman_version_part3" -lt 3 ])
104+
then
105+
error "Need to upgrade Podman package to 4.9.3+."
106+
exit 1
107+
fi
108+
else
109+
error "Failed to parse Podman version."
110+
exit 1
111+
fi
112+
# Skip Docker version checks if Podman is detected
113+
return
114+
fi
115+
85116
# docker has been installed and check its version
86117
if [[ $(docker --version) =~ (([0-9]+)\.([0-9]+)([\.0-9]*)) ]]
87118
then
@@ -91,7 +122,7 @@ function check_docker {
91122

92123
note "docker version: $docker_version"
93124
# the version of docker does not meet the requirement
94-
if [ "$docker_version_part1" -lt 17 ] || ([ "$docker_version_part1" -eq 17 ] && [ "$docker_version_part2" -lt 6 ])
125+
if [ "$docker_version_part1" -lt 20 ] || ([ "$docker_version_part1" -eq 20 ] && [ "$docker_version_part2" -lt 10 ])
95126
then
96127
error "Need to upgrade docker package to 20.10.10+."
97128
exit 1

make/install.sh

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ set +o noglob
99

1010
usage=$'Please set hostname and other necessary attributes in harbor.yml first. DO NOT use localhost or 127.0.0.1 for hostname, because Harbor needs to be accessed by external clients.
1111
Please set --with-trivy if needs enable Trivy in Harbor.
12+
Please set --with-podman if you want to force prepare to treat the Docker CLI as Podman.
1213
Please do NOT set --with-chartmuseum, as chartmusuem has been deprecated and removed.
1314
Please do NOT set --with-notary, as notary has been deprecated and removed.'
1415
item=0
@@ -17,6 +18,8 @@ item=0
1718
with_clair=$false
1819
# trivy is not enabled by default
1920
with_trivy=$false
21+
# podman option not enabled by default
22+
with_podman=$false
2023

2124
# flag to using docker compose v1 or v2, default would using v1 docker-compose
2225
DOCKER_COMPOSE=docker-compose
@@ -28,6 +31,8 @@ while [ $# -gt 0 ]; do
2831
exit 0;;
2932
--with-trivy)
3033
with_trivy=true;;
34+
--with-podman)
35+
with_podman=true;;
3136
*)
3237
note "$usage"
3338
exit 1;;
@@ -64,13 +69,23 @@ then
6469
prepare_para="${prepare_para} --with-trivy"
6570
fi
6671

72+
if [ $with_podman ]
73+
then
74+
prepare_para="${prepare_para} --with-podman"
75+
fi
76+
6777
./prepare $prepare_para
78+
6879
echo ""
6980

70-
if [ -n "$DOCKER_COMPOSE ps -q" ]
71-
then
72-
note "stopping existing Harbor instance ..."
73-
$DOCKER_COMPOSE down -v
81+
# Check if any containers started by compose are present. Capture the compose
82+
# output and filter to only valid container IDs so vendor warnings (for
83+
# example "Emulate Docker CLI using podman...") don't make the check true.
84+
compose_ps_output=$($DOCKER_COMPOSE ps -q 2>/dev/null | grep -E '^[0-9a-fA-F]+$' || true)
85+
if [ -n "$compose_ps_output" ]
86+
then
87+
note "stopping existing Harbor instance ..."
88+
$DOCKER_COMPOSE down -v
7489
fi
7590
echo ""
7691

make/photon/prepare/commands/prepare.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
@click.command()
2828
@click.option('--conf', default=input_config_path, help="the path of Harbor configuration file")
2929
@click.option('--with-trivy', is_flag=True, help="the Harbor instance is to be deployed with Trivy")
30-
def prepare(conf, with_trivy):
30+
@click.option('--with-podman', is_flag=True, help="the Harbor instance will be deployed using Podman (avoid Docker logging options)")
31+
def prepare(conf, with_trivy, with_podman):
3132

3233
delfile(config_dir)
3334
config_dict = parse_yaml_config(conf, with_trivy=with_trivy)
@@ -65,4 +66,4 @@ def prepare(conf, with_trivy):
6566
if with_trivy:
6667
prepare_trivy_adapter(config_dict)
6768

68-
prepare_docker_compose(config_dict, with_trivy)
69+
prepare_docker_compose(config_dict, with_trivy, with_podman)

0 commit comments

Comments
 (0)