Transferring Applications via FTP

Deploying a Php Application to a VM using FTP

Prerequisites

  • A free Codefresh account
  • 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)

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.

The Example Php Project

The example project can be found on GitHub. The application is a simple Php application that displays an example timer.

Example Php Application

Example Php Application

Create the Pipeline

Our pipeline will contain four stages:

  • A stage for cloning
  • A stage for packaging
  • A stage for transferring files

Codefresh UI Pipeline View

Codefresh UI Pipeline View

Here is the entire pipeline:

codefresh.yml

# More examples of Codefresh YAML can be found at
# https://codefresh.io/docs/docs/yaml-examples/examples/

version: "1.0"
# Stages can help you organize your steps in stages
stages:
  - "clone"
  - "install"
  - "transfer"
steps:
  clone:
    title: "Cloning main repository..."
    type: "git-clone"
    arguments:
      repo: "codefresh-contrib/ftp-php-app"
      git: "github"
    stage: "clone"
  install_dependencies:
    title: "Collecting Php dependencies..."
    type: "freestyle"
    working_directory: "./ftp-php-app"
    arguments:
      image: "composer:1.9.3"
      commands:
        - "composer install --ignore-platform-reqs --no-interaction --no-plugins --no-scripts --prefer-dist"
    stage: "install"
  steps:
    ftp_transfer:
    title: "Transferring application to VM via ftp..."
    type: "freestyle" 
    working_directory: "./ftp-php-app"
    arguments:
      image: "dockito/lftp-client:latest"
      environment:
        - USER=<USER>
        - PASSWORD=<PASSWORD>
        - HOST=<HOST>
        - PUB_FTP_DIR=<PATH/TO/DIR>
      commands:
        - 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
    stage: "transfer"

This pipeline does the following:

  1. A git-clone step that clones the main repository
  2. A freestyle step that installs the necessary Php dependencies for our application
  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:

Codefresh Enbironment Variables

Codefresh Enbironment Variables