Skip to content

Commit

Permalink
compose-dirs v1.4.0 update
Browse files Browse the repository at this point in the history
  • Loading branch information
cpontvieux-systra committed Oct 12, 2021
1 parent 8f815b7 commit d8563cd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
CHANGELOG
=========

Next
version 2.6.0
-------------
- Updated image versions.
- `capp` can be tested in docker.
- `compose-dirs` updated to version `1.4.0`.
- More verbose tasks on `deploy`/`undeploy`.

version 2.5.0
-------------
Expand Down
29 changes: 19 additions & 10 deletions capp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ from yaml import (

from verify_dca import verify_checksum

__version__ = (2, 5, 0)
__version__ = (2, 6, 0)


def printflush(*args, **kwargs):
Expand Down Expand Up @@ -603,6 +603,7 @@ class CApp:
return sorted(hooks)

def _run_hook(self, hook_file, app, target_env, version, compose_file, target_dir):
printflush(f"Run hook {hook_file}")
run(['/usr/bin/sudo', str(hook_file), app, target_env, str(version), str(compose_file), str(target_dir)], stdin=0, check=True, text=True)

def _to_bytes(self, value_unit):
Expand Down Expand Up @@ -802,12 +803,16 @@ class CApp:
f.truncate()
f.write('\n'.join(deps))
f.write('\n')
run(['sudo', '/usr/local/bin/compose-dirs', 'update'], check=True, text=True)
printflush("Update systemd")
run(['sudo', '/usr/local/bin/compose-dirs', 'update', f'{app}/{target_env}'], check=True, text=True)
systemd_svc = self._get_systemd_service_name(app, target_env)
if args.start:
printflush("Restart application")
run(['sudo', 'systemctl', 'restart', systemd_svc], check=True, text=True)
elif run(['systemctl', 'is-active', systemd_svc], capture_output=True).returncode == 0:
printflush("Stop application")
run(['sudo', 'systemctl', 'stop', systemd_svc], check=True, text=True)
printflush("Cleaning dangling images…")
run(['docker', 'image', 'prune', '-f'], text=True)
self._post_deploy(app, target_env, version, target_dir / 'docker-compose.yml', target_dir)

Expand Down Expand Up @@ -875,7 +880,7 @@ class CApp:
signature = b64decode(signature_base64)
for pubkey_file in (f for f in self.pubkeys_dir.iterdir() if f.is_file() and f.suffix == '.pub'):
if self._verify_signature(signature, compose_file, pubkey_file):
printflush("signature: 'OK'")
printflush("Signature: 'OK'")
break
else:
raise ValueError("metadata signature mismatch")
Expand Down Expand Up @@ -1060,13 +1065,13 @@ class CApp:
self._run_hook(hook_file.resolve(), app, target_env, version, compose_file, target_dir)

def _pull_images(self, target_dir):
printflush(end='')
if target_dir.is_dir() and (target_dir / 'docker-compose.yml').is_file():
printflush("Pulling images…")
run(['docker-compose', 'pull', '--ignore-pull-failures', '--quiet'], cwd=target_dir, text=True)

def _build_images(self, target_dir, quiet=True, use_cache=True):
printflush(end='')
if target_dir.is_dir() and (target_dir / 'docker-compose.yml').is_file():
printflush("Building images…")
cmd = ['docker-compose', 'build', '--pull']
if quiet:
cmd.append('--quiet')
Expand All @@ -1075,14 +1080,16 @@ class CApp:
run(cmd, cwd=target_dir, text=True)

def _load_images(self, image_files):
printflush(end='')
for image_file in image_files:
printflush(f"Loading image {image_file}…")
run(f'zcat "{str(image_file)}" | docker image load', shell=True, check=True, text=True)
run(['docker', 'image', 'prune', '-f'], text=True)
if image_files:
printflush("Cleaning dangling images…")
run(['docker', 'image', 'prune', '-f'], text=True)

def _clean_volumes(self, target_dir):
printflush(end='')
if target_dir.is_dir() and (target_dir / 'docker-compose.yml').is_file():
printflush("Cleaning volumes…")
run(['docker-compose', 'down', '-v'], cwd=target_dir, text=True)

def _copy_context(self, src_dir, dest_dir):
Expand Down Expand Up @@ -1117,7 +1124,8 @@ class CApp:
f.truncate()
f.write('\n'.join(deps))
f.write('\n')
run(['sudo', '/usr/local/bin/compose-dirs', 'update'], check=True, text=True)
printflush("Update systemd")
run(['sudo', '/usr/local/bin/compose-dirs', 'update', f'{app}/{target_env}'], check=True, text=True)
if target_dir.is_dir():
with open(target_dir / 'docker-compose.yml', encoding='utf8') as f:
dc = full_load(f)
Expand All @@ -1135,6 +1143,7 @@ class CApp:
if location_nginx_config_file.is_file():
location_nginx_config_file.unlink()
dc_down_args = '-v --rmi all' if args.all else '--rmi local'
printflush("Destroying application…")
run(f"docker-compose down {dc_down_args} 2>&1 | grep -v ^Network | grep -v '^Removing network'", shell=True, cwd=target_dir, text=True)
self._post_undeploy(app, target_env, version, target_dir / 'docker-compose.yml', target_dir)
rmtree(target_dir, ignore_errors=True)
Expand Down Expand Up @@ -1205,7 +1214,7 @@ class CApp:
self.check_right(Right.STATUS, app=app, env=target_env)
self.trace_action('status', vars(args))
svc = self._get_systemd_service_name(app, target_env)
execlp('systemctl', 'systemctl', 'status', '--no-pager', svc)
execlp('systemctl', 'systemctl', 'status', '--no-pager', '--lines=0', svc)

def action_logs(self, args):
app = args.app
Expand Down
22 changes: 11 additions & 11 deletions capp-installer-template
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/bin/bash
set -e
CAPP_VER=to_replace
COMPOSE_SYSTEMD_VER=1.3.0
COMPOSE_SYSTEMD_VER=v1.4.0
def_min_dca_ver=2
def_cont_mem='10G'
def_cont_proc=1000
usage() {
echo "$0 default_hostname default_email [min_dca_ver=$def_min_dca_ver] [container_max_memory_size=$def_cont_mem] [container_max_process=$def_cont_proc] [nohttps]" >&2
echo " container_max_memory_size should be expressed with M or G units" >&2
# shellcheck disable=SC2086
exit ${1:-1}
}
if [ "$1" = "-v" ] || [ "$1" = "--version" ]; then
Expand All @@ -17,6 +18,7 @@ fi
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
usage 0
fi
# shellcheck disable=SC2046
if [ $(id -u) -ne 0 ]; then
echo "Root required" >&2
exit 1
Expand Down Expand Up @@ -65,12 +67,12 @@ default_hostname=${dh}
EOF
mkdir -p /etc/capp/users /etc/capp/pubkeys /etc/capp/rights /etc/capp/hooks.d/{pre_deploy,post_deploy,pre_undeploy,post_undeploy}
tmpdir=$(mktemp -d)
cd $tmpdir
curl -Ls https://github.com/jrd/compose-systemd/archive/v${COMPOSE_SYSTEMD_VER}.tar.gz | tar xzf -
cd "$tmpdir"
curl -Ls https://github.com/jrd/compose-systemd/archive/${COMPOSE_SYSTEMD_VER}.tar.gz | tar xzf -
tail -n+$offset "$me" | base64 -d | tar xJf -
cp compose-systemd-${COMPOSE_SYSTEMD_VER}/compose-dirs.conf /etc/
cp compose-systemd-${COMPOSE_SYSTEMD_VER}/compose-dirs /usr/local/bin/
ln -sf $(which docker-compose) /usr/local/bin/dc
cp compose-systemd-*/compose-dirs.conf /etc/
cp compose-systemd-*/compose-dirs /usr/local/bin/
ln -sf "$(which docker-compose)" /usr/local/bin/dc
mkdir -p /var/docker-volumes/nginx-proxy/{vhost.d,certs} /etc/compose /home/deploy/dca
id -u compose >/dev/null 2>&1 || useradd --home-dir /etc/compose --no-create-home --user-group --shell /usr/sbin/nologin -c "Compose" -l compose
chown :compose /var/docker-volumes/nginx-proxy/vhost.d /etc/capp/users /etc/capp/pubkeys /etc/capp/rights
Expand Down Expand Up @@ -163,11 +165,9 @@ Cmnd_Alias CAPP_CMD = /usr/local/bin/capp
EOF
chmod u=r,g=r,o= /etc/sudoers.d/{compose,deploy}
set +e
cd /etc/compose/dca
docker-compose pull
cd /etc/compose/proxy
docker-compose pull
rm -rf $tmpdir
(cd /etc/compose/dca; docker-compose pull)
(cd /etc/compose/proxy/gen; ./get-nginx-tmpl; cd ..; docker-compose pull)
rm -rf "$tmpdir"
/usr/local/bin/compose-dirs install
/usr/local/bin/compose-dirs update
/usr/local/bin/compose-dirs start
Expand Down
2 changes: 1 addition & 1 deletion testindocker
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Then add temporary the IP to your `/etc/hosts` file:
IP test.capp myapp.test.capp anysubdomain.test.capp
EOF
trap 'docker rmi capptest' EXIT
trap 'docker kill capptest; docker rmi capptest' EXIT
docker run \
--name capptest \
--rm \
Expand All @@ -41,5 +42,4 @@ docker run \
echo "Wait for systemd to start"
sleep 1
docker exec -t capptest /root/capp-installer test.capp mail@example.com "$@"
trap 'docker kill capptest; docker rmi capptest' EXIT
docker logs -f capptest

0 comments on commit d8563cd

Please sign in to comment.