Migrating from Drone.io

So, you’ve decided to try Codefresh? Welcome on board!

We’ll help you get up to speed with basic functionality such as: compiling, testing and building Docker images.

Repository

Fork this repository to compare the Drone and Codefresh.

Looking .drone.yml file

In the root of this repository you’ll find a file named .drone.yml this is Drone’s build descriptor and it describes the different steps that comprise general process (build, publish, notify, etc). Let’s quickly review the contents of this file:

.drone.yml

pipeline:
  build:
    image: node:latest
    environment:
      - DEBUG=*
    commands:
      - npm install
      - npm install -g mocha
      - npm install -g istanbul
      - npm install -g gulp
      - npm install -g debug

  publish:
    image: plugins/docker
    repo: demochat
    username: ${DOCKERHUB_USERNAME}
    password: ${DOCKERHUB_PASSWORD}
    tags: [ "latest", "1.0" ]
    when:
      branch: master
      event: push

  slack:
    image: plugins/slack
    webhook: https://hooks.slack.com/services/...
    channel: drone
    username: drone
    template: >
      *{{ build.status }}* <{{ build.link }}|{{ repo.owner }}/{{ repo.name }}#{{ build.commit }}> ({{ build.ref }}) by {{ build.author }}
    when:
      event: [ push, pull_request ]
      status: [ success, failure ]

The screen with processes of drone you can see below

codefresh_drone_processes.png

Looking codefresh.yml file

In this file, we will look at on build, freestyle, composition steps to see how to use them to build, test and deploy your repository. See more details about codefresh.yml steps here.

codefresh.yml

version: '1.0'
steps:

  build_step:
    type: build
    dockerfile: Dockerfile
    image-name: demochat
    tag: ${{CF_BRANCH}}

  unit_tests:
    image: ${{build_step}}
    fail-fast: false
    commands:
      - npm install
      - gulp test

  integration_step:
    type: composition
    composition:
      version: '2'
      services:
        app:
          image: ${{build_step}}
          links:
            - mongo
          ports:
            - 5000
        mongo:
          image: mongo
    composition-candidates:
      main:
        image: nhoag/curl
        command: bash -c "sleep 30 && curl http://app:5000/" | echo 'works'

  deploy_to_ecs:
      image: codefresh/cf-deploy-ecs
      commands:
        - cfecs-update --image-name demochat --image-tag ${{CF_BRANCH}} eu-west-1 demochat-cluster demochat-webapp
      environment:
        - AWS_ACCESS_KEY_ID=${{AWS_ACCESS_KEY_ID}}
        - AWS_SECRET_ACCESS_KEY=${{AWS_SECRET_ACCESS_KEY}}
      when:
        branch:
          only:
            - master

The screen with processes of Codefresh build you can see below

codefresh_processes.png

Compare steps of Drone vs Codefresh

Let’s take build and publish steps from .drone.yml and create the similar logic using codefresh.yml steps.

build step of .drone.yml

  build:
    image: node:latest
    environment:
      - DEBUG=*
    commands:
      - npm install
      - npm install -g mocha
      - npm install -g istanbul
      - npm install -g gulp
      - npm install -g debug

In build step of codefresh.yml we just use Dockerfile with defined commands to create your docker image.

Dockerfile

FROM node:latest
RUN mkdir -p /src
WORKDIR /src
COPY package.json /src/

RUN npm install
RUN npm install -g mocha
RUN npm install -g istanbul
RUN npm install -g gulp
RUN npm install -g debug

COPY . /src
ENV DEBUG=*
CMD ["npm", "start"]

build step of codefresh.yml

# codefresh.yml
  build_step:
    type: build
    dockerfile: Dockerfile
    image-name: demochat
    tag: ${{CF_BRANCH}}
Build step of codefresh.yml

More information about build step you can find here.

The publish step of .drone.yml in codefresh.yml can be look like push step

build step of codefresh.yml

push_to_dockerhub:
  type: push
  title: Step Title
  description: Free text description
  candidate: ${{build_step}}
  tag: latest
  credentials:
    username: ${DOCKERHUB_USERNAME}
    password: ${DOCKERHUB_PASSWORD}
  fail_fast: false
  when:
    branch:
      only: 
        - master
Push step of codefresh.yml

More information about push step you can find here.