Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support .slugignore #9

Closed
CGA1123 opened this issue Aug 16, 2021 · 4 comments · Fixed by #18
Closed

Support .slugignore #9

CGA1123 opened this issue Aug 16, 2021 · 4 comments · Fixed by #18
Assignees

Comments

@CGA1123
Copy link
Owner

CGA1123 commented Aug 16, 2021

.slugignore files can be used to nuke a bunch of files/folders from the final slug, making it smaller.

See: https://devcenter.heroku.com/articles/slug-compiler#ignoring-files-with-slugignore

Should be feasible by using the Skip options in https://pkg.go.dev/github.com/otiai10/copy#Options

@CGA1123 CGA1123 self-assigned this Aug 18, 2021
@CGA1123
Copy link
Owner Author

CGA1123 commented Aug 18, 2021

Also, should remember to update the README to reflect this (removing the TODO)

@CGA1123
Copy link
Owner Author

CGA1123 commented Aug 18, 2021

https://github.com/denormal/go-gitignore < this should be useful

@CGA1123
Copy link
Owner Author

CGA1123 commented Aug 18, 2021

alternatively: https://github.com/sabhiram/go-gitignore

i've tried both out, but they both seem to be missing some edge cases from some rough testing 😞

Not sure if I want to implement my own .slugignore parser? Would need to come up with some sensible examples to test against 🤔

Heroku doesn't support the ! operator that gitignore does, but they don't go into much more detail about what else is/isn't support which isn't ideal!

@CGA1123
Copy link
Owner Author

CGA1123 commented Aug 18, 2021

CGA1123 added a commit that referenced this issue Aug 20, 2021
Closes: #9 

Adds support for `.slugignore` files. `prepare` will now only copy files which do not match any entry in the `.slugignore` file for a given `source-dir`.

The logic is intended to follow logic similar to [this](https://github.com/heroku/slug-compiler/blob/68b63a30907f171e60f8398463d6bbd13b4ed178/lib/slug_compiler.rb#L131-L152):

```ruby
      lines = File.read(slugignore_path).split
      total = lines.inject(0) do |total, line|
        line = (line.split(/#/).first || "").strip
        if line.empty?
          total
        else
          globs = if line =~ /\//
                    [File.join(build_dir, line)]
                  else
                    # 1.8.7 and 1.9.2 handle expanding ** differently,
                    # where in 1.9.2 ** doesn't match the empty case. So
                    # try empty ** explicitly
                    ["", "**"].map { |g| File.join(build_dir, g, line) }
                  end

          to_delete = Dir[*globs].uniq.map { |p| File.expand_path(p) }
          to_delete = to_delete.select { |p| p.match(/^#{build_dir}/) }
          to_delete.each { |p| FileUtils.rm_rf(p) }
          total + to_delete.size
        end
      end
```

Which as far as I can tell has not changes since Heroku closed-source their compiler, which can be verified by extracting the builder source from Heroku via a custom buildpack.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant