|
| 1 | +Chef Server |
| 2 | +=========== |
| 3 | + |
| 4 | +This image runs |
| 5 | +[Chef Server core](https://downloads.getchef.com/chef-server/). The |
| 6 | +latest version is published as `3ofcoins/chef-server`. Git repository |
| 7 | +containing the Dockerfile lives at |
| 8 | +https://github.com/3ofcoins/docker-images/tree/master/public/chef-server |
| 9 | + |
| 10 | +Environment Variables |
| 11 | +--------------------- |
| 12 | + |
| 13 | + - `PUBLIC_URL` - should be configured to a full public URL of the |
| 14 | + endpoint (e.g. `https://chef.example.com`) |
| 15 | + - `OC_AD_ADMINISTRATORS` - if set, it should be a comma-separated |
| 16 | + list of users that will be allowed to add oc_id applications |
| 17 | + |
| 18 | +Ports |
| 19 | +----- |
| 20 | + |
| 21 | +Ports 80 (HTTP) and 443 (HTTPS) are exposed. |
| 22 | + |
| 23 | +Volumes |
| 24 | +------- |
| 25 | + |
| 26 | +`/var/opt/opscode` directory, that holds all Chef server data, is a |
| 27 | +volume. Directories `/var/log/opscode` and `/etc/opscode` are linked |
| 28 | +there as, respectively, `log` and `etc`. |
| 29 | + |
| 30 | +If there is a file `etc/chef-server-local.rb` in this volume, it will |
| 31 | +be read at the end of `chef-server.rb` and it can be used to customize |
| 32 | +Chef Server's settings. |
| 33 | + |
| 34 | +Signals |
| 35 | +------- |
| 36 | + |
| 37 | + - `docker kill -s HUP $CONTAINER_ID` will run `chef-server-ctl reconfigure` |
| 38 | + - `docker kill -s USR1 $CONTAINER_ID` will run `chef-server-ctl status` |
| 39 | + |
| 40 | +Usage |
| 41 | +----- |
| 42 | + |
| 43 | +### Prerequisites and first start |
| 44 | + |
| 45 | +The `kernel.shmmax` and `kernel.shmall` sysctl values should be set to |
| 46 | +a high value on the host. You may also run Chef server as a privileged |
| 47 | +container to let it autoconfigure -- but the setting will propagate to |
| 48 | +host anyway, and it would be the only reason for making the container |
| 49 | +privileged, so it is better to avoid it. |
| 50 | + |
| 51 | +First start will automatically run `chef-server-ctl |
| 52 | +reconfigure`. Subsequent starts will not run `reconfigure`, unless |
| 53 | +file `/var/opt/opscode/bootstrapped` has been deleted. You can run |
| 54 | +`reconfigure` (e.g. after editing `etc/chef-server.rb`) using |
| 55 | +`docker-enter` or by sending SIGHUP to the container: `docker kill |
| 56 | +-HUP $CONTAINER_ID`. |
| 57 | + |
| 58 | +### Maintenance commands |
| 59 | + |
| 60 | +Chef Server's design makes it impossible to wrap it cleanly in |
| 61 | +a container - it will always be necessary to run custom |
| 62 | +commands. While some of the management commands may work with linked |
| 63 | +containers with varying amount of ugly hacks, it is simpler to have |
| 64 | +one way of interacting with the software that is closest to |
| 65 | +interacting with a Chef Server installed directly on host (and thus |
| 66 | +closest to supported usage). |
| 67 | + |
| 68 | +You will need `nsenter` utility and |
| 69 | +[`docker-enter`](https://github.com/jpetazzo/nsenter) script by |
| 70 | +[Jérôme Petazzoni](https://github.com/jpetazzo) on your Docker |
| 71 | +host. The easiest way to install it is to run the installer Docker |
| 72 | +image: |
| 73 | + |
| 74 | + docker run --rm -v /usr/local/bin:/target jpetazzo/nsenter |
| 75 | + |
| 76 | +Then, you can use the `docker-enter` script to run `chef-server-ctl` |
| 77 | +commands (note that the command is `ctl`, not `chef-server-ctl`; `ctl` |
| 78 | +is a wrapper that sets missing environment variables, lack of which |
| 79 | +would confuse `chef-server-ctl`): |
| 80 | + |
| 81 | + docker-enter $CONTAINER_ID chef-server-ctl status |
| 82 | + docker-enter $CONTAINER_ID chef-server-ctl user-add … |
| 83 | + docker-enter $CONTAINER_ID chef-server-ctl org-add … |
| 84 | + docker-enter $CONTAINER_ID chef-server-ctl … |
| 85 | + |
| 86 | +### Publishing the endpoint |
| 87 | + |
| 88 | +This container is not supposed to listen on a publically available |
| 89 | +port. It is very strongly recommended to use a proxy server, such as |
| 90 | +[nginx](http://nginx.org/), as a public endpoint. |
| 91 | + |
| 92 | +Unfortunately, Chef's logic for figuring out the absolute URL of |
| 93 | +various pieces (oc_id, bookshelf, erchef API, etc) for links and |
| 94 | +redirects is twisted and fragile. There are `chef-server.rb` settings, |
| 95 | +but some pieces insist on using the `Host:` header of the request, and |
| 96 | +it doesn't seem possible to use plain HTTP endpoint and have the Chef |
| 97 | +Server generate HTTPS redirects everywhere. |
| 98 | + |
| 99 | +The main setting you need to configure is `PUBLIC_URL` environment |
| 100 | +variable. It needs to contain full public URL, as seen by `knife` and |
| 101 | +`chef-client` (e.g. `PUBLIC_URL=https://chef-api.example.com/`). |
| 102 | + |
| 103 | +Then, you need to make sure that the proxy passes proper `Host:` |
| 104 | +header to the Chef Server, and talks with the Chef Server on |
| 105 | +the same protocol that the final endpoint will use (i.e. proxy that |
| 106 | +listens on HTTPS would need to use Chef Server's self-signed HTTPS |
| 107 | +endpoint; proxy that listens on plain HTTP would need to talk to HTTP |
| 108 | +endpoint). |
| 109 | + |
| 110 | +If you prefer to avoid overhead of encrypting the connection between |
| 111 | +proxy and the Chef Server, it *should* be sufficient to rewrite the |
| 112 | +`Location:` headers (`proxy_redirect` in nginx, `ProxyPassReverse` in |
| 113 | +Apache). It works for me, but I can't guarantee you won't bump into |
| 114 | +a wrong URL generated by the server. |
| 115 | + |
| 116 | +A sample nginx configuration looks like this: |
| 117 | + |
| 118 | + server { |
| 119 | + listen 443 ssl; |
| 120 | + server_name chef.example.com; |
| 121 | + ssl_certificate /path/to/chef.example.com.pem; |
| 122 | + ssl_certificate_key /path/to/chef.example.com.key; |
| 123 | + client_max_body_size 4G; |
| 124 | + location / { |
| 125 | + proxy_pass http://127.0.0.1:5000; |
| 126 | + proxy_set_header Host $host; |
| 127 | + proxy_set_header X-Forwarded-Proto https; |
| 128 | + proxy_redirect default; |
| 129 | + proxy_redirect http://chef.example.com https://chef.example.com; |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | +### Backup and restore |
| 134 | + |
| 135 | +1. `docker stop chef-server` |
| 136 | +2. Archive `/var/opt/opscode` volume (delete the `bootstrapped` file |
| 137 | + from the archive to force `chef-server-ctl reconfigure` run on the |
| 138 | + new container) |
| 139 | +3. `docker start chef-server` |
| 140 | + |
| 141 | +Same thing works for upgrades: just reuse container, remembering to |
| 142 | +remove the `bootstrapped` file. You may also need to remove the |
| 143 | +symlinks in `/var/opt/opscode/service` and/or run `chef-server-ctl |
| 144 | +upgrade` via `docker-enter`. |
| 145 | + |
| 146 | +### Chef Plugins |
| 147 | + |
| 148 | +**UNSUPPORTED.** No idea how to handle this (especially that this is |
| 149 | +the point at which licensing issues start to occur). Most likely, a |
| 150 | +separate image based off this one would be necessary. |
0 commit comments