Skip to content

Instantly share code, notes, and snippets.

@d0x2f
Last active August 17, 2021 22:18
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save d0x2f/0e5549bba6d7fa5b8c3bbab27ff3dbae to your computer and use it in GitHub Desktop.
Save d0x2f/0e5549bba6d7fa5b8c3bbab27ff3dbae to your computer and use it in GitHub Desktop.
.drone.yml example
workspace:
base: /build
pipeline:
dbnode1:
detach: true
image: mysql/mysql-cluster:7.5
commands:
- sleep 5
- >
ndbd --nodaemon --ndb-nodeid=2
--connect-string="nodeid=2\;host=dbmanager"
dbnode2:
detach: true
image: mysql/mysql-cluster:7.5
commands:
- sleep 5
- >
ndbd --nodaemon --ndb-nodeid=3
--connect-string="nodeid=3\;host=dbmanager"
dbserver:
detach: true
image: mysql/mysql-cluster:7.5
environment:
- MYSQL_DATABASE=encapto_ci_testing
- MYSQL_ROOT_PASSWORD=mysql
- MYSQL_ROOT_HOST=%
commands:
- cp /build/src/(snip)/back/API/container/drone/my.cnf /etc/my.cnf
- sleep 10
- /entrypoint.sh mysqld --ndb-nodeid=4 --ndb-connectstring="nodeid=4\;host=dbmanager"
dbmanager:
detach: true
image: mysql/mysql-cluster:7.5
commands:
- cp /build/src/(snip)/back/API/container/drone/my.cnf /etc/my.cnf
- >
ndb_mgmd --nodaemon --ndb-nodeid=1 --connect-string="nodeid=1\;host=dbmanager"
--config-file=/build/src/(snip)/back/API/container/drone/mysql-cluster.cnf
build-image:
image: docker
commands:
# 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
seed-db:
image: "api-build:${DRONE_BUILD_NUMBER}"
group: parallel-1
environment:
- ENCAPTO_DATABASE_USER=root
- ENCAPTO_DATABASE_PASSWORD=mysql
- ENCAPTO_DATABASE_HOST=dbserver
- ENCAPTO_DATABASE_NAME=encapto_ci_testing
commands:
# Ensure all db nodes are still running
- ping -c1 dbnode1
- ping -c1 dbnode2
- ping -c1 dbmanager
- ping -c1 dbserver
# Wait for the mysql service to be ready.
- while (! mysqladmin ping -hdbserver --silent); do sleep 1; done
# Seed database with initial data.
- composer run seed-db
build:
image: "api-build:${DRONE_BUILD_NUMBER}"
group: parallel-1
volumes:
- composer-cache:/root/.composer
commands:
# Install dependencies.
- composer install --no-interaction --no-progress --no-suggest
generate-swagger:
image: "api-build:${DRONE_BUILD_NUMBER}"
environment:
- ENCAPTO_DATABASE_USER=root
- ENCAPTO_DATABASE_PASSWORD=mysql
- ENCAPTO_DATABASE_HOST=dbserver
- ENCAPTO_DATABASE_NAME=encapto_ci_testing
commands:
# Generate swagger.json.
- composer run swagger-generate
validate-swagger:
image: "node:alpine"
group: parallel-2
volumes:
- npm-cache:/root/.npm
commands:
# Install swagger validator and validate swagger.json
- "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:
- ENCAPTO_DATABASE_USER=root
- ENCAPTO_DATABASE_PASSWORD=mysql
- ENCAPTO_DATABASE_HOST=dbserver
- ENCAPTO_DATABASE_NAME=encapto_ci_testing
secrets:
- source: meraki_api_key
target: MERAKI_API_KEY
commands:
# 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:
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=.
-Dsonar.gitlab.commit_sha=${DRONE_COMMIT}
-Dsonar.gitlab.ref_name=${DRONE_BRANCH}
-Dsonar.gitlab.project_id=2
publish:
image: docker
group: parallel-3
secrets:
- source: portus_token
target: PORTUS_TOKEN
commands:
# Login to the registry
- docker login portus.(snip) -u drone-ci -p $PORTUS_TOKEN
# Build production image, which includes the code and without xdebug.
- >
docker build . --target production
-t portus.(snip)/build/api-php-fpm:latest
-t portus.(snip)/build/api-php-fpm:$(cat VERSION)
# Build the nginx proxy image.
- >
docker build ./nginx
-t portus.(snip)/build/api-nginx:latest
-t portus.(snip)/build/api-nginx:$(cat VERSION)
# Build the db image.
- >
docker build ./db
-t portus.(snip)/build/db:latest
-t portus.(snip)/build/db:$(cat VERSION)
# Publish to the registry
- docker push portus.(snip)/build/api-php-fpm:latest
- docker push portus.(snip)/build/api-php-fpm:$(cat VERSION)
- docker push portus.(snip)/build/api-nginx:latest
- docker push portus.(snip)/build/api-nginx:$(cat VERSION)
- docker push portus.(snip)/build/db:latest
- docker push portus.(snip)/build/db:$(cat VERSION)
volumes:
- /var/run/docker.sock:/var/run/docker.sock
when:
branch:
- master
status:
- success
delete-build-image:
image: docker
err_ignore: true
ommands:
# 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
err_ignore: true
webhook: https://hooks.slack.com/services/(snip)
channel: ci
when:
status:
- success
- failure
@alexislefebvre
Copy link

@d0x2f Thanks a lot! I was struggling with the cache plugin and adding a composer-cache:/root/.composer volume is so much easier.

I had to add my account to the list of admins in order to mark the repository as trusted: http://docs.drone.io/user-admins/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment