I am debugging an issue where I am doing my development inside of a Docker container, but Jekyll is not properly updating static HTML or CSS files after the first time it has been written. I have added the following code to static_file.rb after line 83:
sha256_src = Digest::SHA256.file path
sha256_dst = Digest::SHA256.file dest_path
fail "invalid file copy: #{path} / #{dest_path}" unless sha256_src == sha256_dst
And I see that the fail triggered because the hash does not match. Instead, an older version of the static file at path has been copied to dest_path. I thought I was losing my mind, but I know that Docker uses layered file systems and so I wonder if I am hitting some kind of bug or known issue.
Are there any known issues with using the following technologies in tandem with each other:
Jekyll
Docker containers
Linux containers
FileUtils cp method
Ruby 2.2.3p173
I have had to work around it by running the following command:
cp s5/*.css _site/s5/
cp s5/*.html _site/s5/
Instead of having it work automatically for me with jekyll build.
Here is how I am linking my files to the docker image:
export ABSPATH=$(cd "$(dirname "$0")"; cd ../; pwd)
docker run -d --name static -t -i -p 4000:4000 -p 2422:22 --link static-db:db -v "$ABSPATH:/mnt/app" me/static:0.0.2 /sbin/my_init --enable-insecure-key
Docker version:
Client:
Version: 1.8.3
API version: 1.20
Go version: go1.4.2
Git commit: f4bf5c7
Built: Mon Oct 12 18:01:15 UTC 2015
OS/Arch: darwin/amd64
Server:
Version: 1.8.3
API version: 1.20
Go version: go1.4.2
Git commit: f4bf5c7
Built: Mon Oct 12 18:01:15 UTC 2015
OS/Arch: linux/amd64
Docker info:
Containers: 10
Images: 265
Storage Driver: aufs
Root Dir: /mnt/sda1/var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 285
Dirperm1 Supported: true
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 4.1.10-boot2docker
Operating System: Boot2Docker 1.8.3 (TCL 6.4); master : af8b089 - Mon Oct 12 18:56:54 UTC 2015
CPUs: 1
Total Memory: 3.859 GiB
Name: dev
ID: ZY6F:2VSO:EDRL:TWYE:JAS6:5GC3:PPAO:TNA6:KCCB:HFLC:4IQB:5BYE
Debug mode (server): true
File Descriptors: 21
Goroutines: 33
System Time: 2015-10-18T18:36:20.08630971Z
EventsListeners: 0
Init SHA1:
Init Path: /usr/local/bin/docker
Docker Root Dir: /mnt/sda1/var/lib/docker
Username: me
Registry: https://index.docker.io/v1/
Labels:
provider=virtualbox
I am running this linked to a volume on OSX.
Here is an interactive session using binding.pry inside of static_file.rb. You can see that FileUtils.cp is not working properly.
In step 9-10 one can see I am manually invoking the FileUtils::cp command, and the resulting file hash is aa75cd.... I even try using FileUtils.cp to copy my original file to a different file path without success. However, in step 20-21, when I invoke the shell cp command directly using cp, it works and the resulting file has the proper hash of 724707....
Parsing Haml layouts...done.
Parsing Scss layouts...done.
Configuration file: /mnt/app/_config.yml
Source: /mnt/app
Destination: /mnt/app/_site
Generating...
From: /usr/local/lib/ruby/gems/2.2.0/gems/jekyll-2.5.3/lib/jekyll/static_file.rb # line 92 Jekyll::StaticFile#write:
77: def write(dest)
78: dest_path = destination(dest)
79:
80: return false if File.exist?(dest_path) and !modified?
81: ##mtimes[path] = mtime
82:
83: FileUtils.mkdir_p(File.dirname(dest_path))
84: FileUtils.rm(dest_path) if File.exist?(dest_path)
85:
86: FileUtils.cp(path, dest_path)
87:
88: sha256_src = Digest::SHA256.file path
89: sha256_dst = Digest::SHA256.file dest_path
90:
91: if sha256_src != sha256_dst
=> 92: binding.pry
93: end
94: puts "invalid file copy: #{path} / #{dest_path}" unless sha256_src == sha256_dst
95:
96: true
97: end
[1] pry(#<Jekyll::StaticFile>)> path
=> "/mnt/app/styles/scruff5.css"
[2] pry(#<Jekyll::StaticFile>)> dest_path
=> "/mnt/app/_site/styles/scruff5.css"
[3] pry(#<Jekyll::StaticFile>)> Digest::SHA256.file path
=> #<Digest::SHA256: 72470716291c6fef0c8c2151a0d0997f0991396cda964ba48e3cbb65cc7f7908>
[4] pry(#<Jekyll::StaticFile>)> Digest::SHA256.file dest_path
=> #<Digest::SHA256: aa75cd20ddf51b86ec2344002532f08891e05eb1a0a9f7e5f99d8fda05c5c920>
[5] pry(#<Jekyll::StaticFile>)> dest_path
=> "/mnt/app/_site/styles/scruff5.css"
[6] pry(#<Jekyll::StaticFile>)> FileUtils.rm(dest_path)
=> ["/mnt/app/_site/styles/scruff5.css"]
[7] pry(#<Jekyll::StaticFile>)> Digest::SHA256.file dest_path
Errno::ENOENT: No such file or directory # rb_sysopen - /mnt/app/_site/styles/scruff5.css
from /usr/local/lib/ruby/2.2.0/digest.rb:49:in `initialize'
[8] pry(#<Jekyll::StaticFile>)> Digest::SHA256.file path
=> #<Digest::SHA256: 72470716291c6fef0c8c2151a0d0997f0991396cda964ba48e3cbb65cc7f7908>
[9] pry(#<Jekyll::StaticFile>)> FileUtils.cp(path, dest_path)
=> nil
[10] pry(#<Jekyll::StaticFile>)> Digest::SHA256.file dest_path
=> #<Digest::SHA256: aa75cd20ddf51b86ec2344002532f08891e05eb1a0a9f7e5f99d8fda05c5c920>
[11] pry(#<Jekyll::StaticFile>)> dest_path
=> "/mnt/app/_site/styles/scruff5.css"
[12] pry(#<Jekyll::StaticFile>)> dest_path = dest_path + '-2'
=> "/mnt/app/_site/styles/scruff5.css-2"
[13] pry(#<Jekyll::StaticFile>)> FileUtils.cp(path, dest_path)
=> nil
[14] pry(#<Jekyll::StaticFile>)> FileUtils.cp(path, dest_path)
=> nil
[15] pry(#<Jekyll::StaticFile>)> Digest::SHA256.file dest_path
=> #<Digest::SHA256: aa75cd20ddf51b86ec2344002532f08891e05eb1a0a9f7e5f99d8fda05c5c920>
[16] pry(#<Jekyll::StaticFile>)> (Digest::SHA256.file dest_path).hexdigest
=> "aa75cd20ddf51b86ec2344002532f08891e05eb1a0a9f7e5f99d8fda05c5c920"
[17] pry(#<Jekyll::StaticFile>)> (Digest::SHA256.file path).hexdigest
=> "72470716291c6fef0c8c2151a0d0997f0991396cda964ba48e3cbb65cc7f7908"
[18] pry(#<Jekyll::StaticFile>)> FileUtils.rm dest_path
=> ["/mnt/app/_site/styles/scruff5.css-2"]
[19] pry(#<Jekyll::StaticFile>)> dest_path = '/mnt/app/_site/styles/scruff5.css'
=> "/mnt/app/_site/styles/scruff5.css"
[20] pry(#<Jekyll::StaticFile>)> `cp #{path} #{dest_path}`
=> ""
[21] pry(#<Jekyll::StaticFile>)> Digest::SHA256.file dest_path
=> #<Digest::SHA256: 72470716291c6fef0c8c2151a0d0997f0991396cda964ba48e3cbb65cc7f7908>
[22] pry(#<Jekyll::StaticFile>)>
After doing the above analysis and determining that [FileUtils.cp][1] seemed to be at the root of this issue, I downgraded from Ruby 2.2.1 to Ruby 2.1.7p400, and this issue now appears to be corrected. It would appear that Ruby 2.2.1 has a potentially version serious regression in FileUtils.
Related
I'm trying to build a project on a Linux Ubuntu 22.04, under Windows 11 22H2 Wsl2.
But when i run ./vendor/bin/sail up or ./vendor/bin/sail up -d I'm blocked by a infinity step:
[+] Building 663.1s (7/15)
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 32B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/ubuntu:22.04 0.8s
=> [ 1/11] FROM docker.io/library/ubuntu:22.04#sha256:4b1d0c4a2d2aaf63b37111f34eb9fa89fa1bf53dd6 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 99B 0.0s
=> CACHED [ 2/11] WORKDIR /var/www/html 0.0s-
=> CACHED [ 3/11] RUN ln -snf /usr/share/zoneinfo/UTC /etc/localtime && echo UTC > /etc/timezone 0.0si
=> [ 4/11] RUN apt-get update && apt-get install -y gnupg gosu curl ca-certificates zip un 662.2s
=> => # Processing triggers for ca-certificates (20211016) ...
=> => # Updating certificates in /etc/ssl/certs...
=> => # 0 added, 0 removed; done.
=> => # Running hooks in /etc/ca-certificates/update.d...
=> => # done.
=> => # gpg: keybox '/root/.gnupg/pubring.kbx' created
Last night I let the build running on this step all night long.
I tried to re-install the packages (php, wsl, ubuntu 22.04 distro, composer and node and npm under nvm), and re-clone the project, but nothing happen.
Thanks for your time.
Behold:
bear#ptah:~/Pictures/Wallpapers
$ stat /home/bear/Dropbox/.#NineFoxes.org
File: /home/bear/Dropbox/.#NineFoxes.org -> polar#fennec.3781:1659418908
Size: 28 Blocks: 0 IO Block: 4096 symbolic link
Device: 10306h/66310d Inode: 57016400 Links: 1
Access: (0777/lrwxrwxrwx) Uid: ( 1000/ bear) Gid: ( 1000/ bear)
Access: 2022-09-23 12:31:49.280214712 -0700
Modify: 2022-08-07 22:25:24.000000000 -0700
Change: 2022-09-23 12:31:49.532216732 -0700
Birth: 2022-09-23 12:31:49.280214712 -0700
bear#ptah:~/Pictures/Wallpapers
$ stat /home/bear/Dropbox/foo.log
File: /home/bear/Dropbox/foo.log
Size: 1471 Blocks: 8 IO Block: 4096 regular file
Device: 10306h/66310d Inode: 57016411 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/ bear) Gid: ( 1000/ bear)
Access: 2022-09-23 12:31:49.280214712 -0700
Modify: 2022-09-10 23:28:04.000000000 -0700
Change: 2022-09-23 12:31:50.116221410 -0700
Birth: 2022-09-23 12:31:49.280214712 -0700
bear#ptah:~/Pictures/Wallpapers
$ irb
irb(main):001:0> File.stat '/home/bear/Dropbox/foo.log'
=> #<File::Stat dev=0x10306, ino=57016411, mode=0100644, nlink=1, uid=1000, gid=1000, rdev=0x0, size=1471, blksize=4096, blocks=8, atime=2022-09-23 12:31:49.280214712 -0700, mtime=2022-09-10 23:28:04 -0700, ctime=2022-09-23 12:31:50.11622141 -0700>
irb(main):002:0> File.stat '/home/bear/Dropbox/.#NineFoxes.org'
Traceback (most recent call last):
5: from /usr/bin/irb:23:in `<main>'
4: from /usr/bin/irb:23:in `load'
3: from /usr/lib/ruby/gems/2.7.0/gems/irb-1.2.6/exe/irb:11:in `<top (required)>'
2: from (irb):2
1: from (irb):2:in `stat'
Errno::ENOENT (No such file or directory # rb_file_s_stat - /home/bear/Dropbox/.#NineFoxes.org)
irb(main):003:0>
The filename is simply correct; that is the file and Ruby fails to stat it. Linux can, everything else can. Ruby can stat a file without a hash in it, also. What is needed to render this file usable to Ruby? (No, renaming is not an option; I need to stat the file.)
Note: This is the filename that Dir.glob finds, also. This is the filename that Ruby thinks it has.
irb(main):003:0> x = Dir.glob('Dropbox/*.org', File::FNM_DOTMATCH)
=> ["Dropbox/NineFoxes.org", "Dropbox/.#NineFoxes.org", "Dropbox/Elf.org", "Dropbox/Midra.org"]
irb(main):004:0> File.stat(x[0])
=> #<File::Stat dev=0x10306, ino=57016406, mode=0100744, nlink=1, uid=1000, gid=1000, rdev=0x0, size=38102, blksize=4096, blocks=80, atime=2022-09-23 12:31:49.280214712 -0700, mtime=2022-07-29 22:00:02 -0700, ctime=2022-09-23 12:31:50.11622141 -0700>
irb(main):005:0> File.stat(x[1])
Traceback (most recent call last):
5: from /usr/bin/irb:23:in `<main>'
4: from /usr/bin/irb:23:in `load'
3: from /usr/lib/ruby/gems/2.7.0/gems/irb-1.2.6/exe/irb:11:in `<top (required)>'
2: from (irb):5
1: from (irb):5:in `stat'
Errno::ENOENT (No such file or directory # rb_file_s_stat - Dropbox/.#NineFoxes.org)
irb(main):006:0> File.stat(x[2])
=> #<File::Stat dev=0x10306, ino=57016408, mode=0100644, nlink=1, uid=1000, gid=1000, rdev=0x0, size=8416, blksize=4096, blocks=24, atime=2022-09-23 12:31:49.280214712 -0700, mtime=2022-09-19 18:08:32 -0700, ctime=2022-09-23 12:31:50.120221442 -0700>
irb(main):007:0>
Additional: This is Linux, MX Linux 21, ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [x86_64-linux-gnu]. The shell is Bash.
File.stat just calls File::Stat.new and that will raise an exception if the file doesn't exist; this is the behaviour you're seeing.
Note that /home/bear/Dropbox/.#NineFoxes.org is a symlink (see the Access: 0777/lrwxrwxrwx in stat's output). Ruby's File.stat documentation doesn't say if it follows symlinks or not but File.lstat says:
Same as File::stat, but does not follow the last symbolic link. Instead, reports on the link itself.
so it is implied that File.stat will follow the symlink and stat what it points to.
So the /home/bear/Dropbox/.#NineFoxes.org symlink does exist but what the symlink references doesn't exist.
cy.intercept('POST', '/api/create_payment_intent', {
fixture: 'payment_intent.json', // fixture file with mocked response
}).as('createPaymentIntent');
payment_intent.json file exists at cypress/fixtures/ directory filled with valid json.
Error:
[1] [1] Error: An error was thrown while processing a network event: A fixture file could not be found at any of the following paths:
[1] [1]
[1] [1] > cypress/fixtures/payment_intent.json
[1] [1] > cypress/fixtures/payment_intent.json{{extension}}
[1] [1]
[1] [1] Cypress looked for these file extensions at the provided path:
[1] [1]
[1] [1] > .json, .js, .coffee, .html, .txt, .csv, .png, .jpg, .jpeg, .gif, .tif, .tiff, .zip
[1] [1]
[1] [1] Provide a path to an existing fixture file.
[1] [1]
[1] [1] Because this error occurred during a `before each` hook we are skipping the remaining tests in the current suite: `Neo4j Aura Console - Common`
[1] [1] Error: A fixture file could not be found at any of the following paths:
[1] [1]
[1] [1] > cypress/fixtures/payment_intent.json
[1] [1] > cypress/fixtures/payment_intent.json{{extension}}
[1] [1]
[1] [1] Cypress looked for these file extensions at the provided path:
Hoe does one debug this when I have done exactly what the documentation has stated?
I am trying to get into animations using the Plots package. I am following this tutorial: https://docs.juliaplots.org/latest/animations/
However when trying to execute the program I get the following error:
ERROR: LoadError: failed process: Process(`/home/olep/.julia/artifacts/7f40eeb66d90d3026ae5fb68761c263b57adb840/bin/ffmpeg -v 16 -framerate 3 -i /tmp/jl_h1sGUw/%06d.png -i /tmp/jl_h1sGUw/palette.bmp -lavfi paletteuse=dither=sierra2_4a -loop 0 -y /home/olep/Documents/Studium/Semester2/tutorial_anim_fps30.gif`, ProcessSignaled(11)) [0]
Stacktrace:
[1] run
# ./process.jl:438 [inlined]
[2] (::FFMPEG.var"#4#6"{Cmd})(command_path::String)
# FFMPEG ~/.julia/packages/FFMPEG/aazvf/src/FFMPEG.jl:114
[3] (::JLLWrappers.var"#2#3"{FFMPEG.var"#4#6"{Cmd}, String})()
# JLLWrappers ~/.julia/packages/JLLWrappers/bkwIo/src/runtime.jl:49
[4] withenv(::JLLWrappers.var"#2#3"{FFMPEG.var"#4#6"{Cmd}, String}, ::Pair{String, String}, ::Vararg{Pair{String, String}, N} where N)
# Base ./env.jl:161
[5] withenv_executable_wrapper(f::Function, executable_path::String, PATH::String, LIBPATH::String, adjust_PATH::Bool, adjust_LIBPATH::Bool)
# JLLWrappers ~/.julia/packages/JLLWrappers/bkwIo/src/runtime.jl:48
[6] #invokelatest#2
# ./essentials.jl:708 [inlined]
[7] invokelatest
# ./essentials.jl:706 [inlined]
[8] #ffmpeg#7
# ~/.julia/packages/JLLWrappers/bkwIo/src/products/executable_generators.jl:7 [inlined]
[9] ffmpeg
# ~/.julia/packages/JLLWrappers/bkwIo/src/products/executable_generators.jl:7 [inlined]
[10] #exe#2
# ~/.julia/packages/FFMPEG/aazvf/src/FFMPEG.jl:113 [inlined]
[11] ffmpeg_exe
# ~/.julia/packages/FFMPEG/aazvf/src/FFMPEG.jl:125 [inlined]
[12] buildanimation(anim::Animation, fn::String, is_animated_gif::Bool; fps::Int64, loop::Int64, variable_palette::Bool, verbose::Bool, show_msg::Bool)
# Plots ~/.julia/packages/Plots/vVVub/src/animation.jl:98
[13] #gif#232
# ~/.julia/packages/Plots/vVVub/src/animation.jl:64 [inlined]
[14] top-level scope
# ~/Documents/Studium/Semester2/EM2/HW/01/animTest.jl:11
in expression starting at /home/olep/Documents/Studium/Semester2/EM2/HW/01/animTest.jl:11
I am on manjaro (Arch linux).
Any ideas what’s going wrong?
Manjaro:
Reinstall julia -> julia-bin
sudo pamac install julia-bin
my first time to ask stuff on stack-overflow, here in china i seldom able to meet any chef developer to talk about my problem so i am posting it here to seek for help. This issue has been bothering me for weeks and i am still trying to settle it.
here are my error msg:
* directory[/root/tools/projectname/../bootproxy] action create (up to date)
* template[/root/tools/projectname/../bootproxy/oc.proxy.conf] action create (up to date)
* directory[/root/tools/projectname/../bootproxy] action create (up to date)
* file[/tmp/dockerinfo.txt] action delete
- delete file /tmp/dockerinfo.txt
* bash[docker ps -a|grep -v CONTAINER|grep -v monitor|awk '{print $1, $NF}'] action run
- execute "bash" "/tmp/chef-script20170319-2107-fx41as"
* ruby_block[result] action run
- execute the ruby block result
* docker_container[bootproxy] action redeploy
- stopping bootproxy (will kill after 30s)
- deleting bootproxy
================================================================================
Error executing action redeploy on resource 'docker_container[bootproxy]'
================================================================================
Docker::Error::ServerError
--------------------------
Could not get container for bootproxy
Cookbook Trace:
---------------
/var/chef/cache/cookbooks/docker/libraries/docker_container.rb:319:in `block (3 levels) in <class:DockerContainer>'
/var/chef/cache/cookbooks/docker/libraries/helpers_base.rb:66:in `with_retries'
/var/chef/cache/cookbooks/docker/libraries/docker_container.rb:250:in `block (2 levels) in <class:DockerContainer>'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:81:in `converge_if_changed'
/var/chef/cache/cookbooks/docker/libraries/docker_container.rb:247:in `block in <class:DockerContainer>'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:132:in `instance_eval'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:132:in `compile_and_converge_action'
/var/chef/cache/cookbooks/docker/libraries/docker_container.rb:169:in `call_action'
/var/chef/cache/cookbooks/docker/libraries/docker_container.rb:360:in `block in <class:DockerContainer>'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:132:in `instance_eval'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:132:in `compile_and_converge_action'
/var/chef/cache/cookbooks/docker/libraries/docker_container.rb:169:in `call_action'
/var/chef/cache/cookbooks/docker/libraries/docker_container.rb:403:in `block in <class:DockerContainer>'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:132:in `instance_eval'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:132:in `compile_and_converge_action'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:78:in `run_action'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:106:in `block (2 levels) in converge'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:106:in `each'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:106:in `block in converge'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:105:in `converge'
Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/webserver/recipes/default.rb
218: docker_container container_name do
219: repo docker[:image]
220: tag docker[:tag]
221: #Add all docker link
222: # links node.set[:linking]
223: links lazy{node.run_state[:linking]}
224: env docker[:env]
225: command docker[:command]
226: kill_after 30
227: # autoremove true
228: action :redeploy
229: port docker[:ports]
230: volumes node.default["bindvolume"]
231: cap_add 'SYS_ADMIN'
232: devices []
233: privileged true
234: timeout 30
235: # {["/dev/fuse"]}
236: end
237: else
238: docker_container container_name do
239: repo docker[:image]
240: tag docker[:tag]
241: #Add all docker link
242: links node.run_state[:linking]
243: env docker[:env]
244: command docker[:command]
245: kill_after 30
246: # autoremove true
247: action :redeploy
248: port docker[:ports]
249: volumes node.default["bindvolume"]
250: cap_add 'SYS_ADMIN'
251: devices []
252: privileged true
253: timeout 30
254: # {["/dev/fuse"]}
255: end
256: end
257:
258: if (not (defined?(docker[:exec])).nil?) && (not "#{docker[:exec]}" == "")
259: execute 'execute command inside docker' do
260: command "docker exec -i #{container_name} /bin/bash -c \'#{docker[:exec]}\'"
261: end
262: end
263:
264: etchosts.push("#{container_name}:#{container_name}")
265: end
266:
267: #Add proxy.conf to folder if bootproxy defined
268: if defined?(node[:externalmode]) && node[:externalmode].eql?("bootproxy")
269: #Prepare bootproxy directories
270: directory "#{node[:deploycode][:basedirectory]}../bootproxy" do
Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/webserver/recipes/default.rb:218:in `block in from_file'
docker_container("bootproxy") do
action [:redeploy]
retries 0
retry_delay 2
default_guard_interpreter :default
declared_type :docker_container
cookbook_name "webserver"
recipe_name "default"
kill_after 30
repo "daocloud.io/library/nginx"
tag "stable-alpine"
exposed_ports {"80/tcp"=>{}, "5000/tcp"=>{}}
port_bindings {"80/tcp"=>[{"HostIp"=>"0.0.0.0", "HostPort"=>"80"}], "5000/tcp"=>[{"HostIp"=>"0.0.0.0", "HostPort"=>"5000"}]}
port ["80:80", "5000:5000"]
volumes_binds ["/root/tools/projectname/../bootproxy:/etc/nginx/conf.d/"]
links #<ChefCompat::CopiedFromChef::Chef::DelayedEvaluator:0x000000055c4a90#/var/chef/cache/cookbooks/webserver/recipes/default.rb:223>
cap_add ["SYS_ADMIN"]
privileged true
timeout 30
connection #<Docker::Connection:0x00000008301238 #url="unix:///", #options={:socket=>"/var/run/docker.sock", :read_timeout=>60}>
network_mode "bridge"
detach true
signal "SIGTERM"
end
Running handlers:
[2017-03-19T21:20:15+08:00] ERROR: Running exception handlers
Running handlers complete
[2017-03-19T21:20:15+08:00] ERROR: Exception handlers complete
Chef Client failed. 20 resources updated in 34 seconds
[2017-03-19T21:20:15+08:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2017-03-19T21:20:15+08:00] ERROR: docker_container[bootproxy] (webserver::default line 218) had an error: Docker::Error::ServerError: Could not get container for bootproxy
[2017-03-19T21:20:15+08:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
and here are my codes:
node.run_state[:linking] = []
#Special handling if bootproxy, get all local running docker id and name and link into bootproxy
if localfolder.eql?("bootproxy")
container_name = localfolder
node.set[:dockerinfo] = []
results = "/tmp/dockerinfo.txt"
file results do
action :delete
end
cmd = "docker ps -a|grep -v CONTAINER|grep -v monitor|awk \'{print $1, $NF}\'"
bash cmd do
code <<-EOH
#{cmd} > #{results}
EOH
end
ruby_block "result" do
only_if { "cat #{results}| wc -l;while [ $? -ne 0 ]; do cat #{results}| wc -l;done" }
# only_if { ::File.exists?(results) }
block do
f = File.open(results)
dockerinfo = Hash.new
f.each do |line|
dockerinfo[line.chomp.split(' ')[0]] = line.chomp.split(' ')[1]
end
f.close
node.set[:dockerinfo] = dockerinfo
node.run_state[:linking] = dockerinfo
node.run_state[:linking] = []
node.set[:dockerinfo].each do |hash, dockername|
node.run_state[:linking].push("#{dockername}:#{dockername}")
end
end
end
else
node.run_state[:linking] = etchosts
end
if node.default["bindvolume"].eql?([":"])
node.default["bindvolume"] = nil
end
if localfolder.eql?("bootproxy")
# Using lazy evaluation if bootproxy
docker_container container_name do
repo docker[:image]
tag docker[:tag]
#Add all docker link
# links node.set[:linking]
links lazy{node.run_state[:linking]}
env docker[:env]
command docker[:command]
kill_after 30
# autoremove true
action :redeploy
port docker[:ports]
volumes node.default["bindvolume"]
cap_add 'SYS_ADMIN'
devices []
privileged true
timeout 30
# {["/dev/fuse"]}
end
else
docker_container container_name do
repo docker[:image]
tag docker[:tag]
#Add all docker link
links node.run_state[:linking]
env docker[:env]
command docker[:command]
kill_after 30
# autoremove true
action :redeploy
port docker[:ports]
volumes node.default["bindvolume"]
cap_add 'SYS_ADMIN'
devices []
privileged true
timeout 30
# {["/dev/fuse"]}
end
end
What i am trying to do here, is to run a set of docker by chef docker cookbook version 2.14.3, with names looping into "localfolder", and when localfolder = "bootproxy", execute bash command to check what dockers are currently running and link them by a nginx docker named as "bootproxy".
My issue here is, whenever i cleared all my cache or after i have re-uploaded all my cookbook "webserver", chef-client runs fine without error. But when i rerun the chef-client, i got
Docker::Error::ServerError
--------------------------
Could not get container for bootproxy
due to the value of "links" in "docker_container" resources became "#" instead of an array that included the current running docker names like [ "container1:container1", "container2:container2", "container3:container3"]. So i suspect that the ruby_block that trying to get value from the host is being cached and not running after the first successive execution. My removal of cache (rm -rf /var/chef/cache) proved it but i cannot define removal of cache inside cookbook(not a neat way to work it out too). I need to make the chef-client able to rerun as i am using it to deploy my set of codes in the whole envionment. Please give me any advise for this.
Thanks!
I think you missed fixing the second resource, it isn't using the lazy{} helper.
Overall this code is kind of a mess so it's really hard to tell what it is doing in the first place. I recommend writing a lot of tests and maybe more comments.