|
| 1 | +--- |
| 2 | +title:"Transferring Applications via FTP" |
| 3 | +description:"Deploying a Php Application to a VM using FTP" |
| 4 | +group:yaml-examples |
| 5 | +sub_group:examples |
| 6 | +toc:true |
| 7 | +--- |
| 8 | + |
| 9 | +##Prerequisites |
| 10 | + |
| 11 | +- A[free Codefresh account](https://codefresh.io/docs/docs/getting-started/create-a-codefresh-account/) |
| 12 | +- A remote machine with an ftp server and ssh setup (ensure that your ftp directory, I.e.,`/srv/ftp/pub` has the proper write permissions for the ftp user) |
| 13 | + |
| 14 | +>Note that as you may already know, FTP is extremely insecure as it relies on plain-text passwords and usernames, making data very vulnerable to sniffing. A more secure solution would be to use SFTP or SCP. |
| 15 | +
|
| 16 | +##The Example Php Project |
| 17 | + |
| 18 | +The example project can be found on[Github](https://github.com/anna-codefresh/php-composer-sample-app). The application is a simple Php application that displays an example timer. |
| 19 | + |
| 20 | +{% include image.html |
| 21 | +lightbox="true" |
| 22 | +file="/images/learn-by-example/php/test-environment.png" |
| 23 | +url="/images/learn-by-example/php/test-environment.png" |
| 24 | +alt="Example Php Application" |
| 25 | +caption="Example Php Application" |
| 26 | +max-width="90%" |
| 27 | +%} |
| 28 | + |
| 29 | +##Create the Pipeline |
| 30 | + |
| 31 | +Our pipeline will contain four stages: |
| 32 | + |
| 33 | +- A stage for cloning |
| 34 | +- A stage for packaging |
| 35 | +- A stage for transferring files |
| 36 | + |
| 37 | +{% include image.html |
| 38 | +lightbox="true" |
| 39 | +file="/images/examples/php-file-transfer/pipeline.png" |
| 40 | +url="/images/examples/php-file-transfer/pipeline.png" |
| 41 | +alt="Codefresh UI Pipeline View" |
| 42 | +caption="Codefresh UI Pipeline View" |
| 43 | +max-width="90%" |
| 44 | +%} |
| 45 | + |
| 46 | +Here is the entire pipeline: |
| 47 | + |
| 48 | +```yaml |
| 49 | +# More examples of Codefresh YAML can be found at |
| 50 | +# https://codefresh.io/docs/docs/yaml-examples/examples/ |
| 51 | + |
| 52 | +version:"1.0" |
| 53 | +# Stages can help you organize your steps in stages |
| 54 | +stages: |
| 55 | + -"clone" |
| 56 | + -"install" |
| 57 | + -"transfer" |
| 58 | +steps: |
| 59 | +clone: |
| 60 | +title:"Cloning main repository..." |
| 61 | +type:"git-clone" |
| 62 | +arguments: |
| 63 | +repo:"anna-codefresh/php-composer-sample-app" |
| 64 | +git:"github" |
| 65 | +stage:"clone" |
| 66 | +install_dependencies: |
| 67 | +title:"Collecting Php dependencies..." |
| 68 | +type:"freestyle" |
| 69 | +working_directory:"./php-composer-sample-app" |
| 70 | +arguments: |
| 71 | +image:"composer:1.9.3" |
| 72 | +commands: |
| 73 | + -"composer install --ignore-platform-reqs --no-interaction --no-plugins --no-scripts --prefer-dist" |
| 74 | +stage:"install" |
| 75 | +steps: |
| 76 | +ftp_transfer: |
| 77 | +title:"Transferring application to VM via ftp..." |
| 78 | +type:"freestyle" |
| 79 | +working_directory:"./php-composer-sample-app" |
| 80 | +arguments: |
| 81 | +image:"dockito/lftp-client:latest" |
| 82 | +environment: |
| 83 | + -USER=<USER> |
| 84 | + -PASSWORD=<PASSWORD> |
| 85 | + -HOST=<HOST> |
| 86 | + -PUB_FTP_DIR=<PATH/TO/DIR> |
| 87 | +commands: |
| 88 | + -lftp -u $USER,$PASSWORD -e "cd $PUB_FTP_DIR; mkdir php-composer-sample-app; cd php-composer-sample-app; mput "*.*"; bye" $HOST |
| 89 | +stage:"transfer" |
| 90 | +``` |
| 91 | +This pipeline does the following: |
| 92 | +
|
| 93 | +1. A [git-clone]({{$site.baseurl}}/docs/codefresh-yaml/steps/git-clone/) step that clones the main repository |
| 94 | +2. A [freestyle step]($$site.baseurl}}/docs/codefresh-yaml/steps/freestyle/) that installs the necessary Php dependencies for our application |
| 95 | +3. A freestyle step that transfers our application via ftp |
| 96 | +
|
| 97 | +## What to Read Next |
| 98 | +
|
| 99 | +- [Codefresh YAML]({{site.baseurl}}/docs/codefresh-yaml/what-is-the-codefresh-yaml/) |
| 100 | +- [Git-clone Step]({{$site.baseurl}}/docs/codefresh-yaml/steps/git-clone/) |
| 101 | +- [Freestyle Step]($$site.baseurl}}/docs/codefresh-yaml/steps/freestyle/) |
| 102 | +
|
| 103 | +
|