blob: 8363f60b44bfb5eccb700d8e347f1e2a7b10e6c2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#!/bin/bash -e
# cyche-build <name> <file> <hash> [--self]
#
# (Re)build and deploy the service <name> using the docker-compose configuration
# in <file> (usually, docker-compose.yml).
#
# In the typical case, this is a straightforward process and `docker compose up`
# can properly recreate/start containers for the guest service. However, when
# rebuilding cychedelic itself, --self must be given, to instruct this file to
# modify its behavior to support self-upgrade of the running compose service.
#
# In `--self` mode, we prepare and start the cychedelic service under an
# alternate project name each time, before taking down the existing (old)
# services. This is necessary because running `docker compose up` terminates
# old containers before starting new one. Termination of the ACID service
# interrupts the `compose up` process before it can start the replacements.
# Normally, `docker compose down` is then not needed.
#
# We take <hash> (from cyche-source) so we may commit it to the cache iff the
# deployment is successful.
#
# This file exits early on any failure (non-zero). On a successful run in
# `--self` mode, this file does not exit (we are killed by `compose down`).
cd "/services/$1"
if [ "$4" == "--self" ]; then
prev=$(cat '.git/previous_slug')
[ -n "$prev" ] && prev="--project-name $prev"
slug=$(echo -n "$1-"; tr -dc a-z </dev/urandom | head -c 12)
next="--project-name $slug"
fi
docker compose $next --file "$2" pull
docker compose $next --file "$2" build \
--force-rm \
--no-cache \
--pull
docker compose $next --file "$2" up \
--detach \
--remove-orphans \
--force-recreate
echo "$3" >.git/previous_hash
if [ "$4" == "--self" ]; then
echo "$slug" >.git/previous_slug
docker compose --file "$2" down
docker compose $prev --file "$2" down
fi
|