Skip to content

Instantly share code, notes, and snippets.

@arehmandev
Forked from d0x2f/.drone.yml
Created January 28, 2018 12:09
Show Gist options
  • Save arehmandev/a0bfd7ba2d49215b69bc2480e8a25f5d to your computer and use it in GitHub Desktop.
Save arehmandev/a0bfd7ba2d49215b69bc2480e8a25f5d to your computer and use it in GitHub Desktop.

Revisions

  1. @d0x2f d0x2f revised this gist Jan 28, 2018. 1 changed file with 32 additions and 4 deletions.
    36 changes: 32 additions & 4 deletions .drone.yml
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,11 @@ pipeline:
    build-image:
    image: docker
    commands:
    - docker build . --target development -t api-build:${DRONE_BUILD_NUMBER}
    # Build development target, which includes xdebug.
    # Tag with both api-build:<build_number> and api-build:latest.
    # The <build_number> tag will be removed after the build
    # and the latest tag will stay as a cache.
    - docker build . --target development -t api-build:${DRONE_BUILD_NUMBER} -t api-build:latest
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock

    @@ -19,7 +23,9 @@ pipeline:
    - DATABASE_HOST=mysql
    - DATABASE_NAME=(snip)
    commands:
    # Wait for the mysql service to be ready.
    - while (! mysqladmin ping -hmysql --silent); do sleep 1; done
    # Seed database with initial data.
    - composer run seed-db

    build:
    @@ -28,6 +34,7 @@ pipeline:
    volumes:
    - composer-cache:/root/.composer
    commands:
    # Install dependencies.
    - composer install --no-interaction --no-progress --no-suggest

    generate-swagger:
    @@ -38,6 +45,7 @@ pipeline:
    - DATABASE_HOST=mysql
    - DATABASE_NAME=(snip)
    commands:
    # Generate swagger.json.
    - composer run swagger-generate

    validate-swagger:
    @@ -46,6 +54,7 @@ pipeline:
    volumes:
    - npm-cache:/root/.npm
    commands:
    # Install swagger validator and validate swagger.json
    - "npm install -g swagger-cli"
    - "swagger-cli validate ./swagger.json"

    @@ -67,8 +76,11 @@ pipeline:
    - source: meraki_api_key
    target: MERAKI_API_KEY
    commands:
    # This php.ini contains settings to disable html_errors and to enable apcu for cli.
    - cp container/php.ini /etc/php7/php.ini
    # The tests read the meraki key from a file.
    - echo $MERAKI_API_KEY > tests/meraki_api_key.txt
    # Run the tests.
    - composer run test

    sonarqube:
    @@ -99,8 +111,13 @@ pipeline:
    image: docker
    group: parallel-3
    commands:
    - docker tag api-build:${DRONE_BUILD_NUMBER} registry.(snip):5000/api:latest
    - docker push registry.(snip):5000/api:latest
    # Build production image, which includes the code and without xdebug.
    - docker build . --target production -t registry.(snip)/api:latest
    # Build the nginx proxy image.
    - docker build ./nginx -t registry.(snip)/api-nginx:latest
    # Publish both to the registry
    - docker push registry.(snip)/api:latest
    - docker push registry.(snip)/api-nginx:latest
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    when:
    @@ -109,9 +126,20 @@ pipeline:
    status:
    - success

    delete-build-image:
    image: docker
    commands:
    # Delete the build image.
    - docker rmi api-build:${DRONE_BUILD_NUMBER}
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    when:
    status:
    - success
    - failure

    slack:
    image: plugins/slack
    group: parallel-3
    webhook: https://hooks.slack.com/services/(snip)
    channel: ci
    when:
  2. @d0x2f d0x2f renamed this gist Jan 27, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. @d0x2f d0x2f created this gist Jan 27, 2018.
    127 changes: 127 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,127 @@
    workspace:
    base: /build

    pipeline:

    build-image:
    image: docker
    commands:
    - docker build . --target development -t api-build:${DRONE_BUILD_NUMBER}
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock

    seed-db:
    image: "api-build:${DRONE_BUILD_NUMBER}"
    group: parallel-1
    environment:
    - DATABASE_USER=root
    - DATABASE_PASSWORD=msyql
    - DATABASE_HOST=mysql
    - DATABASE_NAME=(snip)
    commands:
    - while (! mysqladmin ping -hmysql --silent); do sleep 1; done
    - composer run seed-db

    build:
    image: "api-build:${DRONE_BUILD_NUMBER}"
    group: parallel-1
    volumes:
    - composer-cache:/root/.composer
    commands:
    - composer install --no-interaction --no-progress --no-suggest

    generate-swagger:
    image: "api-build:${DRONE_BUILD_NUMBER}"
    environment:
    - DATABASE_USER=root
    - DATABASE_PASSWORD=msyql
    - DATABASE_HOST=mysql
    - DATABASE_NAME=(snip)
    commands:
    - composer run swagger-generate

    validate-swagger:
    image: "node:alpine"
    group: parallel-2
    volumes:
    - npm-cache:/root/.npm
    commands:
    - "npm install -g swagger-cli"
    - "swagger-cli validate ./swagger.json"

    sniff:
    image: "api-build:${DRONE_BUILD_NUMBER}"
    group: parallel-2
    commands:
    - "composer run sniff"

    test:
    image: "api-build:${DRONE_BUILD_NUMBER}"
    group: parallel-2
    environment:
    - DATABASE_USER=root
    - DATABASE_PASSWORD=msyql
    - DATABASE_HOST=mysql
    - DATABASE_NAME=(snip)
    secrets:
    - source: meraki_api_key
    target: MERAKI_API_KEY
    commands:
    - cp container/php.ini /etc/php7/php.ini
    - echo $MERAKI_API_KEY > tests/meraki_api_key.txt
    - composer run test

    sonarqube:
    image: newtmitch/sonar-scanner
    group: parallel-3
    secrets:
    - source: sonar_token
    target: SONAR_TOKEN
    volumes:
    - sonar-cache:/root/.sonar/cache
    when:
    branch:
    - master
    - staging
    status:
    - success
    commands:
    - >
    sonar-scanner
    -Dsonar.projectName="API (${DRONE_BRANCH})"
    -Dsonar.host.url=https://sonarqube.(snip)
    -Dsonar.projectKey=api:${DRONE_BRANCH}
    -Dsonar.projectVersion=$(cat VERSION)
    -Dsonar.login=$SONAR_TOKEN
    -Dsonar.projectBaseDir=.

    publish:
    image: docker
    group: parallel-3
    commands:
    - docker tag api-build:${DRONE_BUILD_NUMBER} registry.(snip):5000/api:latest
    - docker push registry.(snip):5000/api:latest
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    when:
    branch:
    - master
    status:
    - success

    slack:
    image: plugins/slack
    group: parallel-3
    webhook: https://hooks.slack.com/services/(snip)
    channel: ci
    when:
    status:
    - success
    - failure

    services:
    mysql:
    image: mysql:5.6
    environment:
    - MYSQL_DATABASE=(snip)
    - MYSQL_ROOT_PASSWORD=msyql