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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
#!/bin/sh
# Deploy langpack-o-matic charm
# Author: Martin Pitt <martin.pitt@ubuntu.com>
# Usage: charms/deploy.sh <credentials-dir>
# The credentials-dir is a directory with:
# - langpack.asc: Public GPG key of the Launchpad user that uploads langpacks
# to Ubuntu or the PPA
# - langpack.priv.asc: Corresponding private key
# - launchpad-export-settings.credentials: Launchpad token for a
# ~ubuntu-langpack team user that can manipulate
# https://translations.launchpad.net/ubuntu/xenial/+language-packs, i. e.
# request a full export
#
# For local deployment into LXD it's fine for these to be empty, as you most
# probably don't want to actually upload packages to Ubuntu:
# mkdir -p /tmp/creds
# touch /tmp/creds/{langpack.asc,langpack.priv.asc,launchpad-export-settings.credentials}
#
# For Ubuntu's production deployment, these files are on
# wendigo.canonical.com:~prod-ues-langpack/credentials/
set -e
CHARM_RELEASE=xenial
# settings for deployment in private Canonistack or juju-local
# settings for Canonical ProdStack 4.5
if [ "$OS_USERNAME" = "prod-ues-langpack" ]; then
LANDSCAPE=1
fi
CHARMDIR=$(dirname $(readlink -f $0))
#
# Juju 1 vs. 2 abstractions
#
if juju --version 2>&1 | grep -q '^2'; then
JUJU=juju
unset JUJU1
elif type juju-1 >/dev/null 2>&1; then
JUJU=juju-1
JUJU1=1
else
JUJU=juju
JUJU1=1
fi
if [ -n "$JUJU1" ]; then
JUJU_SET="$JUJU set"
else
JUJU_SET="$JUJU set-config"
fi
deploy_charm() {
local charm=$1
shift
if [ -n "$JUJU1" ]; then
$JUJU deploy --repository "$CHARMDIR" "$@" local:$CHARM_RELEASE/$charm $APPNAME
else
$JUJU deploy --series $CHARM_RELEASE "$@" "$CHARMDIR/$CHARM_RELEASE/$charm" $APPNAME
fi
}
#
# helper functions
#
wait_deployed() {
echo "waiting for $1 to get deployed..."
while ! $JUJU status --format=short $1 | egrep 'active|started|idle'; do
sleep 5
done
}
subordinate_charms() {
if [ -n "$LANDSCAPE" ]; then
echo 'deploying subordinate charms to $1'
$JUJU add-relation ksplice "$1"
$JUJU add-relation landscape-client "$1"
fi
}
CREDENTIALS_DIR="$1"
if [ -z "$1" ] || [ -n "$2" ]; then
echo "Usage: $0 <credentials dir>" >&2
exit 1
fi
if [ ! -d "$CREDENTIALS_DIR" ]; then
echo "ERROR: $CREDENTIALS_DIR does not exist" >&2
exit 1
fi
# create charm config
config_yaml=$(mktemp)
trap "rm $config_yaml" EXIT INT QUIT PIPE
#
# deploy subordinate charms for automatic machine management (only if
# $LANDSCAPE is set, i. e. for the production environment in ProdStack)
#
if [ -n "$LANDSCAPE" ]; then
[ -d "$CHARMDIR/$CHARM_RELEASE/landscape-client" ] || bzr checkout --lightweight lp:charms/trusty/landscape-client "$CHARMDIR/$CHARM_RELEASE/landscape-client"
[ -d "$CHARMDIR/$CHARM_RELEASE/ksplice" ] || { echo "Please check out ksplice charm to $CHARMDIR/$CHARM_RELEASE"; exit 1; }
#
# install/update basenode into charms
#
[ -d "$CHARMDIR/basenode" ] || { echo "Please check out basenode into $CHARMDIR"; exit 1; }
for charmdir in $CHARMDIR/$CHARM_RELEASE/*; do
# ignore subordinate charms
if grep -q 'subordinate:.*true' $charmdir/metadata.yaml; then
continue
fi
echo "Installing basenode into $charmdir"
rm -rf "$charmdir/exec.d/basenode"
mkdir -p "$charmdir/exec.d"
cp -r "$CHARMDIR/basenode" "$charmdir/exec.d"
done
if ! $JUJU status | grep -q ksplice; then
deploy_charm ksplice
$JUJU_SET ksplice accesskey=$(cat /srv/mojo/LOCAL/${MOJO_PROJECT}/canonical-is-ksplice.key)
$JUJU_SET ksplice source=""
fi
if ! $JUJU status | grep -q landscape-client; then
cat <<EOF >> "$config_yaml"
landscape-client:
url: https://landscape.is.canonical.com/message-system
ping-url: http://landscape.is.canonical.com/ping
account-name: standalone
registration-key: $(cat /srv/mojo/LOCAL/${MOJO_PROJECT}/canonical-is-landscape.key)
tags: juju-managed, devops-instance, devops-production
EOF
deploy_charm landscape-client --config $config_yaml
fi
fi
#
# deploy langpack-o-matic charm
#
if $JUJU status | grep -q langpack-o-matic; then
echo 'WARNING: langpack-o-matic already deployed, skipping' >&2
else
cat <<EOF >> "$config_yaml"
langpack-o-matic:
gpg-public: |
$(cat "$CREDENTIALS_DIR/langpack.asc" | sed 's/^/ /')
gpg-private: |
$(cat "$CREDENTIALS_DIR/langpack.priv.asc" | sed 's/^/ /')
lp-credentials: |
$(cat "$CREDENTIALS_DIR/launchpad-export-settings.credentials" | sed 's/^/ /')
EOF
deploy_charm langpack-o-matic --config "$config_yaml" --constraints 'root-disk=40G'
wait_deployed langpack-o-matic
subordinate_charms langpack-o-matic
fi
|