github.com/henvic/wedeploycli@v1.7.6-0.20200319005353-3630f582f284/deployment/transport/README.md (about) 1 # Transport layer 2 The transport package contains code responsible for packing a deployment and sending it to Liferay Cloud. 3 4 There are two transports, currently: 5 6 * [git](https://git-scm.com) (stable) 7 * [gogit](https://github.com/src-d/go-git) (experimental, not stable) 8 9 In theory, *gogit* can replace git allowing the CLI tool to be independent of any external tools. However, gogit is still not [100% compatible](https://github.com/src-d/go-git/blob/master/COMPATIBILITY.md). 10 11 Once gogit is more stable, A/B testing can be used to verify if it works better than relying on a git external binary dependency. As of May, 2019 it is better to fail hard with an error message asking the user to install git instead of using a fallback strategy when git is not found. 12 13 ## Interface 14 15 ```go 16 // Transport for the deployment. 17 type Transport interface { 18 Setup(context.Context, transport.Settings) error 19 Init() error 20 ProcessIgnored() (map[string]struct{}, error) 21 Stage(services.ServiceInfoList) error 22 Commit(message string) (hash string, err error) 23 AddRemote() error 24 Push() (groupUID string, err error) 25 UploadDuration() time.Duration 26 UserAgent() string 27 } 28 ``` 29 30 ## Commands invoked by transport/git 31 32 1. git version 33 2. git init 34 3. git status --ignored --untracked-files=all --porcelain -- . 35 4. git config core.autocrlf false --local 36 5. git config core.safecrlf false --local 37 6. git config user.name "Liferay Cloud user" --local 38 7. git config user.email "user@deployment" --local 39 8. git config --add credential.helper "" 40 9. git config --add credential.helper :credential-helper 41 10. git add :src 42 11. git commit --no-verify --allow-empty --message :msg 43 12. git rev-parse HEAD 44 13. git remote add :remote-name :remote-address 45 14. git push :branch --force --no-verify 46 47 ### Deploying to the server 48 1. The user types `lcp deploy`. 49 2. CLI finds all `LCP.json` in the current directory and subdirectories. 50 3. Verify the Git version used. 51 4. Create a Git repo on a temporary directory, to not clash with any existing Git repo on user's service. 52 ```sh 53 $ git status --ignored --untracked-files=all --porcelain -- . // Get all ignored files 54 $ git config core.autocrlf false --local 55 $ git config core.safecrlf false --local 56 $ git config user.name "Liferay Cloud user" --local 57 $ git config user.email "user@deployment" --local 58 $ git config --add credential.helper "" 59 $ git config --add credential.helper :credential-helper 60 ``` 61 5. For all services (for every `LCP.json`) the following command is run: `git add :src` 62 6. We commit to Git using: 63 ```sh 64 $ git commit --no-verify --allow-empty --message :msg 65 $ git rev-parse HEAD // Get the SHA1 of the latest commit 66 ``` 67 7. We add the remote. The remote address is [discovered](https://github.com/henvic/wedeploycli/blob/7a00f6d2bfeec5e710f6790b24c1a2a442a6465c/deployment/transport/git/git.go#L349) via a common convention. The following command is used: 68 ```sh 69 $ git remote add :remote-name :remote-address 70 ``` 71 8. The code is then pushed to the server using: 72 ```sh 73 git push :branch --force --no-verify 74 ``` 75 76 _Note_: There is a [hack](https://github.com/henvic/wedeploycli/blob/7a00f6d2bfeec5e710f6790b24c1a2a442a6465c/deployment/transport/git/pushhack.go#L37) for Windows and some [versions](https://github.com/henvic/wedeploycli/blob/7a00f6d2bfeec5e710f6790b24c1a2a442a6465c/deployment/transport/git/pushhack.go#L24) of Git on pushing the code. 77 78 About 4). The command used was: 79 ```sh 80 $ lcp deploy --copy-pkg ./ 81 ``` 82 83 ```sh 84 ➜ test-hosting-dxpcloud git:(master) ✗ l 85 total 32 86 -rw-r--r--@ 1 iliyan staff 6.0K May 31 2018 .DS_Store 87 drwxr-xr-x 13 iliyan staff 416B May 22 16:03 .git 88 -rw-r--r-- 1 iliyan staff 85B May 10 15:13 LCP.json 89 -rw-r--r-- 1 iliyan staff 95B Jan 29 09:42 index.html 90 drwx------ 4 iliyan staff 128B May 22 16:01 myprj3-2019-05-22-16-01-28+0200 91 ➜ test-hosting-dxpcloud git:(master) ✗ cd myprj3-2019-05-22-16-01-28+0200 92 ➜ myprj3-2019-05-22-16-01-28+0200 git:(master) l 93 total 0 94 drwxr-xr-x 13 iliyan staff 416B May 22 16:03 .git 95 drwxr-xr-x 4 iliyan staff 128B May 22 16:01 test-hosting-dxpcloud 96 ➜ myprj3-2019-05-22-16-01-28+0200 git:(master) lcp deploy --copy-pkg ./ 97 ``` 98 99 100 ### Important information 101 * the status --ignored command is used to retrieve all files ignored by .gitignore files 102 * configs core.autocrlf and core.safecrlf are unset to avoid warnings regarding mixed [line endings](https://en.wikipedia.org/wiki/Newline) in files 103 * config user is set because a commit requires these values to be set 104 * the first call to credential.helper is used to bypass the use of any other credential helper in the project besides the one provided 105 * :credential-helper is `which lcp` appended with `git-credential-helper` 106 * :src is a path to a service 107 * on the commit command, the --no-verify flag bypasses any hooks 108 * :msg is a git commit message with a JSON specification (see package repodiscovery/tiny).