Installing docker containers via chef with staged files

So, I have been struggling with this issue for a few days, but it seems to me that this should be a simple fix (perhaps my misunderstanding of a cook or a poker chef).

Here's my scenario. I have a set of containers that contain the components of my application. I have a workflow that essentially continuously deploys each of these containers to different environments with different settings for each (for example Dev will have all containers living on the same VM, but for Staging / Prod, the containers will be distributed across different VMs / hardware).

I am trying to use a chef to deploy these containers with a knife and then run a set of recipes in virtual machines. My problem is that I cannot figure out how to deploy the staged files for the Dockerfile COPY command. Here is an example Dockerfile I'm using. The COPY command should copy the package.json and index.js files to the / src directory and execute npm.

FROM    ubuntu:14.04
# Install dependencies and nodejs
RUN apt-get update -y
RUN apt-get install -y python-software-properties python g++ make curl
RUN curl -sL https://deb.nodesource.com/setup | sudo bash -
RUN apt-get update -y
RUN apt-get install -y build-essential nodejs
# Bundle app source
COPY . /src
# Install app source
RUN cd /src; ls; npm install
EXPOSE  8080
CMD ["node", "/src/index.js"]

      

My default.rb recipe looks like this:

include_recipe 'docker'
docker_image_build_file = '/tmp/docker_image_build.dockerfile'
cookbook_file "/etc/chef/package.json" do
  source 'package.json'
  action :create_if_missing
end
cookbook_file "/etc/chef/index.js" do
  source 'index.js'
  action :create_if_missing
end
cookbook_file docker_image_build_file do
  source 'Dockerfile'
end
docker_image 'node' do
  tag 'nodeTag'
  source docker_image_build_file
  action :build
end
docker_container 'node' do
  detach true
  port '8080:8888'
end

      

I tried to generate files in multiple locations including the docker / chef / directory, chef / directory, and files / default /. Nothing copied. Calling "ls" in my dockerfile after the COPY command only outputs "Dockerfile" and obviously the npm install fails because it cannot find the package.json directory in the / src directory:

<server> Step 14 : RUN cd /src; ls; npm install
<server>  ---> Running in 5f1dba1fd0cf
<server> Dockerfile
<server> npm ERR! install Couldn't read dependencies
<server> npm ERR! package.json ENOENT, open '/src/package.json'
<server> npm ERR! package.json This is most likely not a problem with npm itself.
<server> npm ERR! package.json npm can't find a package.json file in your current directory.
<server> 
<server> npm ERR! System Linux 3.13.0-37-generic
<server> npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install"
<server> npm ERR! cwd /src
<server> npm ERR! node -v v0.10.33
<server> npm ERR! npm -v 1.4.28
<server> npm ERR! path /src/package.json
<server> npm ERR! code ENOPACKAGEJSON
<server> npm ERR! errno 34
<server> npm ERR! 
<server> npm ERR! Additional logging details can be found in:
<server> npm ERR!     /src/npm-debug.log
<server> npm ERR! not ok code 0

      

I know I am probably doing something very stupid, so any help would be appreciated!

PS I realize there are several other options for deploying Dockerfiles, but I'm really trying to use a chef as there are several cookbooks I want to use to prepare my environment, outside of just deploying and running containers.

+3


source to share


1 answer


Just post it here if others have encountered this problem. This happened because my source in docker_image was supposed to be a directory pointing to / tmp and I copied all the files in there. Here's my updated (working) recipe:



include_recipe 'docker'
docker_node_data = '/tmp/docker'
directory docker_node_data do
  action :create
end 
cookbook_file "#{docker_node_data}/package.json" do
  source 'package.json'
  action :create_if_missing
end
cookbook_file "#{docker_node_data}/Dockerfile" do
  source 'Dockerfile'
end
docker_image 'example/node' do
  tag 'latest'
  source docker_node_data
  action :build
end
docker_container 'example/node' do
  detach true
  port '8080:8080'
  action :run
end

      

0


source







All Articles