Skip to content

Commit 3f52f78

Browse files
committed
Chef Server 12 is now supported
- The container won't reconfigure Chef after a reboot - Better logging - Removed unused commands
1 parent 31452c9 commit 3f52f78

File tree

5 files changed

+111
-170
lines changed

5 files changed

+111
-170
lines changed

Dockerfile

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
FROM ubuntu:14.04
22
MAINTAINER Clement Buisson <[email protected]>
3-
#This is a fork of base/chef-server
43

54
ENV DEBIAN_FRONTEND noninteractive
65
RUN apt-get update && \
76
apt-get install -yq --no-install-recommends wget curl && \
8-
wget --no-check-certificate --content-disposition "http://www.opscode.com/chef/download-server?p=ubuntu&pv=14.04&m=x86_64&v=11&prerelease=false&nightlies=false" && \
7+
wget --no-check-certificate --content-disposition "http://www.opscode.com/chef/download-server?p=ubuntu&pv=14.04&m=x86_64&v=12&prerelease=false&nightlies=false" && \
98
dpkg -i chef-server*.deb && \
109
rm chef-server*.deb && \
1110
apt-get remove -y wget && \
1211
rm -rf /var/lib/apt/lists/*
1312

14-
RUN dpkg-divert --local --rename --add /sbin/initctl
15-
RUN ln -sf /bin/true /sbin/initctl
16-
17-
ADD reconfigure_chef.sh /usr/local/bin/
13+
ADD configure_chef.sh /usr/local/bin/
1814
ADD run.sh /usr/local/bin/
19-
CMD rsyslogd -n
2015
VOLUME /root/
2116
VOLUME /var/log
2217
CMD ["run.sh"]

README.md

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,74 @@
11
# chef-server
22

3-
chef-server is running Chef Server 11 in a Ubuntu Trusty 14.04 LTS container.
4-
Image Size: 1.025 GB
3+
chef-server will run Chef Server 12 in an Ubuntu Trusty 14.04 LTS container.
4+
Image Size: 1.124 GB
55

66
This is a fork of: [base/chef-server](https://registry.hub.docker.com/u/base/chef-server/).
77

88
## Environment
99
Chef is running over HTTPS/443 by default. You can however change that to another port by updating the `CHEF_PORT` variable and the expose port `-p`.
1010

11-
You will need to use Chef 11.X in order to be able to use Knife.
12-
Check Knife's version:
13-
```bash
14-
cbuisson@t530:~# knife -v
15-
Chef: 11.16.4
16-
```
17-
*If you have Chef 12 installed on your Docker server, you will need to use* `knife ssl fetch` *in order to get the SSL certificates from the container. Don't forget to update `chef_server_url` with the container ID in knife.rb!*
18-
1911
## Usage
20-
*With log output:*
12+
*Launch the container:*
2113

2214
```
23-
$ docker run --privileged -e CHEF_PORT=443 --name chef-server -d -v ~/chef-logs:/var/log -v ~/install-chef-out:/root -p 443:443 cbuisson/chef-server
15+
$ docker run --privileged -e CHEF_PORT=443 --name chef-server -d -p 443:443 cbuisson/chef-server
2416
```
2517

26-
*Just the container:*
18+
*Launch the container with logs volumes:*
2719

2820
```
29-
$ docker run --privileged -e CHEF_PORT=443 --name chef-server -d -p 443:443 cbuisson/chef-server
21+
$ docker run --privileged -e CHEF_PORT=443 --name chef-server -d -v ~/chef-logs:/var/log -v ~/install-chef-out:/root -p 443:443 cbuisson/chef-server
3022
```
3123

32-
Once the Chef server is configured, you can download the Knife admin keys here:
24+
Once Chef Server 12 is configured, you can download the Knife admin keys here:
3325

3426
```
35-
$ curl -Ok https://IP_HOST:CHEF_PORT/knife_admin_key.tar.gz
27+
$ curl -Ok https://CONTAINER_ID:CHEF_PORT/knife_admin_key.tar.gz
3628
```
3729

38-
Then un-tar that archive and point your knife.rb to the `admin.pem` and `chef-validator.pem` files.
30+
Then un-tar that archive and point your config.rb to the `admin.pem` and `admin-validator.pem` files.
3931

40-
*knife.rb* example:
41-
```bash
32+
*config.rb* example:
33+
34+
```ruby
4235
log_level :info
4336
log_location STDOUT
4437
cache_type 'BasicFile'
4538
node_name 'admin'
4639
client_key '/home/cbuisson/.chef/admin.pem'
47-
validation_client_name 'chef-validator'
48-
validation_key '/home/cbuisson/.chef/chef-validator.pem'
49-
chef_server_url 'https://IP_HOST:CHEF_PORT'
40+
validation_client_name 'admin-validator'
41+
validation_key '/home/cbuisson/.chef/admin-validator.pem'
42+
chef_server_url 'https://CONTAINER_ID:CHEF_PORT/organizations/my_org'
43+
```
44+
Note: CONTAINER_ID **needs** to be resolvable by hostname!
45+
46+
When the config.rb file is ready, you will need to get the SSL certificate files from the container to access Chef Server:
47+
48+
```bash
49+
cbuisson@t530:~/.chef# knife ssl fetch
50+
WARNING: Certificates from 512ab20b1e0d will be fetched and placed in your trusted_cert
51+
directory (/home/cbuisson/.chef/trusted_certs).
52+
53+
Knife has no means to verify these are the correct certificates. You should
54+
verify the authenticity of these certificates after downloading.
55+
56+
Adding certificate for 512ab20b1e0d in /home/cbuisson/.chef/trusted_certs/512ab20b1e0d.crt
5057
```
58+
59+
You should now be able to use the knife command!
60+
```bash
61+
cbuisson@t530:~# knife user list
62+
admin
63+
```
64+
65+
##### Known issue
66+
`chef-manage-ctl reconfigure` needs to run in order to access the Chef webui. When this command is executed within the container, it blocks here:
67+
```bash
68+
* ruby_block[wait for redis service socket] action run
69+
```
70+
Therefore the Chef Server 12 webui isn't available at the moment, however this isn't required to use Chef since Knife is working.
71+
72+
##### Tags
73+
v1.0: Chef Server 11
74+
v2.0: Chef Server 12

configure_chef.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#/bin/bash -x
2+
3+
chef-server-ctl reconfigure |tee /root/out.txt
4+
5+
URL="http://127.0.0.1:8000/_status"
6+
CODE=1
7+
SECONDS=0
8+
TIMEOUT=60
9+
10+
return=`curl -sf ${URL}`
11+
echo "${URL} returns: ${return}" |tee -a /root/out.txt
12+
13+
if [[ -z "$return" ]]; then
14+
echo "Error while running chef-server-ctl reconfigure" |tee -a /root/out.txt
15+
echo -e "Blocking until <${URL}> responds...\n" |tee -a /root/out.txt
16+
17+
while [ $CODE -ne 0 ]; do
18+
19+
curl -sf \
20+
--connect-timeout 3 \
21+
--max-time 5 \
22+
--fail \
23+
--silent \
24+
${URL}
25+
26+
CODE=$?
27+
28+
sleep 2
29+
echo -n "." |tee -a /root/out.txt
30+
31+
if [ $SECONDS -ge $TIMEOUT ]; then
32+
echo "$URL is not available after $SECONDS seconds...stopping the script!" |tee -a /root/out.txt
33+
exit 1
34+
fi
35+
36+
done;
37+
echo -e "\n\n$URL is available!\n" |tee -a /root/out.txt
38+
echo -e "\nSetting up admin user and default organization" |tee -a /root/out.txt
39+
chef-server-ctl user-create admin Admin User [email protected] "passwd" --filename /etc/chef/admin.pem |tee -a /root/out.txt
40+
chef-server-ctl org-create my_org "Default organization" --association_user admin --filename /etc/chef/admin-validator.pem |tee -a /root/out.txt
41+
echo -e "\nRunning: chef-server-ctl install chef-manage" |tee -a /root/out.txt
42+
chef-server-ctl install chef-manage |tee -a /root/out.txt
43+
echo -e "\nRunning: chef-server-ctl reconfigure" |tee -a /root/out.txt
44+
chef-server-ctl reconfigure |tee -a /root/out.txt
45+
fi

reconfigure_chef.sh

Lines changed: 0 additions & 40 deletions
This file was deleted.

run.sh

Lines changed: 18 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,20 @@
11
#!/bin/bash -xe
22
sysctl -w kernel.shmmax=17179869184
3-
/opt/chef-server/embedded/bin/runsvdir-start &
4-
/usr/local/bin/reconfigure_chef.sh
5-
hostname=`hostname`
6-
cat > /var/opt/chef-server/nginx/etc/chef_https_lb.conf << EOL
7-
server {
8-
listen $CHEF_PORT;
9-
server_name $hostname;
10-
access_log /var/log/chef-server/nginx/access.log opscode;
11-
12-
ssl on;
13-
ssl_certificate /var/opt/chef-server/nginx/ca/${hostname}.crt;
14-
ssl_certificate_key /var/opt/chef-server/nginx/ca/${hostname}.key;
15-
16-
ssl_session_timeout 5m;
17-
18-
ssl_protocols SSLv3 TLSv1;
19-
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA;
20-
ssl_prefer_server_ciphers on;
21-
22-
root /var/opt/chef-server/nginx/html;
23-
24-
client_max_body_size 250m;
25-
26-
proxy_set_header Host \$host:\$server_port;
27-
proxy_set_header X-Real-IP \$remote_addr;
28-
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
29-
proxy_set_header X-Forwarded-Proto https;
30-
proxy_pass_request_headers on;
31-
proxy_connect_timeout 1;
32-
proxy_send_timeout 300;
33-
proxy_read_timeout 300;
34-
35-
error_page 404 =404 /404.html;
36-
error_page 503 =503 /503.json;
37-
38-
location /nginx_status {
39-
stub_status on;
40-
access_log off;
41-
allow 127.0.0.1;
42-
deny all;
43-
}
44-
45-
location /knife_admin_key.tar.gz {
46-
default_type application/zip;
47-
alias /etc/chef-server/knife_admin_key.tar.gz;
48-
}
49-
50-
location /version {
51-
types { }
52-
default_type text/plain;
53-
alias /opt/chef-server/version-manifest.txt;
54-
}
55-
56-
location /docs {
57-
index index.html ;
58-
alias /opt/chef-server/docs;
59-
}
60-
61-
# bookshelf
62-
location ~ "/bookshelf/{0,1}.*$" {
63-
proxy_pass http://bookshelf;
64-
}
65-
66-
location ~ "^/(?:stylesheets|javascripts|images|facebox|css|favicon|robots|humans)/{0,1}.*$" {
67-
if (\$http_x_chef_version ~* "^(\d+\.\d+?)\..+$") {
68-
error_page 400 =400 /400-chef_client_manage.json;
69-
return 400;
70-
}
71-
proxy_pass http://chef_server_webui;
72-
proxy_pass_request_headers off;
73-
proxy_cache webui-cache;
74-
proxy_cache_valid 200 302 300m;
75-
proxy_cache_valid 404 1m;
76-
}
77-
78-
location = /_status {
79-
proxy_pass http://erchef/_status;
80-
}
81-
82-
location = /_status/ {
83-
proxy_pass http://erchef/_status;
84-
}
85-
86-
location / {
87-
set \$my_upstream erchef;
88-
if (\$http_x_ops_userid = "") {
89-
set \$my_upstream chef_server_webui;
90-
}
91-
proxy_redirect http://\$my_upstream /;
92-
proxy_pass http://\$my_upstream;
93-
}
94-
}
95-
EOL
96-
cd /etc/chef-server/ && tar -cvzf knife_admin_key.tar.gz admin.pem chef-validator.pem
97-
cat > /etc/chef-server/chef-server.rb << EOL
98-
nginx['ssl_port'] = $CHEF_PORT
99-
EOL
100-
chef-server-ctl restart nginx
101-
chef-server-ctl status >> /root/out.txt
102-
echo "Done!" >> /root/out.txt
103-
tail -F /opt/chef-server/embedded/service/*/log/current
3+
/opt/opscode/embedded/bin/runsvdir-start &
4+
if [ -f "/root/chef_configured" ]
5+
then
6+
echo -e "\nChef Server already configured!\n" |tee -a /root/out.txt
7+
chef-server-ctl status |tee -a /root/out.txt
8+
else
9+
/usr/local/bin/configure_chef.sh
10+
sed -i "s, listen 443;, listen $CHEF_PORT;,g" /var/opt/opscode/nginx/etc/chef_https_lb.conf
11+
sed -i '$i\ location /knife_admin_key.tar.gz {\n default_type application/zip;\n alias /etc/chef/knife_admin_key.tar.gz;\n }' /var/opt/opscode/nginx/etc/chef_https_lb.conf
12+
echo -e "\nCreating tar file with the Knife keys" |tee -a /root/out.txt
13+
cd /etc/chef/ && tar -cvzf knife_admin_key.tar.gz admin.pem admin-validator.pem
14+
echo -e "\nRestart Nginx..." |tee -a /root/out.txt
15+
chef-server-ctl restart nginx
16+
chef-server-ctl status |tee -a /root/out.txt
17+
touch /root/chef_configured
18+
echo -e "\n\nDone!\n" |tee -a /root/out.txt
19+
fi
20+
tail -F /opt/opscode/embedded/service/*/log/current

0 commit comments

Comments
 (0)