Browse Source

new: [gitea] new charm

framadate
Valentin Lab 6 years ago
parent
commit
9b2bc481d0
  1. 100
      gitea/hooks/init
  2. 47
      gitea/hooks/postgres_database-relation-joined
  3. 8
      gitea/hooks/pre_deploy
  4. 11
      gitea/hooks/web_proxy-relation-joined
  5. 22
      gitea/lib/common
  6. 38
      gitea/metadata.yml

100
gitea/hooks/init

@ -0,0 +1,100 @@
#!/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
mkdir -p "$(dirname "$SERVICE_DATASTORE$CONFIG_FILE")"
cat <<EOF > "$SERVICE_DATASTORE$CONFIG_FILE"
APP_NAME = Gitea: Git with a cup of tea
RUN_MODE = prod
RUN_USER = git
[repository]
ROOT = /data/git/repositories
[repository.local]
LOCAL_COPY_PATH = /data/gitea/tmp/local-repo
[repository.upload]
TEMP_PATH = /data/gitea/uploads
[server]
APP_DATA_PATH = /data/gitea
SSH_DOMAIN = localhost
HTTP_PORT = 3000
ROOT_URL = http://$SERVICE_NAME:3000/
DISABLE_SSH = false
SSH_PORT = 5022
LFS_CONTENT_PATH = /data/git/lfs
DOMAIN = localhost
LFS_START_SERVER = true
LFS_JWT_SECRET = j5N_xbVaT12B6qMM5Zc2jy0gSJPOAxGICGKio0Q8Ygo
OFFLINE_MODE = false
[database]
PATH = /data/gitea/gitea.db
DB_TYPE = sqlite3
HOST = postgres
NAME = gitea
USER = root
PASSWD =
SSL_MODE = disable
[indexer]
ISSUE_INDEXER_PATH = /data/gitea/indexers/issues.bleve
[session]
PROVIDER_CONFIG = /data/gitea/sessions
PROVIDER = file
[picture]
AVATAR_UPLOAD_PATH = /data/gitea/avatars
DISABLE_GRAVATAR = false
ENABLE_FEDERATED_AVATAR = true
[attachment]
PATH = /data/gitea/attachments
[log]
ROOT_PATH = /data/gitea/log
MODE = file
LEVEL = Info
[security]
INSTALL_LOCK = true
SECRET_KEY = ZmxgxfSNZZgMEm3MJW1Nn6BfWqSuats7MIHQvgGD2AwIH2Vdx1L77yw569bWJXPI
INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE1NDgyNDE1OTR9.1Uu3crRVkqamIL5U2axcRJh-HEEZzMLbrLvHlhgTv0g
[service]
DISABLE_REGISTRATION = false
REQUIRE_SIGNIN_VIEW = false
REGISTER_EMAIL_CONFIRM = false
ENABLE_NOTIFY_MAIL = false
ALLOW_ONLY_EXTERNAL_REGISTRATION = false
ENABLE_CAPTCHA = false
DEFAULT_KEEP_EMAIL_PRIVATE = false
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
DEFAULT_ENABLE_TIMETRACKING = true
NO_REPLY_ADDRESS = noreply.example.org
[mailer]
ENABLED = false
[openid]
ENABLE_OPENID_SIGNIN = false
ENABLE_OPENID_SIGNUP = false
EOF

47
gitea/hooks/postgres_database-relation-joined

@ -0,0 +1,47 @@
#!/bin/bash
set -e
PASSWORD="$(relation-get password)"
DBUSER="$(relation-get user)"
DBNAME="$(relation-get dbname)"
. lib/common
control=$(printf "%s\0" "$DBUSER" "$DBNAME" "$PASSWORD" | md5_compat)
## Note: we don't use environment variable as it will be ignored if
## $CONFIG_FILE is found. So better modify directly the config file.
# config-add "\
# services:
# $MASTER_BASE_SERVICE_NAME:
# environment:
# - DB_TYPE=postgres
# - DB_HOST=$MASTER_TARGET_SERVICE_NAME
# - DB_NAME=$DBNAME
# - DB_USER=$USER
# - DB_PASSWD=$PASSWORD
# "
# ini set database DB_TYPE postgres
# ini set database HOST postgres
# ini set database NAME gitea.mydomain.org
# ini set database USER gitea.mydomain.org
# ini set database PASSWD g61wsLvKj8cF6A1S
# ini set database SSL_MODE disable
ini merge <<EOF
[database]
DB_TYPE = postgres
HOST = $MASTER_TARGET_SERVICE_NAME
NAME = $DBNAME
USER = $DBUSER
PASSWD = $PASSWORD
SSL_MODE = disable
EOF
relation-set control "$control"
info "Configured $SERVICE_NAME code for $TARGET_SERVICE_NAME access."

8
gitea/hooks/pre_deploy

@ -0,0 +1,8 @@
#!/bin/bash
## Should be executable N time in a row with same result.
set -e
. lib/common
gitea_config_hash || exit 1

11
gitea/hooks/web_proxy-relation-joined

@ -0,0 +1,11 @@
#!/bin/bash
set -e
. lib/common
DOMAIN=$(relation-get domain) || exit 1
ini set server ROOT_URL "http://$DOMAIN/"
ini set server SSH_DOMAIN "$DOMAIN"

22
gitea/lib/common

@ -0,0 +1,22 @@
# -*- mode: shell-script -*-
CONFIG_FILE=/data/gitea/conf/app.ini
ini() {
local action="$1"
shift
crudini "--$action" "$SERVICE_DATASTORE$CONFIG_FILE" "$@"
}
gitea_config_hash() {
config_hash=$(cat "$SERVICE_DATASTORE$CONFIG_FILE" | md5_compat) || exit 1
init-config-add "
$MASTER_BASE_SERVICE_NAME:
labels:
- compose.config_hash=$config_hash
"
}

38
gitea/metadata.yml

@ -0,0 +1,38 @@
description: "Gitea Server"
maintainer: "Valentin Lab <valentin.lab@kalysto.org>"
## XXXvlab: docker uses the 'build' directory or the 'image:' option here.
docker-image: docker.0k.io/gitea
docker-compose:
ports:
- "5022:22"
# environment:
# - USER_UID=1000
# - USER_GID=1000
data-resources:
- /data
# default-options:
# config: |
uses:
log-rotate:
constraint: recommended
auto: pair
solves:
disk-leak: "/data"
postgres-database:
#constraint: required | recommended | optional
#auto: pair | summon | none ## default: pair
constraint: optional
auto: pair
solves:
database: "main storage"
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}:3000
Loading…
Cancel
Save