The build dev command warns about untracked and uncommitted files
so there's a complete picture of what is being packaged that's not in git.
This commit is contained in:
@@ -116,9 +116,22 @@ class Kamal::Cli::Build < Kamal::Cli::Base
|
|||||||
|
|
||||||
ensure_docker_installed
|
ensure_docker_installed
|
||||||
|
|
||||||
uncommitted_changes = Kamal::Git.uncommitted_changes
|
docker_included_files = Set.new(Kamal::Docker.included_files)
|
||||||
if uncommitted_changes.present?
|
git_uncommitted_files = Set.new(Kamal::Git.uncommitted_files)
|
||||||
say "WARNING: building with uncommitted changes:\n #{uncommitted_changes}", :yellow
|
git_untracked_files = Set.new(Kamal::Git.untracked_files)
|
||||||
|
|
||||||
|
docker_uncommitted_files = docker_included_files & git_uncommitted_files
|
||||||
|
if docker_uncommitted_files.any?
|
||||||
|
say "WARNING: Files with uncommitted changes will be present in the dev container:", :yellow
|
||||||
|
docker_uncommitted_files.sort.each { |f| say " #{f}", :yellow }
|
||||||
|
say
|
||||||
|
end
|
||||||
|
|
||||||
|
docker_untracked_files = docker_included_files & git_untracked_files
|
||||||
|
if docker_untracked_files.any?
|
||||||
|
say "WARNING: Untracked files will be present in the dev container:", :yellow
|
||||||
|
docker_untracked_files.sort.each { |f| say " #{f}", :yellow }
|
||||||
|
say
|
||||||
end
|
end
|
||||||
|
|
||||||
with_env(KAMAL.config.builder.secrets) do
|
with_env(KAMAL.config.builder.secrets) do
|
||||||
|
|||||||
30
lib/kamal/docker.rb
Normal file
30
lib/kamal/docker.rb
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
require "tempfile"
|
||||||
|
require "open3"
|
||||||
|
|
||||||
|
module Kamal::Docker
|
||||||
|
extend self
|
||||||
|
BUILD_CHECK_TAG = "kamal-local-build-check"
|
||||||
|
|
||||||
|
def included_files
|
||||||
|
Tempfile.create do |dockerfile|
|
||||||
|
dockerfile.write(<<~DOCKERFILE)
|
||||||
|
FROM busybox
|
||||||
|
COPY . app
|
||||||
|
WORKDIR app
|
||||||
|
CMD find . -type f | sed "s|^\./||"
|
||||||
|
DOCKERFILE
|
||||||
|
dockerfile.close
|
||||||
|
|
||||||
|
cmd = "docker buildx build -t=#{BUILD_CHECK_TAG} -f=#{dockerfile.path} ."
|
||||||
|
system(cmd) || raise("failed to build check image")
|
||||||
|
end
|
||||||
|
|
||||||
|
cmd = "docker run --rm #{BUILD_CHECK_TAG}"
|
||||||
|
out, err, status = Open3.capture3(cmd)
|
||||||
|
unless status
|
||||||
|
raise "failed to run check image:\n#{err}"
|
||||||
|
end
|
||||||
|
|
||||||
|
out.lines.map(&:strip)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -24,4 +24,14 @@ module Kamal::Git
|
|||||||
def root
|
def root
|
||||||
`git rev-parse --show-toplevel`.strip
|
`git rev-parse --show-toplevel`.strip
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# returns an array of relative path names of files with uncommitted changes
|
||||||
|
def uncommitted_files
|
||||||
|
`git ls-files --modified`.lines.map(&:strip)
|
||||||
|
end
|
||||||
|
|
||||||
|
# returns an array of relative path names of untracked files, including gitignored files
|
||||||
|
def untracked_files
|
||||||
|
`git ls-files --others`.lines.map(&:strip)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user