Skip to content

Commit c36faf1

Browse files
committed
Renamed CHEF_PORT to SSL_PORT
SSL_PORT will default to 443 when missing Renamed validation_client_name Updated README
1 parent 24acbe0 commit c36faf1

File tree

2 files changed

+37
-29
lines changed

2 files changed

+37
-29
lines changed

README.md

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,37 @@ Image Size: 1.124 GB
66
This is a fork of: [base/chef-server](https://registry.hub.docker.com/u/base/chef-server/).
77

88
## Environment
9-
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`.
9+
##### Protocol / Port
10+
Chef is running over HTTPS/443 by default.
11+
You can however change that to another port by adding `-e SSL_PORT=new_port` to the `docker run` command below and update the expose port `-p` accordingly.
1012

11-
## Start the container
12-
*Launch the container:*
13+
##### SSL certificate
14+
When Chef Server gets configured it creates an SSL certificate based on the container's FQDN (i.e "103d6875c1c5" which is the "CONTAINER ID"). This default behiavior has been changed to always produce an SSL certificate file named "chef-server.crt".
15+
You can change the certificate name by adding `-e CONTAINER_NAME=new_name` to the `docker run` command. Remember to reflect that change in config.rb!
1316

14-
```
15-
$ docker run --privileged -e CHEF_PORT=443 --name chef-server -d -p 443:443 cbuisson/chef-server
16-
```
17+
##### DNS
18+
The container needs to be **DNS resolvable!**
19+
Be sure **'chef-server'** or **$CONTAINER_NAME** is pointing to the container's IP!
20+
This needs to be done to match the SSL certificate name with the `chef_server_url ` from knife's `config.rb` file.
1721

18-
*Launch the container with logs volumes:*
22+
## Start the container
23+
Docker command:
1924

25+
```bash
26+
$ docker run --privileged --name chef-server -d -p 443:443 cbuisson/chef-server
2027
```
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
22-
```
23-
24-
**Note:** By default `chef-server-ctl reconfigure` will create SSL certificates based on the container's FQDN (i.e "103d6875c1c5" which is its "CONTAINER ID"), I have changed that behiavior to always have a SSL certificate file named "chef-server.crt". You can change the certificate name by adding `-e CONTAINER_NAME=new_name` to the `docker run` command. Remember to reflect that change in config.rb!
2528

26-
'chef-server' or $CONTAINER_NAME **need to be DNS resolvable!**
29+
2 volumes directories are available: `/root` and `/var/log`. Feel free to optionally to use them while running the `docker run` command above by adding: `-v ~/chef-logs:/var/log -v ~/install-chef-out:/root`
2730

2831
## Setup knife
2932

3033
Once Chef Server 12 is configured, you can download the Knife admin keys here:
3134

32-
```
33-
curl -Ok https://chef-server:$CHEF_PORT/knife_admin_key.tar.gz
35+
```bash
36+
curl -Ok https://chef-server:$SSL_PORT/knife_admin_key.tar.gz
3437
```
3538

36-
Then un-tar that archive and point your config.rb to the `admin.pem` and `admin-validator.pem` files.
39+
Then un-tar that archive and point your config.rb to the `admin.pem` and `my_org-validator.pem` files.
3740

3841
*config.rb* example:
3942

@@ -43,9 +46,9 @@ log_location STDOUT
4346
cache_type 'BasicFile'
4447
node_name 'admin'
4548
client_key '/home/cbuisson/.chef/admin.pem'
46-
validation_client_name 'admin-validator'
47-
validation_key '/home/cbuisson/.chef/admin-validator.pem'
48-
chef_server_url 'https://chef-server:$CHEF_PORT/organizations/my_org'
49+
validation_client_name 'my_org-validator'
50+
validation_key '/home/cbuisson/.chef/my_org-validator.pem'
51+
chef_server_url 'https://chef-server:$SSL_PORT/organizations/my_org'
4952
```
5053

5154
When the config.rb file is ready, you will need to get the SSL certificate file from the container to access Chef Server:
@@ -74,4 +77,4 @@ However the webui is not required since you can interact with Chef-Server via th
7477
7578
##### Tags
7679
v1.0: Chef Server 11
77-
v2.X: Chef Server 12
80+
v2.x: Chef Server 12

configure_chef.sh

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
#/bin/bash -x
1+
#!/bin/bash -x
22

3-
cat > /etc/opscode/chef-server.rb << EOL
4-
nginx['enable_non_ssl']=false
5-
nginx['ssl_port']=$CHEF_PORT
6-
EOL
7-
if [[ ! -z $CONTAINER_NAME ]]; then
8-
echo "nginx['server_name']=\"$CONTAINER_NAME\"" >> /etc/opscode/chef-server.rb
3+
# Create chef-server.rb with variables
4+
echo "nginx['enable_non_ssl']=false" > /etc/opscode/chef-server.rb
5+
6+
if [[ -z $SSL_PORT ]]; then
7+
echo "nginx['ssl_port']=443" >> /etc/opscode/chef-server.rb
98
else
9+
echo "nginx['ssl_port']=$SSL_PORT" >> /etc/opscode/chef-server.rb
10+
fi
11+
12+
if [[ -z $CONTAINER_NAME ]]; then
1013
echo "nginx['server_name']=\"chef-server\"" >> /etc/opscode/chef-server.rb
14+
else
15+
echo "nginx['server_name']=\"$CONTAINER_NAME\"" >> /etc/opscode/chef-server.rb
1116
fi
1217

1318
chef-server-ctl reconfigure |tee /root/out.txt
@@ -17,7 +22,7 @@ CODE=1
1722
SECONDS=0
1823
TIMEOUT=60
1924

20-
return=`curl -sf ${URL}`
25+
return=$(curl -sf ${URL})
2126
echo "${URL} returns: ${return}" |tee -a /root/out.txt
2227

2328
if [[ -z "$return" ]]; then
@@ -47,7 +52,7 @@ if [[ -z "$return" ]]; then
4752
echo -e "\n\n$URL is available!\n" |tee -a /root/out.txt
4853
echo -e "\nSetting up admin user and default organization" |tee -a /root/out.txt
4954
chef-server-ctl user-create admin Admin User [email protected] "passwd" --filename /etc/chef/admin.pem |tee -a /root/out.txt
50-
chef-server-ctl org-create my_org "Default organization" --association_user admin --filename /etc/chef/admin-validator.pem |tee -a /root/out.txt
55+
chef-server-ctl org-create my_org "Default organization" --association_user admin --filename /etc/chef/my_org-validator.pem |tee -a /root/out.txt
5156
echo -e "\nRunning: chef-server-ctl install chef-manage" |tee -a /root/out.txt
5257
chef-server-ctl install chef-manage |tee -a /root/out.txt
5358
echo -e "\nRunning: chef-server-ctl reconfigure" |tee -a /root/out.txt
@@ -56,7 +61,7 @@ if [[ -z "$return" ]]; then
5661
sed -i "s,/503.json;,/503.json;\n error_page 497 =503 /500.json;,g" /var/opt/opscode/nginx/etc/chef_https_lb.conf
5762
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
5863
echo -e "\nCreating tar file with the Knife keys" |tee -a /root/out.txt
59-
cd /etc/chef/ && tar -cvzf knife_admin_key.tar.gz admin.pem admin-validator.pem
64+
cd /etc/chef/ && tar -cvzf knife_admin_key.tar.gz admin.pem my_org-validator.pem
6065
echo -e "\nRestart Nginx..." |tee -a /root/out.txt
6166
chef-server-ctl restart nginx
6267
chef-server-ctl status |tee -a /root/out.txt

0 commit comments

Comments
 (0)