From 438909a049a80f7bf685913e77c4c7f536f0f07f Mon Sep 17 00:00:00 2001 From: Felix Bartels Date: Fri, 5 Jun 2020 23:05:57 +0200 Subject: [PATCH] readme and tweaks Signed-off-by: Felix Bartels --- README.md | 57 ++++++++++++++++++++++++++++++++++++++++++++-- docker-compose.yml | 8 +++---- run-agent.sh | 28 +++++++++++++++-------- 3 files changed, 78 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 78a8530..a712c6a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,57 @@ +# Drone CI for Cloudron + +Run the Drone server on Cloudron and the agents locally. + +I am using this setup together with a Gitea running on the same Cloudron installation. + +## Requirements + +- `docker-compose` +- `git` +- `make` +- Cloudron CLI + +## Tips and Tricks + +I would also like to share some very useful commands. To install `drone` CLI, follow [official docs](https://docs.drone.io/cli/install/). + +### Using drone-cli + +Go to your [user settings](https://drone.9wd.eu/account) and get login information + +```bash +export DRONE_SERVER=https://drone.9wd.eu +export DRONE_TOKEN=your token +drone info +``` + +### Executing pipelines directly + +You can also run pipelines directly with the Drone CLI: + +```bash +drone exec --secret-file drone_secrets.yaml .drone.yml +``` + +A template for `drone-secrets.yaml`: + +```yaml +slack_url: https://hooks.slack.com/services/xxxxxxxxxxxx +``` + +### Adding secrets through CLI + +You can either add secrets through the web UI or use drone directly from your terminal: + +```bash +drone secret add -repository username/repository-name --name foo --data bar --allow-pull-request +``` + +## Inspiration + +- [Setting up simple, self-hosted & fast CI/CD solution with Drone.io](https://webhookrelay.com/blog/2019/02/11/using-drone-for-simple-selfhosted-ci-cd/) + ## TODO -- remove commited secrets -- retrieve rpc secret from cloudron +- [*] remove commited secrets +- [*] retrieve rpc secret from cloudron diff --git a/docker-compose.yml b/docker-compose.yml index fb933f8..33ca7e0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,7 +9,7 @@ services: volumes: - /var/run/docker.sock:/var/run/docker.sock environment: - - DRONE_RPC_SERVER=https://drone.9wd.eu - - DRONE_RPC_SECRET=QdExkSpgVY5RiC783UcqFgt8mvEs0Mid - - DRONE_RUNNER_CAPACITY=2 - - DRONE_RUNNER_NAME="clifford" \ No newline at end of file + - DRONE_RPC_SERVER=${DRONE_RPC_SERVER} + - DRONE_RPC_SECRET=${DRONE_RPC_SECRET} + - DRONE_RUNNER_CAPACITY=${DRONE_RUNNER_CAPACITY} + - DRONE_RUNNER_NAME=${DRONE_RUNNER_NAME} \ No newline at end of file diff --git a/run-agent.sh b/run-agent.sh index 97d1573..ade6fae 100755 --- a/run-agent.sh +++ b/run-agent.sh @@ -1,4 +1,4 @@ -#/bin/sh +#!/bin/sh set -x @@ -6,12 +6,22 @@ random_string() { LC_CTYPE=C tr -dc 'a-zA-Z0-9' < /dev/urandom | head -c32 } -if [ ! -e .env ]; then - cat <<-EOF > ".env" -DRONE_RPC_SERVER=https://drone.9wd.eu -DRONE_RPC_SECRET=QdExkSpgVY5RiC783UcqFgt8mvEs0Mid -DRONE_RUNNER_CAPACITY="$(nproc)" -DRONE_RUNNER_NAME="$(hostname)" -EOF -fi +update_env_file () { + varname="$1" + varvalue="$2" + if ! grep -q "$varname" ./.env; then + echo "$varname=$varvalue" >> ./.env + else + sed -i "/$varname/c $varname=$varvalue" ./.env + fi +} + +cloudron pull /app/data/.env .env + +. ./.env + +update_env_file DRONE_RPC_SERVER "https://$DRONE_SERVER_HOST" +update_env_file DRONE_RUNNER_CAPACITY "$(nproc)" +update_env_file DRONE_RUNNER_NAME "$(hostname)" + docker-compose up -d \ No newline at end of file