Follow Symbolic Links for Artifact Paths
<!--IssueSummary start-->
<details>
<summary>
Everyone can contribute. [Help move this issue forward](https://handbook.gitlab.com/handbook/marketing/developer-relations/contributor-success/community-contributors-workflows/#contributor-links) while earning points, leveling up and collecting rewards.
</summary>
- [Close this issue](https://contributors.gitlab.com/manage-issue?action=close&projectId=278964&issueIid=19746)
</details>
<!--IssueSummary end-->
### Summary
The output of my build just happens to be in /foo. I realize that mostly everything in the gitlab runner is done in the PWD (e.g. /home/gitlab-runner/builds) which most likely does not correspond to /foo.
Users should be able to use the following YAML snippet to create an archive rather than first copying the files into the PWD.
Why? COPYING IS *BAAAAAAAAAD* (i.e. it is unnecessarily time / space consuming). Follow symbolic links!!!
### Steps to reproduce
```yaml
image: ubuntu:xenial
stages:
- build
do_build:
stage: build
script:
- mkdir /foo
- touch /foo/bar.txt
- ln -sf /foo foo
artifacts:
paths
- foo/
```
### Example Project
### What is the current *bug* behavior?
artifacts.zip is empty
### What is the expected *correct* behavior?
artifacts.zip should contain entry "foo/bar.txt"
### Relevant logs and/or screenshots
```
WARNING: foo/: no matching files
```
#### Results of GitLab environment info
<details>
<summary>Expand for output related to GitLab environment info</summary>
<pre>
System information
System:
Current User: git
Using RVM: no
Ruby Version: 2.3.3p222
Gem Version: 2.6.6
Bundler Version:1.13.7
Rake Version: 12.0.0
Redis Version: 3.2.5
Git Version: 2.13.5
Sidekiq Version:5.0.4
Go Version: unknown
GitLab information
Version: 9.5.4
Revision: fbffc27
Directory: /opt/gitlab/embedded/service/gitlab-rails
DB Adapter: postgresql
URL: https://example.com
HTTP Clone URL: https://example.com/some-group/some-project.git
SSH Clone URL: git@example.com:some-group/some-project.git
Using LDAP: no
Using Omniauth: no
GitLab Shell
Version: 5.8.0
Repository storage paths:
- default: /var/opt/gitlab/git-data/repositories
Hooks: /opt/gitlab/embedded/service/gitlab-shell/hooks
Git: /opt/gitlab/embedded/bin/git
</pre>
</details>
#### Results of GitLab application Check
<details>
<summary>Expand for output related to the GitLab application check</summary>
<pre>
Checking GitLab Shell ...
GitLab Shell version >= 5.8.0 ? ... OK (5.8.0)
Repo base directory exists?
default... yes
Repo storage directories are symlinks?
default... no
Repo paths owned by git:root, or git:git?
default... yes
Repo paths access is drwxrws---?
default... yes
hooks directories in repos are links: ...
9/6 ... ok
9/7 ... ok
10/8 ... ok
2/10 ... ok
10/11 ... ok
2/12 ... ok
2/13 ... ok
10/14 ... ok
2/15 ... ok
2/17 ... ok
9/21 ... ok
Running /opt/gitlab/embedded/service/gitlab-shell/bin/check
Check GitLab API access: OK
Access to /var/opt/gitlab/.ssh/authorized_keys: OK
Send ping to redis server: OK
gitlab-shell self-check successful
Checking GitLab Shell ... Finished
Checking Sidekiq ...
Running? ... yes
Number of Sidekiq processes ... 1
Checking Sidekiq ... Finished
Checking Reply by email ...
Reply by email is disabled in config/gitlab.yml
Checking Reply by email ... Finished
Checking LDAP ...
LDAP is disabled in config/gitlab.yml
Checking LDAP ... Finished
Checking GitLab ...
Git configured correctly? ... yes
Database config exists? ... yes
All migrations up? ... yes
Database contains orphaned GroupMembers? ... no
GitLab config exists? ... yes
GitLab config up to date? ... yes
Log directory writable? ... yes
Tmp directory writable? ... yes
Uploads directory exists? ... yes
Uploads directory has correct permissions? ... yes
Uploads directory tmp has correct permissions? ... skipped (no tmp uploads folder yet)
Init script exists? ... skipped (omnibus-gitlab has no init script)
Init script up-to-date? ... skipped (omnibus-gitlab has no init script)
Projects have namespace: ...
9/6 ... yes
9/7 ... yes
10/8 ... yes
2/10 ... yes
10/11 ... yes
2/12 ... yes
2/13 ... yes
10/14 ... yes
2/15 ... yes
2/17 ... yes
9/21 ... yes
Redis version >= 2.8.0? ... yes
Ruby version >= 2.3.3 ? ... yes (2.3.3)
Git version >= 2.7.3 ? ... yes (2.13.5)
Active users: ... 3
Checking GitLab ... Finished
</pre>
</details>
### Possible fixes
The error exists somewhere in zip_create.go
https://gitlab.com/gitlab-org/gitlab-runner/blob/master/helpers/archives/zip_create.go#L25
It looks as though current checks to attempt to see if the file is a symlink, but it assumes that the target of the link is a regular file. Realistically, the target of the link could be another link, or a directory, a regular file, or a "special" file (e.g. a. pipe, character device, block device, etc) and we need to have reasonable actions to take in each of those cases. The simplest solution would be to use a recursive function and to pass in the depth of the recursion. Of course, we do not want the recursion to go on indefinitely, so maybe limit the maximum depth to something like 1024.
It might also be wise to consider a special case (namely, the one I am complaining about), when the recursion depth is zero and the target is a symlink'ed directory, just so we don't pull in the entire filesystem by accident.
Also, I vaguely remember that with some versions of zip symbolic links are not supported. They seem to work now in Linux at least.
issue