Browse Source

new: [gitea,drone] new ``drone`` charm.

framadate
Valentin Lab 6 years ago
parent
commit
d40269703d
  1. 63
      drone/hooks/init
  2. 24
      drone/hooks/vcs_manager-relation-joined
  3. 24
      drone/hooks/web_proxy-relation-joined
  4. 3
      drone/lib/common
  5. 49
      drone/metadata.yml
  6. 52
      gitea/actions/info
  7. 3
      gitea/metadata.yml

63
drone/hooks/init

@ -0,0 +1,63 @@
#!/bin/bash
## Init is run on host
## For now it is run every time the script is launched, but
## it should be launched only once after build.
## Accessible variables are:
## - SERVICE_NAME Name of current service
## - DOCKER_BASE_IMAGE Base image from which this service might be built if any
## - SERVICE_DATASTORE Location on host of the DATASTORE of this service
## - SERVICE_CONFIGSTORE Location on host of the CONFIGSTORE of this service
set -e
. lib/common
mode="$(options-get mode)" || exit 1
case "$mode" in
single)
capacity="$(options-get capacity)" || exit 1
init-config-add "\
$MASTER_BASE_SERVICE_NAME:
environment:
DRONE_RUNNER_CAPACITY: $capacity
volumes:
- /var/run/docker.sock:/var/run/docker.sock
"
;;
multi)
secret="$(options-get secret)" || {
err "In 'multi' mode, you must set a 'secret' in $DARKYELLOW$SERVICE_NAME$NORMAL service's" \
"options to share with slave drones."
echo " You can use: 'openssl rand -hex 16' to create one." >&2
exit 1
}
init-config-add "\
$MASTER_BASE_SERVICE_NAME:
environment:
DRONE_RPC_SECRET: $secret
"
;;
esac
admin="$(options-get admin)" || exit 1
if [ "$admin" ]; then
init-config-add "\
$MASTER_BASE_SERVICE_NAME:
environment:
DRONE_USER_CREATE: \"username:$admin,admin:true\"
"
fi
init-config-add "\
$MASTER_BASE_SERVICE_NAME:
environment:
DRONE_SERVER_HOST: $MASTER_BASE_SERVICE_NAME
DRONE_SERVER_PROTO: http
"

24
drone/hooks/vcs_manager-relation-joined

@ -0,0 +1,24 @@
#!/bin/bash
. lib/common
## XXXvlab: all this to escape forced stdout capture
VCS_MANAGER_NAME=$(
charm=$(get_service_charm "$TARGET_SERVICE_NAME")
SERVICE_DATASTORE="$DATASTORE/$TARGET_SERVICE_NAME" charm.run_direct_action "$charm" info name
#run_service_action "$TARGET_SERVICE_NAME" info name
) || {
err "vcs-manager $TARGET_SERVICE_NAME was not able to return a name upon query."
exit 1
}
## this drone server url is a direct access to gitea, mainly
## to check credentials with the vcs manager.
config-add "\
services:
$MASTER_BASE_SERVICE_NAME:
environment:
DRONE_${VCS_MANAGER_NAME^^}_SERVER: http://$TARGET_SERVICE_NAME:3000/
"

24
drone/hooks/web_proxy-relation-joined

@ -0,0 +1,24 @@
#!/bin/bash
set -e
. lib/common
DOMAIN=$(relation-get domain) || exit 1
PROTO=$(relation-get protocol) || true
PROTO=${PROTO:-https}
## These are mainly to setup the correct web-hook
if [ "$MASTER_BASE_SERVICE_NAME" == "$DOMAIN" ]; then
## This is because the IP will be the docker container version
PROTO=http
fi
config-add "\
services:
$MASTER_BASE_SERVICE_NAME:
environment:
DRONE_SERVER_HOST: $DOMAIN
DRONE_SERVER_PROTO: $PROTO
"

3
drone/lib/common

@ -0,0 +1,3 @@
# -*- mode: shell-script -*-

49
drone/metadata.yml

@ -0,0 +1,49 @@
description: "Drone Server"
maintainer: "Valentin Lab <valentin.lab@kalysto.org>"
## XXXvlab: docker uses the 'build' directory or the 'image:' option here.
docker-image: docker.0k.io/drone:1.0
docker-compose:
environment:
DRONE_OPEN: "true" ## users are authenticated through the vcs-manager anyway
DRONE_GIT_ALWAYS_AUTH: "false"
DRONE_TLS_AUTOCERT: "false"
## default database
DATABASE_DRIVER: sqlite3
DATABASE_CONFIG: /data/drone.sqlite
# GIN_MODE: release
## Should probably offer an option in charm, with 'log.{}'
# DRONE_LOGS_DEBUG: "true"
# DRONE_LOGS_TEXT=true
# DRONE_LOGS_PRETTY=true
# DRONE_LOGS_COLOR=true
data-resources:
- /data
default-options:
mode: single ## mode is 'single' or 'multi'
capacity: 2 ## only if mode is 'single'
#secret: ## only if mode is 'multi'
uses:
vcs-manager:
#constraint: required | recommended | optional
#auto: pair | summon | none ## default: pair
constraint: required
auto: pair
solves:
feature: "Version control system manager"
web-proxy:
#constraint: required | recommended | optional
#auto: pair | summon | none ## default: pair
constraint: recommended
auto: pair
solves:
proxy: "Public access"
default-options:
target: !var-expand ${MASTER_BASE_SERVICE_NAME}:80

52
gitea/actions/info

@ -0,0 +1,52 @@
#!/bin/bash
## Load action gets a first argument a DIRECTORY holding the necessary files.
##
##
if [ -z "$SERVICE_DATASTORE" ]; then
echo "This script is meant to be run through 'compose' to work properly." >&2
exit 1
fi
usage="$exname [-h|--help] KEYWORD"
KEYWORD=
while [ "$1" ]; do
case "$1" in
"--help"|"-h")
print_usage
exit 0
;;
*)
[ -z "$KEYWORD" ] && { KEYWORD=$1 ; shift ; continue ; }
err "Unexpected argument '$1'."
exit 1
;;
esac
shift
done
if [ -z "$KEYWORD" ]; then
err "You must provide a keyword as first argument."
print_usage
exit 1
fi
. "$CHARM_PATH/lib/common"
## This can work only if ~/.pgpass is correctly created by init.
case "$KEYWORD" in
url)
ini get server ROOT_URL || true
;;
name)
echo gitea
;;
*)
err "Unknown keyword $KEYWORD."
exit 1
;;
esac

3
gitea/metadata.yml

@ -14,6 +14,9 @@ data-resources:
# default-options: # default-options:
# config: | # config: |
provides:
vcs-manager:
uses: uses:
log-rotate: log-rotate:
constraint: recommended constraint: recommended

Loading…
Cancel
Save