diff --git a/drone/hooks/init b/drone/hooks/init new file mode 100755 index 00000000..b5ca40f0 --- /dev/null +++ b/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 +" diff --git a/drone/hooks/vcs_manager-relation-joined b/drone/hooks/vcs_manager-relation-joined new file mode 100755 index 00000000..eacd229f --- /dev/null +++ b/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/ +" diff --git a/drone/hooks/web_proxy-relation-joined b/drone/hooks/web_proxy-relation-joined new file mode 100755 index 00000000..c4b6d9f9 --- /dev/null +++ b/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 +" diff --git a/drone/lib/common b/drone/lib/common new file mode 100644 index 00000000..1558c9af --- /dev/null +++ b/drone/lib/common @@ -0,0 +1,3 @@ +# -*- mode: shell-script -*- + + diff --git a/drone/metadata.yml b/drone/metadata.yml new file mode 100644 index 00000000..fa1845e9 --- /dev/null +++ b/drone/metadata.yml @@ -0,0 +1,49 @@ +description: "Drone Server" +maintainer: "Valentin Lab " +## 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 diff --git a/gitea/actions/info b/gitea/actions/info new file mode 100755 index 00000000..fb442d6c --- /dev/null +++ b/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 diff --git a/gitea/metadata.yml b/gitea/metadata.yml index 83389c34..d15c9061 100644 --- a/gitea/metadata.yml +++ b/gitea/metadata.yml @@ -14,6 +14,9 @@ data-resources: # default-options: # config: | +provides: + vcs-manager: + uses: log-rotate: constraint: recommended