Skip to content

Commit 14f16d6

Browse files
tbraeutigamlunny
authored andcommitted
snap-packaging for gitea (#2568)
* Modify tbraeutigam/gogs-snap for gitea * Fix building on 16.04 (manually build go-bindata). -> add _source.tar.bz2 to .gitignore (used by snapcraft cleanbuild) * Streamline Snap packaging: - Take advantage of install-hooks (snapd 2.27) - Use snapctl configuration storage for unchanging values * Move to using Snap Hooks for configuration * Missed re-adding daemon statement * Fix two warnings from Codacy.
1 parent 02ecc03 commit 14f16d6

File tree

7 files changed

+394
-0
lines changed

7 files changed

+394
-0
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,13 @@ coverage.all
5959
/integrations/mysql.ini
6060
/integrations/pgsql.ini
6161
/node_modules
62+
63+
64+
# Snapcraft
65+
snap/.snapcraft/
66+
parts/
67+
stage/
68+
prime/
69+
*.snap
70+
*.snap-build
71+
*_source.tar.bz2

snap/helpers/app.ini

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
APP_NAME = Gitea: Go Git Service
2+
RUN_USER = root
3+
RUN_MODE = prod
4+
CUSTOM_PATH = SNAP_DIR_DATA/custom
5+
6+
[server]
7+
DOMAIN = localhost
8+
PROTOCOL = http
9+
HTTP_PORT = 3001
10+
ROOT_URL = http://localhost:3001/
11+
DISABLE_SSH = false
12+
SSH_PORT = 22
13+
STATIC_ROOT_PATH = SNAP_DIR_DATA/static
14+
APP_DATA_PATH = SNAP_DIR_COMMON/data
15+
SSH_ROOT = SNAP_DIR_COMMON/ssh
16+
SSH_KEY_TEST_PATH = SNAP_DIR_DATA/sshkeytest
17+
18+
[database]
19+
DB_TYPE = sqlite3
20+
PATH = SNAP_DIR_COMMON/gitea.db
21+
22+
[repository]
23+
ROOT = SNAP_DIR_COMMON/repositories/data
24+
25+
[repository.upload]
26+
ENABLED = true
27+
ALLOWED_TYPES = "image/jpeg|image/png"
28+
FILE_MAX_SIZE = 10
29+
MAX_FILES = 5
30+
TEMP_PATH = SNAP_DIR_COMMON/repositories/tmp
31+
32+
[release.attachment]
33+
PATH = SNAP_DIR_COMMON/releases/attachments
34+
35+
[smartypants]
36+
ENABLED = true
37+
38+
[indexer]
39+
ISSUE_INDEXER_PATH = SNAP_DIR_COMMON/indexers/issues.bleve
40+
41+
42+
[mailer]
43+
ENABLED = false
44+
45+
[service]
46+
REGISTER_EMAIL_CONFIRM = false
47+
ENABLE_NOTIFY_MAIL = false
48+
DISABLE_REGISTRATION = false
49+
ENABLE_CAPTCHA = false
50+
REQUIRE_SIGNIN_VIEW = false
51+
52+
[picture]
53+
AVATAR_UPLOAD_PATH = SNAP_DIR_COMMON/pictures/avatars
54+
DISABLE_GRAVATAR = true
55+
ENABLE_FEDERATED_AVATAR = false
56+
57+
[attachment]
58+
PATH = SNAP_DIR_COMMON/attachments
59+
60+
[session]
61+
PROVIDER = memory
62+
63+
[log]
64+
MODE = file
65+
LEVEL = Trace
66+
ROOT_PATH = SNAP_DIR_COMMON/log

snap/helpers/configuration.sh

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#!/bin/bash
2+
if snapctl get gitea.snap.custom; then
3+
cdir=$(snapctl get gitea.snap.custom)
4+
else
5+
cdir=$SNAP_COMMON
6+
fi
7+
8+
cfg="$cdir/conf/app.ini"
9+
bak="$cdir/conf/app.ini.bak-$(date -Ins)"
10+
basecfg="$SNAP/snap/helpers/app.ini"
11+
smp="$SNAP/gitea/custom/conf/app.ini.sample"
12+
13+
function toSnap() {
14+
OIFS=$IFS
15+
IFS='
16+
'
17+
category="none"
18+
src="$cfg"
19+
[[ "$1" = "init" ]] && src="$smp"
20+
[[ "$1" = "snap" ]] && src="$basecfg"
21+
22+
for l in $(sed 's_;\([A-Z]*\)_\1_g' $src | grep -v -e '^;' -e '^$'); do
23+
if echo $l | grep -q '^[[]'; then
24+
category=$(CatToSnap "$l")
25+
elif echo $l | grep -q '^[A-Z]'; then
26+
option=$(OptToSnap "$l")
27+
value=$(ValToSnap "$l")
28+
if [[ $category = "none" ]]; then
29+
snapctl set "$option=$value"
30+
else
31+
snapctl set "$category.$option=$value"
32+
fi
33+
fi
34+
done
35+
IFS=$OIFS
36+
}
37+
38+
function toIni() {
39+
OIFS=$IFS
40+
IFS='
41+
'
42+
category="none"; option="none"; catUnset=true
43+
src=$smp
44+
[[ -f $cfg ]] && src="$cfg"
45+
tmpIni="$cfg.tmp"
46+
[[ -f $src ]] && cp "$src" "$tmpIni"
47+
cp $tmpIni $bak
48+
echo '' > $cfg
49+
for l in $(grep -v -e '^;' -e '^$' $tmpIni); do
50+
if echo $l | grep -q '^[[]'; then
51+
category=$(CatToSnap "$l")
52+
catUnset=true
53+
elif echo $l | grep -q '^[A-Z]'; then
54+
option=$(OptToSnap "$l")
55+
if [[ $category = "none" ]]; then
56+
value=$(snapctl get $option)
57+
echo $(OptToIni "$option") = $value >> $cfg
58+
else
59+
value=$(snapctl get $category.$option)
60+
if $catUnset; then
61+
echo "" >> $cfg
62+
echo "[$(CatToIni "$category")]" >> $cfg
63+
catUnset=false
64+
fi
65+
echo $(OptToIni "$option") = $value >> $cfg
66+
fi
67+
fi
68+
done;
69+
IFS=$OIFS
70+
}
71+
72+
function CatToSnap {
73+
ret=$(echo "$1" \
74+
| grep -oP '[A-Za-z0-9._]+' \
75+
| sed 's|\.|-|g' \
76+
| sed 's|_|99|g')
77+
echo $ret
78+
}
79+
function OptToSnap {
80+
ret=$(echo "$1" \
81+
| grep -oP '^[A-Z_]+' \
82+
| tr '[:upper:]' '[:lower:]' \
83+
| sed 's|_|-|g')
84+
echo $ret
85+
}
86+
function ValToSnap {
87+
ret=$(echo "$1" \
88+
| grep -oP '=.*$' \
89+
| sed 's_^= __g' \
90+
| sed 's_^=__g' \
91+
| sed "s|SNAP_DIR_DATA|$SDATA|g" \
92+
| sed "s|SNAP_DIR_COMMON|$SCOMMON|g" \
93+
| sed 's|{}||g')
94+
echo $ret
95+
}
96+
97+
function CatToIni {
98+
ret=$(echo "$1" \
99+
| sed 's|-|.|g' \
100+
| sed 's|\ |_|g' \
101+
| sed 's|99|_|g')
102+
echo $ret
103+
}
104+
function OptToIni {
105+
ret=$(echo "$1" \
106+
| tr '[:lower:]' '[:upper:]' \
107+
| sed 's|-|_|g')
108+
echo $ret
109+
}
110+
111+
[[ "$1" = "configure" ]] \
112+
&& toIni \
113+
&& exit 0
114+
115+
[[ "$1" = "install" ]] \
116+
&& echo "Initial Configuration..." \
117+
&& mkdir -p $SNAP_COMMON/conf \
118+
&& toSnap init \
119+
&& toSnap snap \
120+
&& toIni sample \
121+
&& exit 0
122+
123+
[[ "$1" = "save" ]] \
124+
&& echo "Saving current config..." \
125+
&& toSnap \
126+
&& exit 0

snap/helpers/simple_launcher.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
if ! env | grep -q root; then
4+
echo "
5+
+----------------------------------------+
6+
| You are not running gitea as root. |
7+
| This is required for the snap package. |
8+
| Please re-run as root. |
9+
+----------------------------------------+
10+
"
11+
$SNAP/gitea/gitea --help
12+
exit 1
13+
fi
14+
15+
# Set usernames for gitea
16+
export USERNAME=root
17+
export USER=root
18+
19+
export GITEA_WORK_DIR=$(snapctl get gitea.snap.workdir)
20+
export GITEA_CUSTOM=$(snapctl get gitea.snap.custom)
21+
22+
$SNAP/bin/gconfig save
23+
cd $SNAP/gitea; ./gitea $@

snap/hooks/configure

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
$SNAP/bin/gconfig configure

snap/hooks/install

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
export SDATA=$(echo $SNAP_DATA | sed "s|$SNAP_REVISION|current|")
4+
export SCOMMON="$SNAP_COMMON"
5+
export isRoot=`true`
6+
snapctl set gitea.snap.workdir="$SDATA/custom"
7+
snapctl set gitea.snap.custom="$SCOMMON"
8+
9+
function mkDirCommon(){
10+
for dir in $@; do
11+
mkdir -p "$SCOMMON/$dir"
12+
done
13+
}
14+
15+
function mkdirData(){
16+
for dir in $@; do
17+
mkdir -p "$SDATA/$dir"
18+
if [ -d $SNAP/$dir ]; then
19+
cp -r --preserve=mode \
20+
$SNAP/$dir/* \
21+
$SNAP/$dir/.[a-zA-Z0-9-]* \
22+
$SDATA/$dir/ 2> $SCOMMON/log/snap-mkdirData.log
23+
fi
24+
done
25+
}
26+
27+
mkDirCommon pictures \
28+
repositories \
29+
attachments \
30+
data \
31+
log
32+
33+
mkdirData certs \
34+
sshkeytest \
35+
custom/conf \
36+
static/templates \
37+
static/scripts \
38+
static/public
39+
40+
[[ -f $SNAP_COMMON/conf/app.ini ]] || $SNAP/bin/gconfig install
41+
42+
# Configure Git to use the right templates
43+
mkdir -p $SDATA/git/
44+
cp -r --preserve=mode $SNAP/usr/share/git-core/templates $SDATA/git/
45+
$SNAP/usr/bin/git config --global init.templateDir $SDATA/git/templates/

0 commit comments

Comments
 (0)