Skip to content

Commit bf80c8c

Browse files
committed
feat: support custom git config
This allows for, among other things, mapping URLs to provide authentication for private repos.
1 parent fa9ac03 commit bf80c8c

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,28 @@ custom:
6666
With `Dockerfile` the path to the Dockerfile that must be in the current folder (or a subfolder).
6767
Please note the `dockerImage` and the `dockerFile` are mutually exclusive.
6868

69+
To install requirements with custom git settings (e.g., to map private repositories with
70+
authentication parameters), add the following to your `serverless.yml`:
71+
72+
```yaml
73+
custom:
74+
pythonRequirements:
75+
dockerizePip: true
76+
dockerGit: true
77+
```
78+
79+
The `dockerGit` option will mount your `$HOME/.gitconfig` as a volume in the docker container.
80+
81+
In case you want to use a different git configuration, you can specify the path (absolute) to it through `dockerGitConfig` option:
82+
83+
```yaml
84+
custom:
85+
pythonRequirements:
86+
dockerizePip: true
87+
dockerGit: true
88+
dockerGitConfig: /home/.git/config
89+
```
90+
6991
To install requirements from private git repositories, add the following to your `serverless.yml`:
7092

7193
```yaml

lib/pip.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,17 @@ async function installRequirements(targetFolder, pluginInstance, funcOptions) {
286286
);
287287
}
288288

289+
if (options.dockerGit) {
290+
const homePath = require('os').homedir();
291+
const gitConfigPath = options.dockerGitConfig || `${homePath}/.gitconfig`;
292+
293+
// Mount necessary git files to work with private repos
294+
dockerCmd.push(
295+
'-v',
296+
`${gitConfigPath}:/root/.gitconfig:z`
297+
);
298+
}
299+
289300
// If we want a download cache...
290301
const dockerDownloadCacheDir = '/var/useDownloadCache';
291302
if (options.useDownloadCache) {

test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,32 @@ test(
223223
{ skip: !canUseDocker() || brokenOn('win32') }
224224
);
225225

226+
test(
227+
'dockerGitConfig option correctly resolves docker command',
228+
async (t) => {
229+
process.chdir('tests/base');
230+
const path = npm(['pack', '../..']);
231+
npm(['i', path]);
232+
const stdout = sls(['package'], {
233+
noThrow: true,
234+
env: {
235+
dockerizePip: true,
236+
dockerGit: true,
237+
dockerGitConfig: `${__dirname}${sep}tests${sep}base${sep}custom_gitconfig`,
238+
dockerImage: 'break the build to log the command',
239+
},
240+
});
241+
t.true(
242+
stdout.includes(
243+
`-v ${__dirname}${sep}tests${sep}base${sep}custom_gitconfig:/root/.gitconfig:z`
244+
),
245+
'docker command properly resolved'
246+
);
247+
t.end();
248+
},
249+
{ skip: !canUseDocker() || brokenOn('win32') }
250+
)
251+
226252
test('default pythonBin can package flask with default options', async (t) => {
227253
process.chdir('tests/base');
228254
const path = npm(['pack', '../..']);

0 commit comments

Comments
 (0)