Skip to content

Commit

Permalink
New Chef 12 version
Browse files Browse the repository at this point in the history
Cleaner log output
  • Loading branch information
c-buisson committed Aug 23, 2017
1 parent c36faf1 commit 6d18575
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ MAINTAINER Clement Buisson <clement.buisson@gmail.com>
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && \
apt-get install -yq --no-install-recommends wget curl && \
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" && \
wget --no-check-certificate --content-disposition "http://www.opscode.com/chef/download-server?p=ubuntu&pv=14.04&m=x86_64&v=12.15.8&prerelease=false&nightlies=false" && \
dpkg -i chef-server*.deb && \
rm chef-server*.deb && \
apt-get remove -y wget && \
Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ You can however change that to another port by adding `-e SSL_PORT=new_port` to
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".
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!

##### Logs
`/var/log/` is accessible via a volume directory. Feel free to optionally to use it with the `docker run` command above by adding: `-v ~/chef-logs:/var/log`

##### DNS
The container needs to be **DNS resolvable!**
Be sure **'chef-server'** or **$CONTAINER_NAME** is pointing to the container's IP!
Expand All @@ -23,10 +26,14 @@ This needs to be done to match the SSL certificate name with the `chef_server_ur
Docker command:

```bash
$ docker run --privileged --name chef-server -d -p 443:443 cbuisson/chef-server
$ docker run --privileged -t --name chef-server -d -p 443:443 cbuisson/chef-server
```

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`
Follow the installation:

```bash
$ docker logs -f chef-server
```

## Setup knife

Expand Down
52 changes: 26 additions & 26 deletions configure_chef.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash -x
#!/bin/bash

# Create chef-server.rb with variables
echo "nginx['enable_non_ssl']=false" > /etc/opscode/chef-server.rb
Expand All @@ -15,19 +15,19 @@ else
echo "nginx['server_name']=\"$CONTAINER_NAME\"" >> /etc/opscode/chef-server.rb
fi

chef-server-ctl reconfigure |tee /root/out.txt
echo -e "\nRunning: 'chef-server-ctl reconfigure'. This step will take a few minutes..."
chef-server-ctl reconfigure

URL="http://127.0.0.1:8000/_status"
CODE=1
SECONDS=0
TIMEOUT=60

return=$(curl -sf ${URL})
echo "${URL} returns: ${return}" |tee -a /root/out.txt

if [[ -z "$return" ]]; then
echo "Error while running chef-server-ctl reconfigure" |tee -a /root/out.txt
echo -e "Blocking until <${URL}> responds...\n" |tee -a /root/out.txt
echo -e "\nINFO: Chef-Server isn't ready yet!"
echo -e "Blocking until <${URL}> responds...\n"

while [ $CODE -ne 0 ]; do

Expand All @@ -41,30 +41,30 @@ if [[ -z "$return" ]]; then
CODE=$?

sleep 2
echo -n "." |tee -a /root/out.txt
echo -n "."

if [ $SECONDS -ge $TIMEOUT ]; then
echo "$URL is not available after $SECONDS seconds...stopping the script!" |tee -a /root/out.txt
echo "$URL is not available after $SECONDS seconds...stopping the script!"
exit 1
fi
done;

echo -e "\n\n$URL is available!\n" |tee -a /root/out.txt
echo -e "\nSetting up admin user and default organization" |tee -a /root/out.txt
chef-server-ctl user-create admin Admin User admin@myorg.com "passwd" --filename /etc/chef/admin.pem |tee -a /root/out.txt
chef-server-ctl org-create my_org "Default organization" --association_user admin --filename /etc/chef/my_org-validator.pem |tee -a /root/out.txt
echo -e "\nRunning: chef-server-ctl install chef-manage" |tee -a /root/out.txt
chef-server-ctl install chef-manage |tee -a /root/out.txt
echo -e "\nRunning: chef-server-ctl reconfigure" |tee -a /root/out.txt
chef-server-ctl reconfigure |tee -a /root/out.txt
echo "{ \"error\": \"Please use https:// instead of http:// !\" }" > /var/opt/opscode/nginx/html/500.json
sed -i "s,/503.json;,/503.json;\n error_page 497 =503 /500.json;,g" /var/opt/opscode/nginx/etc/chef_https_lb.conf
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
echo -e "\nCreating tar file with the Knife keys" |tee -a /root/out.txt
cd /etc/chef/ && tar -cvzf knife_admin_key.tar.gz admin.pem my_org-validator.pem
echo -e "\nRestart Nginx..." |tee -a /root/out.txt
chef-server-ctl restart nginx
chef-server-ctl status |tee -a /root/out.txt
touch /root/chef_configured
echo -e "\n\nDone!\n" |tee -a /root/out.txt
fi

echo -e "\n\n$URL is available!\n"
echo -e "\nSetting up admin user and default organization"
chef-server-ctl user-create admin Admin User admin@myorg.com "passwd" --filename /etc/chef/admin.pem
chef-server-ctl org-create my_org "Default organization" --association_user admin --filename /etc/chef/my_org-validator.pem
echo -e "\nRunning: 'chef-server-ctl install chef-manage'"...
chef-server-ctl install chef-manage
echo -e "\nRunning: 'chef-server-ctl reconfigure'"...
chef-server-ctl reconfigure
echo "{ \"error\": \"Please use https:// instead of http:// !\" }" > /var/opt/opscode/nginx/html/500.json
sed -i "s,/503.json;,/503.json;\n error_page 497 =503 /500.json;,g" /var/opt/opscode/nginx/etc/chef_https_lb.conf
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
echo -e "\nCreating tar file with the Knife keys"
cd /etc/chef/ && tar -cvzf knife_admin_key.tar.gz admin.pem my_org-validator.pem
echo -e "\nRestart Nginx..."
chef-server-ctl restart nginx
chef-server-ctl status
touch /root/chef_configured
echo -e "\n\nDone!\n"
9 changes: 5 additions & 4 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/bin/bash -xe
sysctl -w kernel.shmmax=17179869184
#!/bin/bash -e
sysctl -wq kernel.shmmax=17179869184
/opt/opscode/embedded/bin/runsvdir-start &
if [ -f "/root/chef_configured" ]
then
echo -e "\nChef Server already configured!\n" |tee -a /root/out.txt
chef-server-ctl status |tee -a /root/out.txt
echo -e "\nChef Server already configured!\n"
chef-server-ctl status
else
echo -e "\nNew install of Chef-Server!"
/usr/local/bin/configure_chef.sh
fi
tail -F /opt/opscode/embedded/service/*/log/current

0 comments on commit 6d18575

Please sign in to comment.