THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Browse Source

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.
tags/v1.5.0-dev
Thorben 1 year ago
parent
commit
14f16d6c2e
7 changed files with 394 additions and 0 deletions
  1. 10
    0
      .gitignore
  2. 66
    0
      snap/helpers/app.ini
  3. 126
    0
      snap/helpers/configuration.sh
  4. 23
    0
      snap/helpers/simple_launcher.sh
  5. 3
    0
      snap/hooks/configure
  6. 45
    0
      snap/hooks/install
  7. 121
    0
      snap/snapcraft.yaml

+ 10
- 0
.gitignore View File

@@ -59,3 +59,13 @@ coverage.all
59 59
 /integrations/mysql.ini
60 60
 /integrations/pgsql.ini
61 61
 /node_modules
62
+
63
+
64
+# Snapcraft
65
+snap/.snapcraft/
66
+parts/
67
+stage/
68
+prime/
69
+*.snap
70
+*.snap-build
71
+*_source.tar.bz2

+ 66
- 0
snap/helpers/app.ini View File

@@ -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

+ 126
- 0
snap/helpers/configuration.sh View File

@@ -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

+ 23
- 0
snap/helpers/simple_launcher.sh View File

@@ -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 $@

+ 3
- 0
snap/hooks/configure View File

@@ -0,0 +1,3 @@
1
+#!/bin/bash
2
+
3
+$SNAP/bin/gconfig configure

+ 45
- 0
snap/hooks/install View File

@@ -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/

+ 121
- 0
snap/snapcraft.yaml View File

@@ -0,0 +1,121 @@
1
+name: gitea
2
+summary:  Gitea - A painless self-hosted Git service
3
+description: |
4
+  The goal of this project is to make the easiest, fastest, and most painless
5
+  way of setting up a self-hosted Git service. With Go, this can be done with
6
+  an independent binary distribution across ALL platforms that Go supports,
7
+  including Linux, Mac OS X, Windows and ARM.
8
+
9
+type: app
10
+icon: public/img/gitea-lg.png
11
+confinement: strict
12
+grade: stable
13
+
14
+version: 'git'
15
+
16
+apps:
17
+  gitea:
18
+    command: bin/gitea
19
+    plugs: [network, network-bind]
20
+  web:
21
+    command: bin/gitea web
22
+    daemon: simple
23
+    plugs: [network, network-bind]
24
+  serv:
25
+    command: bin/gitea serv
26
+    plugs: [network, network-bind]
27
+  admin:
28
+    command: bin/gitea admin
29
+    plugs: [network, network-bind]
30
+  cert:
31
+    command: bin/gitea cert
32
+  hook:
33
+    command: bin/gitea hook
34
+    plugs: [network, network-bind]
35
+  dump:
36
+    command: bin/gitea dump
37
+    plugs: [home]
38
+  help:
39
+    command: bin/gitea --help
40
+  version:
41
+    command: bin/gitea --version
42
+  sqlite:
43
+    command: usr/bin/sqlite3
44
+
45
+parts:
46
+  go:
47
+    source-tag: go1.8.3
48
+    prime:
49
+      - -*
50
+
51
+  gitea:
52
+    plugin: nil
53
+    source: .
54
+    source-type: git
55
+    after: [ go ]
56
+    stage-packages: [ git, sqlite3, openssh-client ]
57
+    build-packages: [ libpam0g-dev, libsqlite3-dev]
58
+    prepare: |
59
+      export PATH=$SNAPCRAFT_PART_INSTALL/../../go/install/bin:$PATH
60
+      export GOPATH=$SNAPCRAFT_PART_INSTALL/../go
61
+      export bld=$SNAPCRAFT_PART_INSTALL/../build
62
+      export src=$SNAPCRAFT_PART_INSTALL/../src
63
+      mkdir -p $GOPATH/src/code.gitea.io/gitea
64
+      cp -r $src/* $GOPATH/src/code.gitea.io/gitea
65
+    build: |
66
+      export PATH=$SNAPCRAFT_PART_INSTALL/../go/bin/:$SNAPCRAFT_PART_INSTALL/../../go/install/bin:$PATH
67
+      export GOPATH=$SNAPCRAFT_PART_INSTALL/../go
68
+      go get -u github.com/jteeuwen/go-bindata/...
69
+      cd $GOPATH/src/code.gitea.io/gitea
70
+      TAGS="bindata sqlite pam cert" make generate build
71
+    install: |
72
+      # Set Convenience Variables
73
+      src=$SNAPCRAFT_PART_INSTALL/../go/src/code.gitea.io/gitea
74
+      giteaBase=$SNAPCRAFT_PART_INSTALL/gitea
75
+      scurrent=/var/snap/$SNAPCRAFT_PROJECT_NAME/current
76
+      scommon=/var/snap/$SNAPCRAFT_PROJECT_NAME/common
77
+      # Copy build artifact and necessary files
78
+      mkdir -p $giteaBase/conf
79
+      # Workaround for gitea ignoring APP_DATA_PATH in app.ini after snap update.
80
+      ln -s $scurrent/custom $giteaBase/custom
81
+      ln -s $scommon/data $giteaBase/data
82
+      # Workaround for cmd/certs not knowing how to put files somewhere else
83
+      ln -s $scurrent/cert.pem $giteaBase/cert.pem
84
+      ln -s $scurrent/key.pem $giteaBase/key.pem
85
+      # Copy static content
86
+      mkdir -p $SNAPCRAFT_PART_INSTALL/static
87
+      cp    $src/gitea             $giteaBase/
88
+      cp -r $src/LICENSE \
89
+            $src/templates \
90
+            $src/public \
91
+            $src/scripts \
92
+            $SNAPCRAFT_PART_INSTALL/static/
93
+      cp -r $src/README.md \
94
+            $src/LICENSE  \
95
+            $src/custom \
96
+            $SNAPCRAFT_PART_INSTALL/
97
+    prime:
98
+      - -etc
99
+      - -usr/lib/systemd
100
+      - -usr/lib/gcc
101
+      - -usr/lib/sasl2
102
+      - -usr/lib/x86_64-linux-gnu/krb5
103
+      - -usr/share/apport
104
+      - -usr/share/bash-completion
105
+      - -usr/share/doc
106
+      - -usr/share/git-core/contrib
107
+      - -usr/share/man
108
+      - -usr/share/upstart
109
+      - -var
110
+
111
+  helpers:
112
+    plugin: dump
113
+    source: snap/helpers
114
+    organize:
115
+      simple_launcher.sh: bin/gitea
116
+      app.ini: gitea/snapApp.ini
117
+      configuration.sh: bin/gconfig
118
+    prime:
119
+      - bin/gitea
120
+      - bin/gconfig
121
+      - gitea/snapApp.ini

Loading…
Cancel
Save