Skip to content

Commit a70ee71

Browse files
authored
feat: allow users to specify files to include in the slug (#6)
1 parent 6a3769b commit a70ee71

File tree

4 files changed

+118
-0
lines changed

4 files changed

+118
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ To use this, see https://gigalixir.readthedocs.io/en/latest/modify-app/releases.
1515
* Easy configuration with `releases_buildpack.config` file
1616
* Easy configuration with `GIGALIXIR_RELEASES_BUILDPACK_CONFIG` environment variable.
1717
* Support for umbrella app compilation through `app_relative_path` configuration.
18+
* Support for adding files to the release through `.gigalixir/releases/includes.txt` file.
1819

1920

2021

@@ -40,6 +41,28 @@ Configuration options are applied in the following order:
4041

4142

4243

44+
## Adding files to the release
45+
46+
To add files to the release, create a `.gigalixir/releases/includes.txt`.
47+
The file follows the `rsync` --include-from syntax.
48+
49+
For example:
50+
```
51+
# include a specific file
52+
/priv/ssl_certificate.pem
53+
54+
# include all files in a directory
55+
/priv/dir/*
56+
57+
# include all files in a directory and its subdirectories
58+
/priv/tree/**
59+
```
60+
61+
Matching files will be available in the `/app` folder at runtime.
62+
Empty directories will be pruned.
63+
64+
65+
4366
## Tests
4467

4568
Tests are available in the [test](test) directory.

bin/compile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ if [ -f .profile.d/phoenix_static_buildpack_env.sh ]; then
6262
cp .profile.d/phoenix_static_buildpack_env.sh _build/${RELEASE_ENV}/rel/$APP/.profile.d/
6363
fi
6464

65+
copy_static_files "_build/${RELEASE_ENV}/rel/${APP}"
66+
6567
# create tarball
6668
mkdir -p $cache_dir/out
6769
rm -f $cache_dir/out/*

lib/build.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,18 @@ output_section() {
7676
delete_broken_symlinks() {
7777
find "$1" -xtype l -delete > /dev/null
7878
}
79+
80+
copy_static_files() {
81+
local dst_dir="$1/"
82+
local includes_path="${build_dir}/.gigalixir/releases/includes.txt"
83+
84+
if [ -f "${includes_path}" ]; then
85+
output_line ".gigalixir/releases/includes.txt file found"
86+
output_section "Copying files to include in the release"
87+
88+
rsync -av \
89+
--include='*/' --include-from="${includes_path}" --exclude='*' \
90+
--prune-empty-dirs --ignore-existing \
91+
"${build_dir}/" "${dst_dir}"
92+
fi
93+
}

test/copy_static_files.sh

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
6+
source $SCRIPT_DIR/.test_support.sh
7+
8+
# include source file
9+
source $SCRIPT_DIR/../lib/build.sh
10+
11+
# override functions
12+
output_line() {
13+
/bin/true
14+
}
15+
output_section() {
16+
/bin/true
17+
}
18+
19+
# TESTS
20+
######################
21+
suite "copy_static_files()"
22+
23+
24+
test "no include file exists"
25+
mkdir -p "${build_dir}/dir1" "${build_dir}/dir2/dir3"
26+
touch "${build_dir}/file0"
27+
touch "${build_dir}/dir1/file1"
28+
touch "${build_dir}/dir2/file2"
29+
touch "${build_dir}/dir2/dir3/file3"
30+
31+
copy_static_files "${build_dir}/copy"
32+
33+
[ ! -d "${build_dir}/copy/dir1" ]
34+
[ ! -d "${build_dir}/copy/dir2" ]
35+
[ ! -f "${build_dir}/copy/file0" ]
36+
37+
test "syncs files in pattern match"
38+
mkdir -p "${build_dir}/.gigalixir/releases"
39+
/bin/echo "file0" > "${build_dir}/.gigalixir/releases/includes.txt"
40+
41+
copy_static_files "${build_dir}/copy" > /dev/null
42+
43+
[ ! -d "${build_dir}/copy/dir1" ]
44+
[ ! -d "${build_dir}/copy/dir2" ]
45+
[ -f "${build_dir}/copy/file0" ]
46+
rm -rf "${build_dir}/copy"
47+
48+
test "testing pattern glob"
49+
/bin/echo "dir2/**" > "${build_dir}/.gigalixir/releases/includes.txt"
50+
51+
copy_static_files "${build_dir}/copy" > /dev/null
52+
53+
[ ! -d "${build_dir}/copy/dir1" ]
54+
[ -f "${build_dir}/copy/dir2/file2" ]
55+
[ -f "${build_dir}/copy/dir2/dir3/file3" ]
56+
[ ! -f "${build_dir}/copy/file0" ]
57+
rm -rf "${build_dir}/copy/dir2"
58+
59+
test "testing pattern match"
60+
/bin/echo "dir2/*" > "${build_dir}/.gigalixir/releases/includes.txt"
61+
62+
copy_static_files "${build_dir}/copy" > /dev/null
63+
64+
[ ! -d "${build_dir}/copy/dir1" ]
65+
[ -f "${build_dir}/copy/dir2/file2" ]
66+
[ ! -d "${build_dir}/copy/dir2/dir3" ]
67+
[ ! -f "${build_dir}/copy/file0" ]
68+
69+
test "does not overwrite files"
70+
/bin/echo "asdf" > "${build_dir}/dir2/file2"
71+
72+
copy_static_files "${build_dir}/copy" > /dev/null
73+
74+
grep -q "asdf" "${build_dir}/copy/dir2/file2" && false
75+
76+
77+
78+
PASSED_ALL_TESTS=true

0 commit comments

Comments
 (0)