initial commit

This commit is contained in:
crystal 2023-02-06 03:29:43 -07:00
commit 514499661e
No known key found for this signature in database
GPG key ID: 1122054731F7CC43
24 changed files with 3199 additions and 0 deletions

118
.ci-make.sh Executable file
View file

@ -0,0 +1,118 @@
#!/bin/sh
CI_VERIFY_API="https://codeberg.org" # Query the Forgejo API at this URL to check upstream CI status
CI_VERIFY_REPO="forgejo/forgejo" # Check this repo at the Forgejo API for upstream CI status
CI_VERIFY_RETRY_TIME=120 # How long to wait in seconds before retrying if the pipeline is pending
CI_VERIFY_RETRY_COUNT=30 # How many times to retry before giving up if the pipeline is pending
case "$1" in
"submodule-build")
cd "$2"
make build
EXIT_STATUS=$?
mv gitea ../"$3"
exit $EXIT_STATUS
;;
"submodule-make")
cd "$2"
shift;shift
make "$@"
exit $?
;;
"ci-verify")
RETRY_LOOPS=0
while [ $RETRY_LOOPS -le $CI_VERIFY_RETRY_COUNT ] ; do
RETRY_LOOPS=$(($RETRY_LOOPS + 1))
CURRENT_COMMIT=$(git submodule status "$2/" | cut -d ' ' -f2)
CI_VERIFY=$(curl $CI_VERIFY_API/api/v1/repos/$CI_VERIFY_REPO/commits/$CURRENT_COMMIT/status | jq --jsonargs .state)
case "$CI_VERIFY" in
'"success"')
echo "CI pipeline passed!"
exit 0
;;
'"pending"')
echo "CI pipeline still pending, checking again in $CI_VERIFY_RETRY seconds..."
sleep $CI_VERIFY_RETRY
;;
*)
echo "ERROR: Bad pipeline status $CI_VERIFY"
exit 1
;;
esac
done
exit 255
;;
"download-binary")
if [ $CI_COMMIT_TAG ] ; then
CI_RELEASE_ASSETS=$(curl $CI_VERIFY_API/api/v1/repos/$CI_VERIFY_REPO/releases/tags/$CI_COMMIT_TAG | jq -c '.assets[]' | grep linux-amd64)
CI_RELEASE_BINARY_URL=$(echo "$CI_RELEASE_ASSETS" | grep linux-amd64\" | jq -r --jsonargs .browser_download_url)
CI_RELEASE_SHA256=$(curl $(echo "$CI_RELEASE_ASSETS" | grep linux-amd64.sha256\" | jq -r --jsonargs .browser_download_url) | cut -d ' ' -f1)
wget --content-disposition $CI_RELEASE_BINARY_URL
DOWNLOAD_SHA256=$(sha256sum forgejo-*-linux-amd64 | cut -d ' ' -f1)
if [ $CI_RELEASE_SHA256 != $DOWNLOAD_SHA256 ] ; then
echo "ERROR: Downloaded file didn't match expected SHA256 sum"
exit 1
fi
mv forgejo-*-linux-amd64 $2
chmod +x $2
exit 0
else
echo "not a tag, skipping download"
exit 0
fi
;;
"package-prep")
mkdir deb/forgejo-bin
mkdir deb/forgejo-sqlite-bin
mv forgejo-bin deb/forgejo-bin/forgejo
mv forgejo-sqlite-bin deb/forgejo-sqlite-bin/forgejo
if [ -x forgejo-bin-dl ] ; then
mkdir deb/forgejo-bin-dl
mv forgejo-bin-dl deb/forgejo-bin-dl/forgejo
mv deb/.forgejo-bin.install deb/debian/forgejo-bin.install
ln -s forgejo.preinst deb/debian/forgejo-bin.preinst
ln -s forgejo.postinst deb/debian/forgejo-bin.postinst
ln -s forgejo.prerm deb/debian/forgejo-bin.prerm
echo >> deb/debian/control
cat deb/.forgejo-bin.control >> deb/debian/control
fi
;;
"package-build")
cd deb
dpkg-buildpackage -b
exit $?
;;
"package-clean")
rm *dbgsym*.deb || true
exit 0
;;
"pkg-gen-sha256")
for deb in *.deb ; do
sha256sum $deb > $deb.sha256
done
;;
"preview-sha256")
for p in *.sha256 ; do
echo $p
cat $p
done
;;
"test-userinst-prep")
cp ./etc/default/forgejo /etc/default/forgejo
mkdir -p /etc/systemd/system/forgejo.service.d
cp ./etc/systemd/system/forgejo.service.d/override.conf /etc/systemd/system/forgejo.service.d/override.conf
;;
"install-run-test")
apt install ./"$2"
[ -f "/etc/default/forgejo" ] && . /etc/default/forgejo
[ -z "$FORGEJO_HOME" ] && FORGEJO_HOME=/var/lib/forgejo
[ -z "$FORGEJO_USER" ] && FORGEJO_USER=forgejo
sudo -u $FORGEJO_USER USER=$FORGEJO_USER \
HOME=$FORGEJO_HOME GITEA_WORK_DIR=$FORGEJO_HOME \
forgejo web --config /etc/forgejo/app.ini &
sleep 10
curl http://localhost:3000/
exit $?
;;
esac

293
.crystalintegration.yml Normal file
View file

@ -0,0 +1,293 @@
platform: linux/amd64
when:
event: [ push, tag ]
variables:
- &ci_verify_image 'sc.cryxtal.org/ci-img/git-curl-jq:latest'
- &golang_image 'golang:1.19'
- &forgejo_test_image 'codeberg.org/forgejo/test_env:1.18'
- &nodejs_image 'node:lts'
- &bin_dl_image 'sc.cryxtal.org/ci-img/bin-dl:latest'
- &deb_build_image 'sc.cryxtal.org/ci-img/dh:bullseye'
- &deb_test_image_bullseye 'sc.cryxtal.org/ci-img/deb-test-img:bullseye'
- &deb_test_image_buster 'sc.cryxtal.org/ci-img/deb-test-img:buster'
- &deb_test_image_sid 'sc.cryxtal.org/ci-img/deb-test-img:sid-780e05e2a5'
- &deb_test_image_jammy 'sc.cryxtal.org/ci-img/deb-test-img:jammy'
- &deb_test_image_focal 'sc.cryxtal.org/ci-img/deb-test-img:focal'
- &deb_test_image_kinetic 'sc.cryxtal.org/ci-img/deb-test-img:kinetic'
- &build_submodule 'forgejo'
- &goproxy_override ''
- &goproxy_setup |-
if [ -n "$${GOPROXY_OVERRIDE:-}" ]; then
export GOPROXY="$${GOPROXY_OVERRIDE}";
echo "Using goproxy from goproxy_override \"$${GOPROXY}\"";
elif [ -n "$${GOPROXY_DEFAULT:-}" ]; then
export GOPROXY="$${GOPROXY_DEFAULT}";
echo "Using goproxy from goproxy_default (secret) not displaying";
else
export GOPROXY="https://proxy.golang.org,direct";
echo "No goproxy overrides or defaults given, using \"$${GOPROXY}\"";
fi
workspace:
base: /go
path: src/cryxtal/forgejo-deb
clone:
clone-recursive:
image: woodpeckerci/plugin-git
settings:
recursive: true
pipeline:
fetch-tags:
image: *ci_verify_image
pull: true
commands:
- git config --add safe.directory '*'
- git fetch --tags --force
- git submodule foreach 'git fetch --tags --force'
ci-verify:
image: *ci_verify_image
group: deps
environment:
BUILD_SUBMODULE: *build_submodule
commands:
- ./.ci-make.sh ci-verify "$BUILD_SUBMODULE"
deps-frontend:
image: *nodejs_image
group: deps
environment:
BUILD_SUBMODULE: *build_submodule
commands:
- ./.ci-make.sh submodule-make "$BUILD_SUBMODULE" deps-frontend
deps-backend:
image: *golang_image
group: deps
environment:
BUILD_SUBMODULE: *build_submodule
GOPROXY_OVERRIDE: *goproxy_override
secrets:
- goproxy_default
commands:
- *goproxy_setup
- ./.ci-make.sh submodule-make "$BUILD_SUBMODULE" deps-backend
tag-pre-condition:
image: *ci_verify_image
environment:
BUILD_SUBMODULE: *build_submodule
commands:
- cd "$BUILD_SUBMODULE"
- git update-ref refs/heads/tag_test $(git rev-parse --verify HEAD)
security-check:
image: *golang_image
group: checks
environment:
BUILD_SUBMODULE: *build_submodule
GOPROXY_OVERRIDE: *goproxy_override
secrets:
- goproxy_default
commands:
- *goproxy_setup
- ./.ci-make.sh submodule-make "$BUILD_SUBMODULE" security-check
build-frontend:
image: *nodejs_image
group: checks
environment:
BUILD_SUBMODULE: *build_submodule
commands:
- ./.ci-make.sh submodule-make "$BUILD_SUBMODULE" frontend
checks-backend:
image: *forgejo_test_image
group: checks
environment:
BUILD_SUBMODULE: *build_submodule
GOPROXY_OVERRIDE: *goproxy_override
secrets:
- goproxy_default
commands:
- *goproxy_setup
- ./.ci-make.sh submodule-make "$BUILD_SUBMODULE" checks-backend
download-bin-amd64:
image: *bin_dl_image
group: build-main
commands:
- ./.ci-make.sh download-binary forgejo-bin-dl
when:
event: [ tag ]
build-forgejo-amd64:
image: *golang_image
group: build-main
environment:
BUILD_SUBMODULE: *build_submodule
GOSUMDB: sum.golang.org
TAGS: bindata
GOPROXY_OVERRIDE: *goproxy_override
secrets:
- goproxy_default
commands:
- *goproxy_setup
- ./.ci-make.sh submodule-build "$BUILD_SUBMODULE" forgejo-bin
build-forgejo-sqlite-amd64:
image: *golang_image
environment:
BUILD_SUBMODULE: *build_submodule
GOSUMDB: sum.golang.org
TAGS: bindata sqlite sqlite_unlock_notify
GOPROXY_OVERRIDE: *goproxy_override
secrets:
- goproxy_default
commands:
- *goproxy_setup
- ./.ci-make.sh submodule-build "$BUILD_SUBMODULE" forgejo-sqlite-bin
package-bullseye:
image: *deb_build_image
commands:
- ./.ci-make.sh package-prep
- ./.ci-make.sh package-build
- ./.ci-make.sh package-clean
gen-sha256:
image: *ci_verify_image
commands:
- ./.ci-make.sh pkg-gen-sha256
- ./.ci-make.sh preview-sha256
test-inst-bullseye:
image: *deb_test_image_bullseye
group: pkg-test-1
commands:
- ./.ci-make.sh install-run-test ./forgejo_*_amd64.deb
test-inst-bullseye-user:
image: *deb_test_image_bullseye
group: pkg-test-1
commands:
- ./.ci-make.sh test-userinst-prep
- ./.ci-make.sh install-run-test ./forgejo_*_amd64.deb
test-inst-bullseye-sqlite:
image: *deb_test_image_bullseye
group: pkg-test-1
commands:
- ./.ci-make.sh install-run-test ./forgejo-sqlite_*_amd64.deb
test-inst-buster-sqlite:
image: *deb_test_image_buster
group: pkg-test-1
commands:
- ./.ci-make.sh install-run-test ./forgejo-sqlite_*_amd64.deb
test-inst-sid-sqlite:
image: *deb_test_image_sid
group: pkg-test-2
commands:
- ./.ci-make.sh install-run-test ./forgejo-sqlite_*_amd64.deb
test-inst-jammy-sqlite:
image: *deb_test_image_jammy
group: pkg-test-2
commands:
- ./.ci-make.sh install-run-test ./forgejo-sqlite_*_amd64.deb
test-inst-focal-sqlite:
image: *deb_test_image_focal
group: pkg-test-2
commands:
- ./.ci-make.sh install-run-test ./forgejo-sqlite_*_amd64.deb
test-inst-kinetic-sqlite:
image: *deb_test_image_kinetic
group: pkg-test-2
commands:
- ./.ci-make.sh install-run-test ./forgejo-sqlite_*_amd64.deb
test-inst-bullseye-bin:
image: *deb_test_image_bullseye
group: pkg-test-3
commands:
- ./.ci-make.sh install-run-test ./forgejo-bin_*_amd64.deb
when:
event: [ tag ]
test-inst-buster-bin:
image: *deb_test_image_buster
group: pkg-test-3
commands:
- ./.ci-make.sh install-run-test ./forgejo-bin_*_amd64.deb
when:
event: [ tag ]
test-inst-sid-bin:
image: *deb_test_image_sid
group: pkg-test-3
commands:
- ./.ci-make.sh install-run-test ./forgejo-bin_*_amd64.deb
when:
event: [ tag ]
test-inst-jammy-bin:
image: *deb_test_image_jammy
group: pkg-test-4
commands:
- ./.ci-make.sh install-run-test ./forgejo-bin_*_amd64.deb
when:
event: [ tag ]
test-inst-focal-bin:
image: *deb_test_image_focal
group: pkg-test-4
commands:
- ./.ci-make.sh install-run-test ./forgejo-bin_*_amd64.deb
when:
event: [ tag ]
test-inst-kinetic-bin:
image: *deb_test_image_kinetic
group: pkg-test-4
commands:
- ./.ci-make.sh install-run-test ./forgejo-bin_*_amd64.deb
when:
event: [ tag ]
upload-crystalcommit:
image: woodpeckerci/plugin-gitea-release
group: upload
settings:
base_url: https://sc.cryxtal.org
files:
- "*.deb"
- "*.deb.sha256"
api_key:
from_secret: sc_api_key
prerelease: true
skip_verify: true
when:
event: [ tag ]
upload-codeberg:
image: woodpeckerci/plugin-gitea-release
group: upload
settings:
base_url: https://codeberg.org
files:
- "*.deb"
- "*.deb.sha256"
api_key:
from_secret: cb_api_key
prerelease: true
skip_verify: true
when:
event: [ tag ]

5
.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
forgejo-bin
forgejo-sqlite-bin
*.deb
deb/forgejo-bin/
deb/forgejo-sqlite-bin/

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "forgejo"]
path = forgejo
url = https://sc.cryxtal.org/mirror/forgejo

16
README.md Normal file
View file

@ -0,0 +1,16 @@
# Debian Packages for Forgejo
Hello! If you're want to run Forgejo on Debian/Ubuntu and you're looking for packages to install it to your system, you've come to the right place!
#### Build tests
[![ci-status](https://ci.cryxtal.org/api/badges/crystal/forgejo-deb/status.svg)](https://ci.cryxtal.org/crystal/forgejo-deb)
## Download info
You can find the latest release downloads in [the releases tab](https://codeberg.org/crystal/forgejo-deb/releases). There are currently 3 packages built by this script.
- `forgejo`: A basic production-ready Forgejo build without SQLite support
- `forgejo-sqlite`: A Forgejo build with SQLite support, best way to get started fast
- `forgejo-bin`: A Debian package with the official Forgejo binary, in case you don't trust my builds
## Installation
These packages are easy to use! Just download your preferred package, install it with `apt install ./forgejo-*-linux-amd64.deb` and point your browser to `http://localhost:3000`. The package will set up Forgejo as a systemd service and take care of creating a new user for Forgejo, so all you need to do is set it up to your liking.
The default username for Forgejo's user is `forgejo`, but it can easily be changed prior to installation, for example if you would rather run Forgejo as user `git`. All you need to do is download the files from the `etc` folder in this repository, put them in the respective places on your system, and customize them to your liking. When you use apt to install the Forgejo package, it will create a new user with the specified settings.

8
deb/.forgejo-bin.control Normal file
View file

@ -0,0 +1,8 @@
Package: forgejo-bin
Architecture: amd64
Priority: optional
Provides: forgejo,gitea
Depends: adduser (>= 3.11)
Conflicts: forgejo,forgejo-bin
Description: Forgejo: Beyond Coding. We Forge. (binary)
The official Forgejo release binary in a Debian package

3
deb/.forgejo-bin.install Normal file
View file

@ -0,0 +1,3 @@
forgejo-bin-dl/forgejo /usr/bin
forgejo.service /usr/lib/systemd/system
app.ini /etc/forgejo

2552
deb/app.ini Normal file

File diff suppressed because it is too large Load diff

8
deb/debian/changelog Normal file
View file

@ -0,0 +1,8 @@
forgejo (1.18.3.0-1) unstable; urgency=medium
* Forgejo version 1.18.3-0
* Use same versioning scheme as Arch package
* See https://codeberg.org/forgejo/forgejo/src/branch/forgejo/RELEASE-NOTES.md#1-18-3-0
-- crystal <crystal@noreply.codeberg.org> Fri, 3 Feb 2023 12:38:00 +0000

1
deb/debian/compat Normal file
View file

@ -0,0 +1 @@
10

23
deb/debian/control Normal file
View file

@ -0,0 +1,23 @@
Source: forgejo
Section: net
Priority: optional
Maintainer: crystal <crystal@noreply.codeberg.org>
Build-Depends: debhelper (>= 10)
Package: forgejo
Architecture: amd64
Priority: optional
Provides: gitea
Depends: adduser (>= 3.11)
Conflicts: forgejo-sqlite,forgejo-bin
Description: Forgejo: Beyond Coding. We Forge.
Forgejo with bindata ONLY - Use this package for MySQL or PostgreSQL setup
Package: forgejo-sqlite
Architecture: amd64
Priority: optional
Provides: forgejo,gitea
Depends: adduser (>= 3.11)
Conflicts: forgejo,forgejo-bin
Description: Forgejo: Beyond Coding. We Forge. (SQLite)
Forgejo with bindata and SQLite support - Use this package to get started immediately

View file

@ -0,0 +1,3 @@
forgejo-sqlite-bin/forgejo /usr/bin
forgejo.service /usr/lib/systemd/system
app.ini /etc/forgejo

View file

@ -0,0 +1 @@
forgejo.postinst

View file

@ -0,0 +1 @@
forgejo.preinst

View file

@ -0,0 +1 @@
forgejo.prerm

View file

@ -0,0 +1,3 @@
forgejo-bin/forgejo /usr/bin
forgejo.service /usr/lib/systemd/system
app.ini /etc/forgejo

View file

@ -0,0 +1,14 @@
#!/usr/bin/env bash
case "$1" in
configure)
[ -f "/etc/default/forgejo" ] && . /etc/default/forgejo
[ -z "$FORGEJO_HOME" ] && FORGEJO_HOME=/var/lib/forgejo
[ -z "$FORGEJO_USER" ] && FORGEJO_USER=forgejo
[ -z "$FORGEJO_NAME" ] && FORGEJO_NAME="Forgejo: Beyond coding. We forge."
[ -z "$FORGEJO_GROUP" ] && FORGEJO_GROUP=forgejo
chown $FORGEJO_USER:$FORGEJO_GROUP /etc/forgejo/app.ini
systemctl daemon-reload || true
systemctl restart forgejo || true
systemctl enable forgejo || true
;;
esac

View file

@ -0,0 +1,34 @@
#!/usr/bin/env bash
case "$1" in
install|upgrade)
[ -f "/etc/default/forgejo" ] && . /etc/default/forgejo
[ -z "$FORGEJO_HOME" ] && FORGEJO_HOME=/var/lib/forgejo
[ -z "$FORGEJO_USER" ] && FORGEJO_USER=forgejo
[ -z "$FORGEJO_NAME" ] && FORGEJO_NAME="Forgejo (Beyond coding. We forge.)"
[ -z "$FORGEJO_GROUP" ] && FORGEJO_GROUP=forgejo
if ! getent group | grep -q "^$FORGEJO_GROUP:" ; then
echo -n "Adding group $FORGEJO_GROUP.."
addgroup --quiet --system $FORGEJO_GROUP 2>/dev/null ||true
echo "..done"
fi
test -d $FORGEJO_HOME || mkdir $FORGEJO_HOME
if ! getent passwd | grep -q "^$FORGEJO_USER:"; then
echo -n "Adding system user $FORGEJO_USER.."
adduser --quiet \
--system \
--ingroup $FORGEJO_GROUP \
--no-create-home \
--disabled-password \
$FORGEJO_USER 2>/dev/null || true
echo "..done"
fi
usermod -c "$FORGEJO_NAME" \
-d $FORGEJO_HOME \
-g $FORGEJO_GROUP \
-s "/bin/bash" \
$FORGEJO_USER
if ! dpkg-statoverride --list $FORGEJO_HOME >/dev/null ; then
chown -R $FORGEJO_USER:$FORGEJO_GROUP $FORGEJO_HOME
chmod u=rwx,g=rwx,o= $FORGEJO_HOME
fi
esac

3
deb/debian/forgejo.prerm Normal file
View file

@ -0,0 +1,3 @@
#!/usr/bin/env bash
systemctl stop forgejo || true
systemctl disable forgejo || true

4
deb/debian/rules Normal file
View file

@ -0,0 +1,4 @@
#!/usr/bin/make -f
%:
dh $@ --with=systemd

86
deb/forgejo.service Normal file
View file

@ -0,0 +1,86 @@
[Unit]
Description=Forgejo (Beyond coding. We forge.)
After=syslog.target
After=network.target
###
# Don't forget to add the database service dependencies
###
#
#Wants=mysql.service
After=mysql.service
#
#Wants=mariadb.service
After=mariadb.service
#
#Wants=postgresql.service
After=postgresql.service
#
#Wants=memcached.service
After=memcached.service
#
#Wants=redis.service
After=redis.service
#
###
# If using socket activation for main http/s
###
#
#After=forgejo.main.socket
#Requires=forgejo.main.socket
#
###
# (You can also provide forgejo an http fallback and/or ssh socket too)
#
# An example of /etc/systemd/system/forgejo.main.socket
###
##
## [Unit]
## Description=Forgejo Web Socket
## PartOf=forgejo.service
##
## [Socket]
## Service=forgejo.service
## ListenStream=<some_port>
## NoDelay=true
##
## [Install]
## WantedBy=sockets.target
##
###
[Service]
# Uncomment the next line if you have repos with lots of files and get a HTTP 500 error because of that
# LimitNOFILE=524288:524288
RestartSec=2s
Type=simple
User=forgejo
Group=forgejo
WorkingDirectory=~
# If using Unix socket: tells systemd to create the /run/forgejo folder, which will contain the forgejo.sock file
# (manually creating /run/forgejo doesn't work, because it would not persist across reboots)
#RuntimeDirectory=forgejo
ExecStart=/usr/bin/forgejo web --config /etc/forgejo/app.ini
Restart=always
Environment=USER=forgejo HOME=/var/lib/forgejo GITEA_WORK_DIR=/var/lib/forgejo
# If you install Git to directory prefix other than default PATH (which happens
# for example if you install other versions of Git side-to-side with
# distribution version), uncomment below line and add that prefix to PATH
# Don't forget to place git-lfs binary on the PATH below if you want to enable
# Git LFS support
#Environment=PATH=/path/to/git/bin:/bin:/sbin:/usr/bin:/usr/sbin
# If you want to bind Forgejo to a port below 1024, uncomment
# the two values below, or use socket activation to pass Forgejo its ports as above
###
#CapabilityBoundingSet=CAP_NET_BIND_SERVICE
#AmbientCapabilities=CAP_NET_BIND_SERVICE
###
# In some cases, when using CapabilityBoundingSet and AmbientCapabilities option, you may want to
# set the following value to false to allow capabilities to be applied on Forgejo process. The following
# value if set to true sandboxes Forgejo service and prevent any processes from running with privileges
# in the host user namespace.
###
#PrivateUsers=false
###
[Install]
WantedBy=multi-user.target

12
etc/default/forgejo Normal file
View file

@ -0,0 +1,12 @@
# Forgejo's Home Directory
#FORGEJO_HOME=/var/lib/forgejo
# User to run Forgejo as (default: forgejo)
FORGEJO_USER=git
# Forgejo user description
#FORGEJO_NAME="Forgejo (Beyond coding. We forge.)"
# Group for Forgejo user (default: forgejo)
FORGEJO_GROUP=git

View file

@ -0,0 +1,6 @@
[Service]
# Uncomment the next line if you have repos with lots of files and get a HTTP 500 error because of that
# LimitNOFILE=524288:524288
User=git
Group=git
Environment=USER=git HOME=/var/lib/forgejo GITEA_WORK_DIR=/var/lib/forgejo

1
forgejo Submodule

@ -0,0 +1 @@
Subproject commit dd6f771d0b957e7c590f22801ba9f23e711364bd