Contributed by Ravi Lachhman
![drone by harness logo with a jedi chicken](https://cd.foundation/wp-content/uploads/sites/78/2020/08/dronebyharness.png)
Drone Architecture
Drone has a Server to Runner model. A Server orchestrates the runners which perform the tasks.
The Drone Server authenticates with your SCM provider and then via a shared secret communicates with the Runners. Wiring up these pieces are pretty simple.
Let’s Get Started
In this example, the moving pieces will be a GitHub Account, a running CentOS machine, a Kubernetes Cluster, and a Docker Hub account. Like always, you can follow along in the blog and/or watch the video. The example GitHub repository can be cloned/forked before this example at https://github.com/ravilach/firstdrone.
Video: https://www.youtube.com/watch?v=kZmOCLCpvmk
GitHub / SCM Prep
The Drone Server needs to authenticate with your SCM provider. This is accomplished in GitHub by making an OAuth application. This is done by navigating to Settings ➡ Developer settings ➡ OAuth Apps + Register a new application.
![screenshot of the No OAuth applications page](https://cd.foundation/wp-content/uploads/sites/78/2020/08/oauthapps.png)
When you register a new OAuth application, you will need to have the DNS/IP address of the Drone Server handy. In my case, this is 34.207.222.178. The callback URL has /login appended to the Homepage URL.
![Screenshot of the filled in OAuth application form](https://cd.foundation/wp-content/uploads/sites/78/2020/08/oauthappform.png)
When you register the application, make sure to note the Client ID and Client Secret, which will be needed to wire the Drone Server.
![Screenshot of a client ID and client Secret](https://cd.foundation/wp-content/uploads/sites/78/2020/08/clientidsecret.png)
CentOS Drone Prep
Depending on where you get CentOS from, you might have to install Docker Engine. Assuming that you have Docker Engine installed, the only piece of prep you need on the server before installing is to generate the shared secret which will be used for Server to Runner communication. Make sure to copy down the shared secret.
openssl rand -hex 16
![Screenshot of command line run: openssl rand -hex 16](https://cd.foundation/wp-content/uploads/sites/78/2020/08/opensslcode.png)
Drone Installation
To get Drone on your machine, simply run a Docker Pull on the image.
sudo docker pull drone/drone:1
![screenshot command line run sudo docker pull drone/drone:1](https://cd.foundation/wp-content/uploads/sites/78/2020/08/dockerpull.png)
Once pulled, you can configure the properties for Docker Run. The properties to fill in for barebones are the secrets and server address and protocol. Let’s go ahead and create an admin user. The admin user follows your GitHub username.
![screenshot create admin user](https://cd.foundation/wp-content/uploads/sites/78/2020/08/dockerconfig.png)
sudo docker run \ --volume=/var/lib/drone:/data \ --env=DRONE_GITHUB_CLIENT_ID=yourClientID \ --env=DRONE_GITHUB_CLIENT_SECRET=yourClientSecret \ --env=DRONE_RPC_SECRET=yourRPCSecret \ --env=DRONE_SERVER_HOST=yourIPorDNS \ --env=DRONE_SERVER_PROTO=http \ --env=DRONE_USER_CREATE=username:yourGitHubUser,admin:true \ --publish=80:80 \ --publish=443:443 \ --restart=always \ --detach=true \ --name=drone \ drone/drone:1
Drone UI
One issuing the Docker Run commands with the properties, you can head to the IP or DNS entry of your Drone server. In my case, navigate to http://34.207.222.178. You will be greeted to authorize your user via GitHub.
Authorize your GitHub Credentials.
![screenshot of GitHub authorize drone credentials](https://cd.foundation/wp-content/uploads/sites/78/2020/08/authorize_github.png)
Once Authorized, Drone will build a list of repositories.
![screenshot of an empty repo list](https://cd.foundation/wp-content/uploads/sites/78/2020/08/drone_repo_empty.png)
![screenshot of filled repo list](https://cd.foundation/wp-content/uploads/sites/78/2020/08/drone_repo.png)
Now you are ready to deploy runners, in this case, Kubernetes.
Kubernetes Cluster Prep
In this example, we will leverage the Kubernetes Runners. For the Kubernetes Runners to request resources on your behalf, a Role Binding is needed as well as the Runner Deployment.
A simple approach is to build out two YAML files, one for the Role and Role Binding and another for the Deployment.
![screenhot of YAML file code](https://cd.foundation/wp-content/uploads/sites/78/2020/08/yamlfiles.png)
kubectl apply -f drone_role.yaml
![screenshot of command line run code kubectl apply -f drone_role.yaml](https://cd.foundation/wp-content/uploads/sites/78/2020/08/drone_role_yaml.png)
In the Runner Deployment Spec, make sure to update the Drone Server, Shared Secret, and Protocol to match your installation.
![screenshot runner deployment specs](https://cd.foundation/wp-content/uploads/sites/78/2020/08/runner_deploy_specs.png)
When the items are filled in, can deploy the Deployment.
kubectl apply -f drone_deployment.yaml
![screenshot deploy deployment](https://cd.foundation/wp-content/uploads/sites/78/2020/08/drone_deploy_kubernetes.png)
Optionally you can validate that the Runner is connected to the Server. Get the Pod Name then run a log command.
kubectl get pods –all-namespaces
![screenshot run log command kubectl get pods --all-namespaces](https://cd.foundation/wp-content/uploads/sites/78/2020/08/pod_name_code.png)
kubectl logs drone-6564db8f9f-949s2 -c runner
![screenshot log command kubectl logs drone-6564db8f9f-949s2 -c runner](https://cd.foundation/wp-content/uploads/sites/78/2020/08/kubernetes_logs_drone.png)
Success! Now would be time to start marching towards your first build.
Marry the CI and SCM Together
Drone leverages Configuration as Code to describe pipelines. Drone can work off of webhook requests from the Source Code Management solution to orchestrate when a new build needs to be kicked off.
Prep the Repository
Can leverage the Drone UI to “Activate” the Repository. In my “firstdrone” repository, the webhooks are empty.
![screenshot of the GitHub empty webhooks page](https://cd.foundation/wp-content/uploads/sites/78/2020/08/webhooks_empty_github.png)
In the Drone UI, navigate to your repository of choice and then Active Repository.
![screenshot of the repo drone settings page](https://cd.foundation/wp-content/uploads/sites/78/2020/08/settings_drone.png)
For this example, the defaults are fine for the Repository Activation. The configuration to modify if needed is the name of the Drone Configuration file to monitor. In this example, you will monitor for “Drone.yaml” in the repository.
![screenshot of config menu where you type in "Drone.yaml" in the Configuration field](https://cd.foundation/wp-content/uploads/sites/78/2020/08/configure_drone_settings.png)
Then you can validate that the webhook has been successfully created in GitHub.
![screenshot of GitHub webhooks page with new hook](https://cd.foundation/wp-content/uploads/sites/78/2020/08/webhooks_github.png)
With the CI and SCM wirings out of the way, the next steps are to define your first pipeline and fire off a build.
Your First Drone Project
If starting with an empty repository you can leverage a simple example of a project structure or wire together your own project/repository.
![screenshot of GitHub project structure including: Dockerfile, Drone.yaml, LISCENSE, README.md and main.go](https://cd.foundation/wp-content/uploads/sites/78/2020/08/github_projectstructure.png)
If following this example, you wired into Drone to watch out for “Drone.yaml”. Drone’s declarative pipeline format is easy to craft and understand as per the example. In the example pipeline, we leverage the Docker Plugin for the publish setting and will be downloaded automatically during execution time.
![screenshot of Drone.yaml file including the docker plugin code](https://cd.foundation/wp-content/uploads/sites/78/2020/08/dockerpublishsettings.png)
The highlighted lines are leveraging secrets to wire in my Docker Hub credentials. You need to update the repo location to your own and create Drone Secrets to wire in.
Back in the Drone UI, navigate to the repository settings, and add the needed secrets.
![drone menu secrets page, adding docker](https://cd.foundation/wp-content/uploads/sites/78/2020/08/drone_secret_docker.png)
Add the appropriate secrets to match the format of the example.
![screenshot of docker secrets showing the secrets name matching the name assigned in the docker.yaml file](https://cd.foundation/wp-content/uploads/sites/78/2020/08/drone_secret_naming.png)
With those wirings out of the way, you are now ready to kick off your first build and publish it to Docker Hub.
Your First Build and Publish
With the wirings out of the way, all that is left is to commit the “Drone.yaml” with some sort of change and you are off to the races.
![screenshot of commit change on GitHub](https://cd.foundation/wp-content/uploads/sites/78/2020/08/commitchange_github.png)
Once you hit Commit changes, the CI magic starts, and your build and publish are off!
![screenshot the build and publish page in Drone](https://cd.foundation/wp-content/uploads/sites/78/2020/08/drone_repo_commit_sm-1.png)
Success! Congratulations on your first Drone build and publish!
![screenshot of successful Drone build](https://cd.foundation/wp-content/uploads/sites/78/2020/08/drone_build_complete.png)
Validating success on Docker Hub. Enjoy the spoils of your hard work and don’t forget to check out Drone!
![screenshot of docker hub showing the successful build](https://cd.foundation/wp-content/uploads/sites/78/2020/08/dockerhub_build_complete.png)