You need a sub-domain for your Drone server. You can create it in Cloudflare under your root domain, or as a normal vanilla sub-domain with your preferred registrar. Something like drone.example.net
Docker is installed.
Docker Compose is installed.
Drone CI Config:
Our Working directory is in /etc/drone. Create this using the following command:
sudo mkdir /etc/drone
cd into it:
Set up your initial Drone server config with the following:
sudo vi docker-compose.yml
Enter the below information:
#initial sever config for docker compose file version: '3' services: drone-server: image: drone/drone:0.8.4 ports: - 127.0.0.1:8000:8000 volumes: - /var/lib/drone:/var/lib/drone/ restart: always env_file: - /etc/drone/server.env drone-agent: image: drone/agent:0.8.4 command: agent restart: always depends_on: - drone-server volumes: - /var/run/docker.sock:/var/run/docker.sock env_file: - /etc/drone/agent.env
The above referenced env files will have the configs for drone:
Create your server.env file:
sudo vi server.env
Enter the below information
#Service settings DRONE_SECRET=<< your random char drone secret> DRONE_HOST=<your drone server sub-domain url> #Registration settings: DRONE_OPEN=false # you don't want random strangers to register DRONE_GOGS=true # enables gogs support DRONE_GOGS_URL=<your existing gogs url> DRONE_GOGS_GIT_USERNAME=<username> DRONE_GOGS_GIT_PASSWORD=<configured gogs password> DRONE_GOGS_PRIVATE=true
DRONE_GOGS_PRIVATE=true has to be set if this is a gogs server that doesn't allow cloning anonymously. We need this here or our authentication will fail on our builds when Drone tries to clone this, often with the following:
0s 2 Initialized empty Git repository in /drone/src/droneurl/path/torepo/.git/ 0s 3 + git remote add origin https://droneurl/path/torepo/.git/ 0s 4 + git fetch --no-tags origin +refs/heads/master: 0s 5 fatal: could not read Username for 'https://droneurl/path/torepo/.git/': No such device or address 0s 6 exit status 128
We don't want this!
create your agent env file:
sudo vi agent.env
#Agent Info DRONE_SECRET=<drone secret> DRONE_SERVER=drone-server:9000
We can test this works by running
docker-compose up to make sure everything starts up successfully:
/usr/local/bin/docker-compose -f /etc/drone/docker-compose.yml up
You can just cancel the running process by pressing the
ctrl+c combination on your keyboard.
Next, we want our Drone server to be started as a service even when the server starts and at all times. This way you don't have to manually invoke the process each time:
- Create your unit File:
sudo vi /etc/systemd/system/droneci.service
Then enter the following:
# This way we can have it start when our server run as a service: [Unit] Description=Drone Server After=docker.service nginx.service # we need this to start after docker and nginx have started [Service] Restart=always ExecStart=/usr/local/bin/docker-compose -f /etc/drone/docker-compose.yml up #start cmd ExecStop=/usr/local/bin/docker-compose -f /etc/drone/docker-compose.yml #stop cmd [Install] WantedBy=multi-user.target
Start the service by running the following command:
sudo systemctl start drone.service
Then check the status of your service:
sudo systemctl status drone.service
If it start's successfully, then it's safe to enable it as a service on system boot:
sudo systemctl enable drone.service
The console should output info saying that it's created the necessary symlinks for the service to start on boot.
If you need any further info regarding Drone, you can check out their official docs here
You can hop onto setting up Nginx with Part 3