~mthaddon/charms/trusty/content-fetcher/trunk

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
Juju charm for deploying content to Apache
==========================================

## How to deploy the charm

Use this charm as a subordinate to a charm like apache2. It will download the
content and install it on the server.

This charm can be joined to a remote-content relation if the superordinate
needs to take action after content is updated. If no action is needed it can
be joined to the generic juju-info relation. If remote-content is used then
the superordinate can set the dest\_dir

## Supported sources

Currently swift, bzr+ssh, file, lp, http, https and ftp are supported. http,
https and ftp access can either be anonymous or via a username and
password. bzr+ssh requires a private key to be shipped with the charm, this
should be a private key which is used for nothing else. swift requires the
full gamut of authentication information.

dest\_dir is the location to expand the archive into. In the case of apache
this would most likely be the document root specified in the vhost

keep\_dir\_count is the number of backups of the deployed content to keep.
Before each deploy the current content is archived before the new content is
pulled in.

deploy\_trigger is used to trigger a deploy of new content. To trigger the
charm to pickup new content increment this. Note that setting any other
parameter will not trigger a deployment.

Examples (not exhaustive:)
http, https and ftp:
--------------------
    archive_location=http://192.168.0.1/content.tar
    archive_location=https://user:pass@192.168.0.1:4343/content.tar
    archive_location=ftp://192.168.0.1/content.tar
    archive_location=ftp://user:pass@192.168.0.1:912/content.tar

swift:
------
    username=$OS_USERNAME
    secret=$OS_PASSWORD
    archive_location=content.tar
    auth_url=$OS_AUTH_URL
    tenant_name=$OS_TENANT_NAME
    container_name=my_container

bzr+ssh:
--------
 Copy private key to ssh-key/content\_fetcher\_rsa within the charm


    archive_location=bzr+ssh://%s@%s/%s
    ssh_host_key=<host key of server with content>

file:
----- 
    archive_location=file:///srv/content.tar

lp:
---
    archive_location=lp:mybranch

High level example:
===================
Below is how the charms relate to one another

    juju deploy apache2
    juju deploy content-fetcher archive_location=http://192.168.0.1/content.tar
    juju add-relation apache2:juju-info content-fetcher:general-info

How to upgrade website content:
=============================== 
    juju set content-fetcher deploy_trigger=<current_value + 1>

Testing the Charm
=================

Get a local copy of the charm as it contains the test server

    bzr branch lp:charms/precise/content-fetcher

1) Deploy Charms
----------------

    juju bootstrap
    juju deploy apache2
    juju set apache2 "servername=mywebsite.mydomain"
    juju deploy local:content-fetcher
    juju set content-fetcher "dest_dir=/srv/mywebsite.mydomain/mywebsite"
    juju add-relation apache2:juju-info content-fetcher:general-info
    juju set apache2 "vhost_http_template=$(base64 testserver/apache-vhost.txt)"

2) Start a test server.
-----------------------

test-content-fetcher.py can be used to test all src types except lp. In the
cases of http, https and ftp a server will be started for content-fetcher to 
talk to, optionally --anon can be passed to turn off auth. For swift the
content is uploaded into a new container. For bzr+ssh and file the archive
is created. For all types instructions are then provided on how to setup the
test and what juju params to set e.g.

    ./tests/testserver/test-content-fetcher.py https    

This will start an https server and return instructions on what juju
commands to run to instruct content-fetcher to grab its content from
a basic auth protected https location. e.g.

    juju set content-fetcher archive_location=https://bob:bob@192.168.0.1:4343/content.tar
    juju set content-fetcher deploy_trigger=$(juju get content-fetcher | grep -A6 deploy_trigger | awk '/value:/ {print $2 + 1}')

This can be tested with:

    juju ssh content-fetcher/0 "curl http://127.0.0.1/"

This should return something like:
    
    <html><body><h1>Website collected from https auth at 2014/03/20 18:07:11</h1></body></html>

## Restrictions

## Todo