|
| 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 | +redirect_from: |
| 8 | + -/docs//learn-by-example/java/spring-mvc-jdbc-template/ |
| 9 | +--- |
| 10 | + |
| 11 | +##Prerequisites |
| 12 | + |
| 13 | +- A[free Codefresh account](https://codefresh.io/docs/docs/getting-started/create-a-codefresh-account/) |
| 14 | +- 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) |
| 15 | + |
| 16 | +>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. |
| 17 | +
|
| 18 | +##The Example Php Project |
| 19 | + |
| 20 | +The example project can be found on[Github](hhttps://github.com/codefresh-contrib/ftp-php-app). The application is a simple Php application that displays an example timer. |
| 21 | + |
| 22 | +{% include image.html |
| 23 | +lightbox="true" |
| 24 | +file="/images/learn-by-example/php/test-environment.png" |
| 25 | +url="/images/learn-by-example/php/test-environment.png" |
| 26 | +alt="Example Php Application" |
| 27 | +caption="Example Php Application" |
| 28 | +max-width="90%" |
| 29 | +%} |
| 30 | + |
| 31 | +##Create the Pipeline |
| 32 | + |
| 33 | +Our pipeline will contain four stages: |
| 34 | + |
| 35 | +- A stage for cloning |
| 36 | +- A stage for packaging |
| 37 | +- A stage for transferring files |
| 38 | + |
| 39 | +{% include image.html |
| 40 | +lightbox="true" |
| 41 | +file="/images/examples/php-file-transfer/pipeline.png" |
| 42 | +url="/images/examples/php-file-transfer/pipeline.png" |
| 43 | +alt="Codefresh UI Pipeline View" |
| 44 | +caption="Codefresh UI Pipeline View" |
| 45 | +max-width="90%" |
| 46 | +%} |
| 47 | + |
| 48 | +Here is the entire pipeline: |
| 49 | + |
| 50 | +```yaml |
| 51 | +# More examples of Codefresh YAML can be found at |
| 52 | +# https://codefresh.io/docs/docs/yaml-examples/examples/ |
| 53 | + |
| 54 | +version:"1.0" |
| 55 | +# Stages can help you organize your steps in stages |
| 56 | +stages: |
| 57 | + -"clone" |
| 58 | + -"install" |
| 59 | + -"transfer" |
| 60 | +steps: |
| 61 | +clone: |
| 62 | +title:"Cloning main repository..." |
| 63 | +type:"git-clone" |
| 64 | +arguments: |
| 65 | +repo:"codefresh-contrib/ftp-php-app" |
| 66 | +git:"github" |
| 67 | +stage:"clone" |
| 68 | +install_dependencies: |
| 69 | +title:"Collecting Php dependencies..." |
| 70 | +type:"freestyle" |
| 71 | +working_directory:"./ftp-php-app" |
| 72 | +arguments: |
| 73 | +image:"composer:1.9.3" |
| 74 | +commands: |
| 75 | + -"composer install --ignore-platform-reqs --no-interaction --no-plugins --no-scripts --prefer-dist" |
| 76 | +stage:"install" |
| 77 | +steps: |
| 78 | +ftp_transfer: |
| 79 | +title:"Transferring application to VM via ftp..." |
| 80 | +type:"freestyle" |
| 81 | +working_directory:"./ftp-php-app" |
| 82 | +arguments: |
| 83 | +image:"dockito/lftp-client:latest" |
| 84 | +environment: |
| 85 | + -USER=<USER> |
| 86 | + -PASSWORD=<PASSWORD> |
| 87 | + -HOST=<HOST> |
| 88 | + -PUB_FTP_DIR=<PATH/TO/DIR> |
| 89 | +commands: |
| 90 | + -lftp -e "set ftp:use-site-utime2 false; mirror -x ^\.git/$ -X flat-logo.png -p -R ftp-php-ap $PUB_FTP_DIR/ftp-php-app; exit" -u $USER,$PASSWORD $HOST |
| 91 | +stage:"transfer" |
| 92 | +``` |
| 93 | +This pipeline does the following: |
| 94 | +
|
| 95 | +1. A [git-clone]({{$site.baseurl}}/docs/codefresh-yaml/steps/git-clone/) step that clones the main repository |
| 96 | +2. A [freestyle step]($$site.baseurl}}/docs/codefresh-yaml/steps/freestyle/) that installs the necessary Php dependencies for our application |
| 97 | +3. A freestyle step that transfers our application via ftp. Note that you will need to change the environment variables to your respective values, either in the YAML itself (above), or through the pipeline settings: |
| 98 | +
|
| 99 | +{% include image.html |
| 100 | +lightbox="true" |
| 101 | +file="/images/examples/php-file-transfer/variables.png" |
| 102 | +url="/images/examples/php-file-transfer/variables.png" |
| 103 | +alt="Codefresh Enbironment Variables" |
| 104 | +caption="Codefresh Enbironment Variables" |
| 105 | +max-width="90%" |
| 106 | +%} |
| 107 | +
|
| 108 | +## What to Read Next |
| 109 | +
|
| 110 | +- [Codefresh YAML]({{site.baseurl}}/docs/codefresh-yaml/what-is-the-codefresh-yaml/) |
| 111 | +- [Git-clone Step]({{$site.baseurl}}/docs/codefresh-yaml/steps/git-clone/) |
| 112 | +- [Freestyle Step]($$site.baseurl}}/docs/codefresh-yaml/steps/freestyle/) |
| 113 | +
|
| 114 | +
|