From ab399ce04064b34dffd53beeaebcc378fae38020 Mon Sep 17 00:00:00 2001 From: Felix Bartels Date: Fri, 5 Jun 2020 22:25:57 +0200 Subject: [PATCH] Add scripting to run drone-server on Cloudron Signed-off-by: Felix Bartels --- CloudronManifest.json | 11 +++++++++++ Dockerfile | 26 ++++++++++++++++++++++++ Makefile | 38 ++++++++++++++++++++++++++++++++++++ start.sh | 30 ++++++++++++++++++++++++++++ supervisor-drone-server.conf | 10 ++++++++++ 5 files changed, 115 insertions(+) create mode 100644 CloudronManifest.json create mode 100644 Dockerfile create mode 100644 Makefile create mode 100755 start.sh create mode 100644 supervisor-drone-server.conf diff --git a/CloudronManifest.json b/CloudronManifest.json new file mode 100644 index 0000000..0a9c651 --- /dev/null +++ b/CloudronManifest.json @@ -0,0 +1,11 @@ +{ + "version": "0.0.1", + "id": "com.github.drone", + "healthCheckPath": "/", + "httpPort": 8000, + "addons": { + "localstorage": {}, + "postgresql": {} + }, + "manifestVersion": 2 +} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..12ae1bf --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM drone/drone:1.7.0 as drone + +FROM cloudron/base:2.0.0@sha256:f9fea80513aa7c92fe2e7bf3978b54c8ac5222f47a9a32a7f8833edf0eb5a4f4 + +EXPOSE 8000 + +# add supervisor configs +RUN sed -e 's,^logfile=.*$,logfile=/run/supervisord.log,' -i /etc/supervisor/supervisord.conf +COPY supervisor-drone-server.conf /etc/supervisor/conf.d/ + +ENV \ + XDG_CACHE_HOME=/app/data \ + DRONE_SERVER_PROTO=https \ + DRONE_DATABASE_DRIVER=postgres \ + DRONE_RUNNER_OS=linux \ + DRONE_RUNNER_ARCH=amd64 \ + DRONE_SERVER_PORT=:8000 \ + DRONE_DATADOG_ENABLED=false + +COPY --from=drone /bin/drone-server /bin + +COPY start.sh /app/pkg/ + +WORKDIR /app/data + +CMD [ "/app/pkg/start.sh" ] \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..80f1534 --- /dev/null +++ b/Makefile @@ -0,0 +1,38 @@ +CLOUDRON_APP ?= drone +CLOUDRON_ID := $(shell jq -r .id CloudronManifest.json) +DOCKER_REPO ?= fbartels + +.PHONY: default +default: build update + +.PHONY: init +init: + cloudron init + +.PHONY: build +build: + cloudron build --set-repository $(DOCKER_REPO)/$(CLOUDRON_ID) + +.PHONY: update +update: build + cloudron update --app ${CLOUDRON_APP} + +.PHONY: install +install: build + cloudron install --location ${CLOUDRON_APP} + +.PHONY: uninstall +uninstall: + cloudron uninstall --app ${CLOUDRON_APP} + +.PHONY: install-debug +install-debug: + cloudron install --location ${CLOUDRON_APP} --debug + +.PHONY: exec +exec: + cloudron exec --app ${CLOUDRON_APP} + +.PHONY: logs +logs: + cloudron logs -f --app ${CLOUDRON_APP} diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..8c24397 --- /dev/null +++ b/start.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +set -x + +random_string() { + LC_CTYPE=C tr -dc 'a-zA-Z0-9' < /dev/urandom | head -c32 +} + +if [ ! -e /app/data/.env ]; then + cat <<-EOF > "/app/data/.env" +# Custom configuration for drone-server +DRONE_GITEA_SERVER=git.9wd.eu +DRONE_GITEA_CLIENT_ID=xxx +DRONE_GITEA_CLIENT_SECRET=xxx +DRONE_RPC_SECRET=$(random_string) +DRONE_DATABASE_SECRET=$(random_string) +DRONE_SERVER_HOST=$CLOUDRON_APP_DOMAIN +DRONE_DATABASE_DATASOURCE=postgres://$CLOUDRON_POSTGRESQL_USERNAME:$CLOUDRON_POSTGRESQL_PASSWORD@$CLOUDRON_POSTGRESQL_HOST:$CLOUDRON_POSTGRESQL_PORT/$CLOUDRON_POSTGRESQL_DATABASE?sslmode=disable +EOF +fi + +# export all values from ".env" +set -a +. /app/data/.env +set +x + +echo "=> Ensure permissions" +chown -R cloudron:cloudron /run /app/data + +exec /usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon -i drone-server diff --git a/supervisor-drone-server.conf b/supervisor-drone-server.conf new file mode 100644 index 0000000..0142163 --- /dev/null +++ b/supervisor-drone-server.conf @@ -0,0 +1,10 @@ +[program:drone-server] +command=/bin/drone-server +directory=/app/data +user=cloudron +autostart=true +autorestart=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0