~ubuntu-langpack/langpack-o-matic/main

« back to all changes in this revision

Viewing changes to charms/deploy.sh

  • Committer: Martin Pitt
  • Date: 2016-09-13 14:17:21 UTC
  • Revision ID: martin.pitt@canonical.com-20160913141721-6i5hmy8zmyet6qtt
Update deployment charm and script

With the charm and in the DevOps environment, building packages can now happen
directly on the instance, so drop schroot from cron.* and documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
# Deploy langpack-o-matic charm
 
3
# Author: Martin Pitt <martin.pitt@ubuntu.com>
 
4
 
 
5
set -e
 
6
 
 
7
CHARM_RELEASE=xenial
 
8
 
 
9
# settings for deployment in private Canonistack or juju-local
 
10
 
 
11
# settings for Canonical ProdStack 4.5
 
12
if [ "$OS_USERNAME" = "prod-ues-langpack" ]; then
 
13
    LANDSCAPE=1
 
14
fi
 
15
 
 
16
CHARMDIR=$(dirname $(readlink -f $0))
 
17
 
 
18
#
 
19
# Juju 1 vs. 2 abstractions
 
20
#
 
21
 
 
22
if juju --version 2>&1 | grep -q '^2'; then
 
23
    JUJU=juju
 
24
    unset JUJU1
 
25
elif type juju-1 >/dev/null 2>&1; then
 
26
    JUJU=juju-1
 
27
    JUJU1=1
 
28
else
 
29
    JUJU=juju
 
30
    JUJU1=1
 
31
fi
 
32
 
 
33
if [ -n "$JUJU1" ]; then
 
34
    JUJU_SET="$JUJU set"
 
35
else
 
36
    JUJU_SET="$JUJU set-config"
 
37
fi
 
38
 
 
39
deploy_charm() {
 
40
    local charm=$1
 
41
    shift
 
42
    if [ -n "$JUJU1" ]; then
 
43
        $JUJU deploy --repository "$CHARMDIR" "$@" local:$CHARM_RELEASE/$charm $APPNAME
 
44
    else
 
45
        $JUJU deploy --series $CHARM_RELEASE "$@" "$CHARMDIR/$CHARM_RELEASE/$charm" $APPNAME
 
46
    fi
 
47
}
 
48
 
 
49
#
 
50
# helper functions
 
51
#
 
52
 
 
53
wait_deployed() {
 
54
    echo "waiting for $1 to get deployed..."
 
55
    while ! $JUJU status --format=short $1 | egrep 'active|started|idle'; do
 
56
        sleep 5
 
57
    done
 
58
}
 
59
 
 
60
subordinate_charms() {
 
61
    if [ -n "$LANDSCAPE" ]; then
 
62
        echo 'deploying subordinate charms to $1'
 
63
        $JUJU add-relation ksplice "$1"
 
64
        $JUJU add-relation landscape-client "$1"
 
65
    fi
 
66
}
 
67
 
 
68
CREDENTIALS_DIR="$1"
 
69
 
 
70
if [ -z "$1" ] || [ -n "$2" ]; then
 
71
   echo "Usage: $0 <credentials dir>" >&2
 
72
   exit 1
 
73
fi
 
74
 
 
75
if [ ! -d "$CREDENTIALS_DIR" ]; then
 
76
   echo "ERROR: $CREDENTIALS_DIR does not exist" >&2
 
77
   exit 1
 
78
fi
 
79
 
 
80
# create charm config
 
81
 
 
82
config_yaml=$(mktemp)
 
83
trap "rm $config_yaml" EXIT INT QUIT PIPE
 
84
 
 
85
#
 
86
# deploy subordinate charms for automatic machine management (only if
 
87
# $LANDSCAPE is set, i. e. for the production environment in ProdStack)
 
88
#
 
89
 
 
90
if [ -n "$LANDSCAPE" ]; then
 
91
    [ -d "$CHARMDIR/$CHARM_RELEASE/landscape-client" ] || bzr checkout --lightweight lp:charms/trusty/landscape-client "$CHARMDIR/$CHARM_RELEASE/landscape-client"
 
92
    [ -d "$CHARMDIR/$CHARM_RELEASE/ksplice" ] || { echo "Please check out ksplice charm to $CHARMDIR/$CHARM_RELEASE"; exit 1; }
 
93
 
 
94
    #
 
95
    # install/update basenode into charms
 
96
    #
 
97
    [ -d "$CHARMDIR/basenode" ] || { echo "Please check out basenode into $CHARMDIR"; exit 1; }
 
98
    for charmdir in $CHARMDIR/$CHARM_RELEASE/*; do
 
99
        # ignore subordinate charms
 
100
        if grep -q 'subordinate:.*true' $charmdir/metadata.yaml; then
 
101
            continue
 
102
        fi
 
103
        echo "Installing basenode into $charmdir"
 
104
        rm -rf "$charmdir/exec.d/basenode"
 
105
        mkdir -p "$charmdir/exec.d"
 
106
        cp -r "$CHARMDIR/basenode" "$charmdir/exec.d"
 
107
    done
 
108
 
 
109
    if ! $JUJU status | grep -q ksplice; then
 
110
        deploy_charm ksplice
 
111
        $JUJU_SET ksplice accesskey=$(cat /srv/mojo/LOCAL/${MOJO_PROJECT}/canonical-is-ksplice.key)
 
112
        $JUJU_SET ksplice source=""
 
113
    fi
 
114
    if ! $JUJU status | grep -q landscape-client; then
 
115
        cat <<EOF >> "$config_yaml"
 
116
landscape-client:
 
117
  url: https://landscape.is.canonical.com/message-system
 
118
  ping-url: http://landscape.is.canonical.com/ping
 
119
  account-name: standalone
 
120
  registration-key: $(cat /srv/mojo/LOCAL/${MOJO_PROJECT}/canonical-is-landscape.key)
 
121
  tags: juju-managed, devops-instance, devops-production
 
122
EOF
 
123
        deploy_charm landscape-client --config $config_yaml
 
124
    fi
 
125
fi
 
126
 
 
127
#
 
128
# deploy langpack-o-matic  charm
 
129
#
 
130
 
 
131
if $JUJU status | grep -q langpack-o-matic; then
 
132
    echo 'WARNING: langpack-o-matic already deployed, skipping' >&2
 
133
else
 
134
    cat <<EOF >> "$config_yaml"
 
135
langpack-o-matic:
 
136
  gpg-public: |
 
137
$(cat "$CREDENTIALS_DIR/langpack.asc" | sed 's/^/    /')
 
138
  gpg-private: |
 
139
$(cat "$CREDENTIALS_DIR/langpack.priv.asc" | sed 's/^/    /')
 
140
  lp-credentials: |
 
141
$(cat "$CREDENTIALS_DIR/launchpad-export-settings.credentials" | sed 's/^/    /')
 
142
EOF
 
143
 
 
144
    deploy_charm langpack-o-matic --config "$config_yaml" --constraints 'root-disk=40G'
 
145
    wait_deployed langpack-o-matic
 
146
    subordinate_charms langpack-o-matic
 
147
fi