~ce-orange-squad/juju-core/ci-cd-scripts

« back to all changes in this revision

Viewing changes to scripts/release-public-tools.bash

  • Committer: Curtis Hovey
  • Date: 2013-10-16 18:45:50 UTC
  • Revision ID: curtis@canonical.com-20131016184550-h017k9uczews6v91
Split release-public-tools.sh into a script to assemble the tree for signing/publication and a  script that publishes to all certified public clouds. Moved the scripts up to scripts because they do not need directories.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env bash
2
2
# Release public tools.
3
3
#
4
 
# Retrieve the published juju-core debs for a specific release.
5
 
# Extract the jujud from the packages.
6
 
# Generate the streams data.
7
4
# Publish to Canonistack, HP, AWS, and Azure.
8
 
#
9
5
# This script requires that the user has credentials to upload the tools
10
6
# to Canonistack, HP Cloud, AWS, and Azure
11
7
 
13
9
 
14
10
 
15
11
usage() {
16
 
        echo usage: $0 RELEASE destination-directory
 
12
        echo "usage: $0 PURPOSE DIST_DIRECTORY"
 
13
        echo "  PURPOSE: 'RELEASE' or  'TESTING'"
 
14
        echo "    RELEASE installs tools/ at the top of juju-dist/tools."
 
15
        echo "    TESTING installs tools/ at juju-dist/testing/tools."
 
16
        echo "  DIST_DIRECTORY: The directory to the assembled tools."
 
17
        echo "    This is the juju-dist dir created by assemble-public-tools.bash."
17
18
        exit 1
18
19
}
19
20
 
20
21
 
21
22
check_deps() {
 
23
    echo "Phase 0: Checking requirements."
22
24
    has_deps=1
23
 
    which lftp || has_deps=0
24
25
    which swift || has_deps=0
25
26
    which s3cmd || has_deps=0
26
27
    test -f ~/.juju/canonistacktoolsrc || has_deps=0
28
29
    test -f ~/.juju/awstoolsrc || has_deps=0
29
30
    test -f ~/.juju/azuretoolsrc || has_deps=0
30
31
    if [[ $has_deps == 0 ]]; then
31
 
        echo "Install lftp, python-swiftclient, and s3cmd"
 
32
        echo "Install python-swiftclient, and s3cmd"
32
33
        echo "Your ~/.juju dir must contain rc files to publish:"
33
34
        echo "  canonistacktoolsrc, hptoolsrc, awstoolsrc, azuretoolsrc"
34
35
        exit 2
35
36
    fi
36
 
}
37
 
 
38
 
 
39
 
build_tool_tree() {
40
 
    if [[ ! -d $DEST_DEBS ]]; then
41
 
        mkdir $DEST_DEBS
42
 
    fi
43
 
    if [[ ! -d $DEST_TOOLS ]]; then
44
 
        mkdir -p $DEST_TOOLS
45
 
    fi
46
 
    if [[ ! -d $DEST_DIST ]]; then
47
 
        mkdir $DEST_DIST
48
 
    fi
49
 
}
50
 
 
51
 
 
52
 
retrieve_released_tools() {
53
 
    # Retrieve previously released tools to ensure the metadata continues
54
 
    # to work for historic releases.
55
 
    source ~/.juju/awstoolsrc
56
 
    s3cmd sync s3://juju-dist/tools/releases/ $DEST_TOOLS
57
 
}
58
 
 
59
 
 
60
 
retrieve_packages() {
61
 
    # Retrieve the $RELEASE packages that contain jujud.
62
 
    cd $DEST_DEBS
63
 
    for archive in $UBUNTU_ARCH $STABLE_ARCH $DEVEL_ARCH; do
64
 
        echo "checking $archive for $RELEASE."
65
 
        lftp -c mirror -I "juju-core_${RELEASE}*.deb" $archive;
66
 
    done
67
 
    mv juju-core/*deb ./
68
 
    rm -r juju-core
69
 
}
70
 
 
71
 
 
72
 
get_version() {
73
 
    # Defines $version. $version can be different than $RELEASE used to
74
 
    # match the packages in the archives.
75
 
    control_version=$1
76
 
    version=$(echo "$control_version" |
77
 
        sed -n 's/^\([0-9]\+\).\([0-9]\+\).\([0-9]\+\)-[0-9].*/\1.\2.\3/p')
78
 
    if [ "${version}" == "" ] ; then
79
 
            echo "Invalid version: $control_version"
80
 
            exit 3
81
 
    fi
82
 
}
83
 
 
84
 
 
85
 
get_series() {
86
 
    # Defines $series.
87
 
    control_version=$1
88
 
    pkg_series=$(echo "$control_version" |
89
 
        sed -e 's/~juju.//;' \
90
 
            -e 's/^.*~\(ubuntu[0-9][0-9]\.[0-9][0-9]\|[a-z]\+\).*/\1/')
91
 
    series=${version_names["$pkg_series"]}
92
 
    case "${series}" in
93
 
            "precise" | "quantal" | "raring" | "saucy" )
94
 
                    ;;
95
 
            *)
96
 
                    echo "Invalid series: $control_version"
97
 
                    exit 3
98
 
                    ;;
99
 
    esac
100
 
}
101
 
 
102
 
 
103
 
get_arch() {
104
 
    # Defines $arch.
105
 
    control_file=$1
106
 
    arch=$(sed -n 's/^Architecture: \([a-z]\+\)/\1/p' $control_file)
107
 
    case "${arch}" in
108
 
            "amd64" | "i386" | "armel" | "armhf" )
109
 
                    ;;
110
 
            *)
111
 
                    echo "Invalid arch: $arch"
112
 
                    exit 3
113
 
                    ;;
114
 
    esac
115
 
}
116
 
 
117
 
 
118
 
archive_tools() {
119
 
    # Builds the jujud tgz for each series and arch.
120
 
    cd $DESTINATION
121
 
    WORK=$(mktemp -d)
122
 
    mkdir ${WORK}/juju
123
 
    packages=$(ls ${DEST_DEBS}/*.deb)
124
 
    for package in $packages; do
125
 
        echo "Extracting jujud from ${package}."
126
 
        dpkg-deb -e $package ${WORK}/juju
127
 
        control_file="${WORK}/juju/control"
128
 
        control_version=$(sed -n 's/^Version: \(.*\)/\1/p' $control_file)
129
 
        get_version $control_version
130
 
        get_series $control_version
131
 
        get_arch $control_file
132
 
        tool="${DEST_TOOLS}/juju-${version}-${series}-${arch}.tgz"
133
 
        echo "Creating $tool."
134
 
        dpkg-deb -x $package ${WORK}/juju
135
 
        bin_dir="${WORK}/juju/usr/bin"
136
 
        lib_dir="${WORK}/juju/usr/lib/juju-${version}/bin"
137
 
        if [[ -f "${bin_dir}/jujud" ]]; then
138
 
            change_dir=$bin_dir
139
 
        elif [[ -f "${lib_dir}/jujud" ]]; then
140
 
            change_dir=$lib_dir
141
 
        else
142
 
            echo "jujud is not in /usr/bin or /usr/lib"
143
 
            exit 4
144
 
        fi
145
 
        tar cvfz $tool -C $change_dir jujud
146
 
        echo "Created ${tool}."
147
 
        rm -r ${WORK}/juju/*
148
 
    done
149
 
}
150
 
 
151
 
 
152
 
generate_streams() {
153
 
    # Create the streams metadata and organised the tree for later publication.
154
 
    cd $DESTINATION
155
 
    ${GOPATH}/bin/juju sync-tools --all --dev \
156
 
        --source=${DESTINATION} --destination=${DEST_DIST}
157
 
    # Support old tools location so that deployments can upgrade to new tools.
158
 
    cp ${DEST_DIST}/tools/releases/*tgz ${DEST_DIST}/tools
159
 
    echo "The tools are in ${DEST_DIST}."
 
37
    juju_version=$(juju --version)
 
38
    echo "Using installed juju: $juju_version" 
160
39
}
161
40
 
162
41
 
163
42
publish_to_canonistack() {
164
 
    echo "Phase 6.1: Publish to canonistack."
165
 
    cd $DESTINATION
 
43
    echo "Phase 1: Publish to canonistack."
166
44
    source ~/.juju/canonistacktoolsrc
167
 
    ${GOPATH}/bin/juju --show-log \
168
 
        sync-tools -e public-tools-canonistack --dev --source=${DEST_DIST}
 
45
    juju --show-log \
 
46
        sync-tools -e public-tools-canonistack --dev --source=${JUJU_DIST}
169
47
    # This needed to allow old deployments upgrade.
170
 
    cd ${DEST_DIST}
171
 
    swift upload juju-dist tools/*.tgz
 
48
    # XXX sinzui 2013-10-09: Ian fixed this.
 
49
    #cd ${JUJU_DIST}
 
50
    #swift upload juju-dist tools/*.tgz
 
51
}
 
52
 
 
53
 
 
54
testing_to_canonistack() {
 
55
    echo "Phase 1: Testing to canonistack."
 
56
    source ~/.juju/canonistacktoolsrc
 
57
    cd $JUJU_DIST/tools/releases/
 
58
    swift upload juju-dist/testing/tools/releases *.tgz
 
59
    cd $JUJU_DIST/tools/streams/v1
 
60
    swift upload juju-dist/testing/tools/streams/v1 *.json
172
61
}
173
62
 
174
63
 
175
64
publish_to_hp() {
176
 
    echo "Phase 6.2: Publish to HP Cloud."
177
 
    cd $DESTINATION
 
65
    echo "Phase 2: Publish to HP Cloud."
178
66
    source ~/.juju/hptoolsrc
179
 
    ${GOPATH}/bin/juju --show-log \
180
 
        sync-tools -e public-tools-hp --dev --source=${DEST_DIST}
 
67
    juju --show-log \
 
68
        sync-tools -e public-tools-hp --dev --source=${JUJU_DIST}
181
69
    # Support old tools location so that deployments can upgrade to new tools.
182
 
    cd ${DEST_DIST}
183
 
    swift upload juju-dist tools/*.tgz
 
70
    # XXX sinzui 2013-10-09: Ian fixed this.
 
71
    #cd ${JUJU_DIST}
 
72
    #swift upload juju-dist tools/*.tgz
 
73
}
 
74
 
 
75
 
 
76
testing_to_hp() {
 
77
    # sync-tools cannot place the tools in a testing location, so swift is
 
78
    # used.
 
79
    echo "Phase 2: Testing to HP Cloud."
 
80
    source ~/.juju/hptoolsrc
 
81
    cd $JUJU_DIST/tools/releases/
 
82
    swift upload juju-dist/testing/tools/releases *.tgz
 
83
    cd $JUJU_DIST/tools/streams/v1
 
84
    swift upload juju-dist/testing/tools/streams/v1 *.json
184
85
}
185
86
 
186
87
 
187
88
publish_to_aws() {
188
 
    echo "Phase 6.3: Publish to AWS."
189
 
    cd $DESTINATION
190
 
    source ~/.juju/awstoolsrc
191
 
    s3cmd sync ${DEST_DIST}/tools s3://juju-dist/
 
89
    echo "Phase 3: Publish to AWS."
 
90
    source ~/.juju/awstoolsrc
 
91
    s3cmd sync ${JUJU_DIST}/tools s3://juju-dist/
 
92
}
 
93
 
 
94
 
 
95
testing_to_aws() {
 
96
    # this is the same as the publishing command except that the
 
97
    # destination is juju-dist/testing/
 
98
    echo "Phase 3: Testing to AWS."
 
99
    source ~/.juju/awstoolsrc
 
100
    s3cmd sync ${JUJU_DIST}/tools s3://juju-dist/testing/
192
101
}
193
102
 
194
103
 
195
104
publish_to_azure() {
196
105
    # This command sets the tool name from the local path! The local path for
197
106
    # each public file MUST match the destination path :(.
198
 
    echo "Phase 6.4: Publish to Azure."
199
 
    cd $DESTINATION
 
107
    echo "Phase 4: Publish to Azure."
200
108
    source ~/.juju/azuretoolsrc
201
 
    cd ${DEST_DIST}
 
109
    cd ${JUJU_DIST}
202
110
    public_files=$(find tools -name *.tgz -o -name *.json)
203
111
    for public_file in $public_files; do
204
112
        echo "Uploading $public_file to Azure West US."
212
120
}
213
121
 
214
122
 
215
 
# These are the archives that are search for matching releases.
216
 
UBUNTU_ARCH="http://archive.ubuntu.com/ubuntu/pool/universe/j/juju-core/"
217
 
STABLE_ARCH="http://ppa.launchpad.net/juju/stable/ubuntu/pool/main/j/juju-core/"
218
 
DEVEL_ARCH="http://ppa.launchpad.net/juju/devel/ubuntu/pool/main/j/juju-core/"
 
123
testing_to_azure() {
 
124
    # This command is like the publish command expcept tht -container is
 
125
    # different.
 
126
    echo "Phase 4: Testing to Azure."
 
127
    source ~/.juju/azuretoolsrc
 
128
    cd ${JUJU_DIST}
 
129
    public_files=$(find tools -name *.tgz -o -name *.json)
 
130
    for public_file in $public_files; do
 
131
        echo "Uploading $public_file to Azure West US."
 
132
        go run $GOPATH/src/launchpad.net/gwacl/example/storage/run.go \
 
133
            -account=${AZURE_ACCOUNT} -container=juju-tools/testing \
 
134
            -location="West US" \
 
135
            -key=${AZURE_JUJU_TOOLS_KEY} \
 
136
            -filename=$public_file \
 
137
            addblock
 
138
    done
 
139
}
219
140
 
220
 
# Series names found in package versions need to be normalised.
221
 
declare -A version_names
222
 
version_names+=(["ubuntu12.04"]="precise")
223
 
version_names+=(["ubuntu12.10"]="quantal")
224
 
version_names+=(["ubuntu13.04"]="raring")
225
 
version_names+=(["ubuntu13.10"]="saucy")
226
 
version_names+=(["precise"]="precise")
227
 
version_names+=(["quantal"]="quantal")
228
 
version_names+=(["raring"]="raring")
229
 
version_names+=(["saucy"]="saucy")
230
141
 
231
142
test $# -eq 2 || usage
232
143
 
233
 
RELEASE=$1
234
 
DESTINATION=$(cd $2; pwd)
235
 
DEST_DEBS="${DESTINATION}/debs"
236
 
DEST_TOOLS="${DESTINATION}/tools/releases"
237
 
DEST_DIST="${DESTINATION}/juju-dist"
238
 
 
239
 
echo "Phase 0: Checking requirements."
 
144
PURPOSE=$1
 
145
if [[ $PURPOSE != "RELEASE" && $PURPOSE != "TESTING" ]]; then
 
146
    usage
 
147
fi
 
148
 
 
149
JUJU_DIST=$(cd $2; pwd)
 
150
if [[ ! -d $JUJU_DIST/tools/releases && ! -d $JUJU_DIST/tools/streams ]]; then
 
151
    usage
 
152
fi
 
153
 
240
154
check_deps
241
 
 
242
 
echo "Phase 1: Building collection and republication tree."
243
 
build_tool_tree
244
 
 
245
 
echo "Phase 2: Retrieving released tools."
246
 
retrieve_released_tools
247
 
 
248
 
echo "Phase 3: Retrieving juju-core packages from archives"
249
 
retrieve_packages
250
 
 
251
 
echo "Phase 4: Extracting jujud from packages and archiving tools."
252
 
archive_tools
253
 
 
254
 
echo "Phase 5: Generating streams data."
255
 
generate_streams
256
 
 
257
 
echo "Phase 6: Publishing tools."
258
 
publish_to_canonistack
259
 
publish_to_hp
260
 
publish_to_aws
261
 
publish_to_azure
 
155
if [[ $PURPOSE == "RELEASE" ]]; then
 
156
    publish_to_canonistack
 
157
    publish_to_hp
 
158
    publish_to_aws
 
159
    publish_to_azure
 
160
else
 
161
    testing_to_canonistack
 
162
    testing_to_hp
 
163
    testing_to_aws
 
164
    testing_to_azure
 
165
fi