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

« back to all changes in this revision

Viewing changes to charms/deploy.sh

  • Committer: Sebastien Bacher
  • Author(s): Cristian Gonzalez
  • Date: 2021-11-04 10:05:59 UTC
  • mfrom: (596.1.1 langpack-o-matic)
  • Revision ID: seb128@ubuntu.com-20211104100559-9nlulabfk5494cuu
Updating the crontab to include Jammy

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