Merge pull request 'unify packages & upgrades' (#107) from twenty-panda/end-to-end:wip-lib into main
Reviewed-on: https://code.forgejo.org/forgejo/end-to-end/pulls/107 Reviewed-by: earl-warren <earl-warren@noreply.code.forgejo.org>
This commit is contained in:
commit
62f75aa56f
10 changed files with 367 additions and 459 deletions
|
@ -1,43 +0,0 @@
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- 'main'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
packages:
|
|
||||||
runs-on: self-hosted
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
info:
|
|
||||||
- version: v7.0
|
|
||||||
branch: next
|
|
||||||
forgejo: https://codeberg.org
|
|
||||||
repo: forgejo-experimental/forgejo
|
|
||||||
tests: ${{ vars.V7_0_TESTS }}
|
|
||||||
- version: v1.21
|
|
||||||
forgejo: https://codeberg.org
|
|
||||||
repo: forgejo/forgejo
|
|
||||||
tests: ${{ vars.V1_21_TESTS }}
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- uses: https://code.forgejo.org/actions/setup-forgejo@v2
|
|
||||||
with:
|
|
||||||
install-only: true
|
|
||||||
|
|
||||||
- name: run
|
|
||||||
if: matrix.info.tests != 'none'
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
set -x
|
|
||||||
forgejo-binary.sh ensure_user forgejo
|
|
||||||
full_version=$(curl -sS ${{ matrix.info.forgejo }}/api/v1/repos/${{ matrix.info.repo }}/releases | jq -r '.[] | .tag_name | select(startswith("${{ matrix.info.version }}"))' | sort -r | head -1)
|
|
||||||
binary=${{ matrix.info.forgejo }}/${{ matrix.info.repo }}/releases/download/${full_version}/forgejo-${full_version#v}-linux-amd64
|
|
||||||
|
|
||||||
export DIR=$(mktemp -d)
|
|
||||||
chown forgejo $DIR /srv
|
|
||||||
|
|
||||||
export VERBOSE="${{ vars.VERBOSE || false }}"
|
|
||||||
|
|
||||||
su -c "packages/run.sh $binary $full_version ${{ matrix.info.version }} ${{ matrix.info.tests }}" forgejo
|
|
|
@ -8,9 +8,7 @@ on:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
upgrade:
|
upgrade:
|
||||||
runs-on: docker
|
runs-on: lxc-bookworm
|
||||||
container:
|
|
||||||
image: 'docker.io/node:20-bookworm'
|
|
||||||
steps:
|
steps:
|
||||||
- name: cache S3 binaries
|
- name: cache S3 binaries
|
||||||
id: S3
|
id: S3
|
||||||
|
@ -27,13 +25,16 @@ jobs:
|
||||||
run: echo no hit
|
run: echo no hit
|
||||||
|
|
||||||
- uses: https://code.forgejo.org/actions/checkout@v4
|
- uses: https://code.forgejo.org/actions/checkout@v4
|
||||||
|
- uses: https://code.forgejo.org/actions/setup-forgejo@v2
|
||||||
|
with:
|
||||||
|
install-only: true
|
||||||
- uses: https://code.forgejo.org/actions/setup-go@v4
|
- uses: https://code.forgejo.org/actions/setup-go@v4
|
||||||
with:
|
with:
|
||||||
go-version: "1.21"
|
go-version: "1.21"
|
||||||
- run: |
|
- run: |
|
||||||
git config --add safe.directory '*'
|
set -x
|
||||||
adduser --quiet --comment forgejo --disabled-password forgejo
|
forgejo-binary.sh ensure_user forgejo
|
||||||
chown -R forgejo:forgejo .
|
apt-get -q install -y -qq build-essential
|
||||||
- run: |
|
- run: |
|
||||||
script=$(pwd)/forgejo/upgrades/test-upgrade.sh
|
script=$(pwd)/forgejo/upgrades/test-upgrade.sh
|
||||||
$script run dependencies
|
$script run dependencies
|
||||||
|
|
29
README.md
29
README.md
|
@ -95,34 +95,19 @@ it does not exist, all tests are run.
|
||||||
* `V1_21_TESTS`
|
* `V1_21_TESTS`
|
||||||
* `V1_20_TESTS`
|
* `V1_20_TESTS`
|
||||||
|
|
||||||
## Running packages locally
|
## Running other tests locally
|
||||||
|
|
||||||
To run and debug package tests, from the root of the source directory.
|
To run and debug tests, from the root of the source directory.
|
||||||
|
|
||||||
Run one test
|
Run one test. When the test fails the instance can be inspected at http://0.0.0.0:3000
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
packages/run.sh https://codeberg.org/forgejo-experimental/forgejo/releases/download/v7.0.0-test/forgejo-7.0.0-test-linux-amd64 v7.0.0-test v7_0 alpine # runs packages/alpine.sh
|
VERBOSE=true ./forgejo/upgrades/test-upgrade.sh test_packages_alpine
|
||||||
|
VERBOSE=true ./forgejo/upgrades/test-upgrade.sh test_storage_stable_s3 minio
|
||||||
```
|
```
|
||||||
|
|
||||||
Cleanup. It will teardown Forgejo and not run them because there is nothing to test.
|
Cleanup. It will teardown the Forgejo instance.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
packages/run.sh https://codeberg.org/forgejo-experimental/forgejo/releases/download/v7.0.0-test/forgejo-7.0.0-test-linux-amd64 v7.0.0-test v7_0 none
|
./forgejo/upgrades/test-upgrade.sh stop
|
||||||
```
|
```
|
||||||
Run all examples for v7_0
|
|
||||||
|
|
||||||
```sh
|
|
||||||
packages/run.sh https://codeberg.org/forgejo-experimental/forgejo/releases/download/v7.0.0-test/forgejo-7.0.0-test-linux-amd64 v7.0.0-test v7_0
|
|
||||||
```
|
|
||||||
|
|
||||||
Remote testing
|
|
||||||
|
|
||||||
To reduce the runtime the following variables can be set to control
|
|
||||||
the number of cases run by the
|
|
||||||
[packages test](.forgejo/workflows/packages.yml) tests. If set to
|
|
||||||
**none** they are not run at all for that version of Forgejo. If
|
|
||||||
it does not exist, all tests are run.
|
|
||||||
|
|
||||||
* `v7_0_PACKAGES_TESTS`
|
|
||||||
* `V1_21_PACKAGES_TESTS`
|
|
||||||
|
|
|
@ -11,293 +11,19 @@
|
||||||
# Everything happens in /tmp/forgejo-upgrades
|
# Everything happens in /tmp/forgejo-upgrades
|
||||||
#
|
#
|
||||||
|
|
||||||
#
|
SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
# Forgejo releases for which a branch exists (7.0/forgejo etc.)
|
SELF="${BASH_SOURCE[0]}"
|
||||||
#
|
source $SELF_DIR/../../lib/lib.sh
|
||||||
RELEASE_NUMBERS="7.0"
|
|
||||||
|
|
||||||
PREFIX===============
|
|
||||||
HOST_PORT=0.0.0.0:3000
|
|
||||||
STORAGE_PATHS="attachments avatars lfs packages repo-archive repo-avatars"
|
STORAGE_PATHS="attachments avatars lfs packages repo-archive repo-avatars"
|
||||||
STORAGE_FUN="attachments avatars lfs packages repo_archive repo_avatars"
|
STORAGE_FUN="attachments avatars lfs packages repo_archive repo_avatars"
|
||||||
DIR=/tmp/forgejo-upgrades
|
|
||||||
export DOT_FORGEJO_CURL=$DIR/forgejo-curl
|
|
||||||
export DOT=$DOT_FORGEJO_CURL # for backward compatibility with forgejo-curl.sh 1.0.0
|
|
||||||
if ${VERBOSE:-false} ; then
|
|
||||||
set -ex
|
|
||||||
PS4='${BASH_SOURCE[0]}:$LINENO: ${FUNCNAME[0]}: '
|
|
||||||
else
|
|
||||||
set -e
|
|
||||||
fi
|
|
||||||
SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
||||||
: ${FORGEJO_USER:=root}
|
|
||||||
: ${FORGEJO_REPO:=fixture}
|
: ${FORGEJO_REPO:=fixture}
|
||||||
: ${FORGEJO_PASSWORD:=admin1234}
|
|
||||||
RELEASE_NUMBERS_AND_DEV="$(for r in $RELEASE_NUMBERS ; do echo -n $r $r-dev ; done)"
|
|
||||||
|
|
||||||
source $SELF_DIR/fixtures.sh
|
source $SELF_DIR/fixtures.sh
|
||||||
|
|
||||||
function maybe_sudo() {
|
|
||||||
if test $(id -u) != 0 ; then
|
|
||||||
SUDO=sudo
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function log_info() {
|
|
||||||
echo "$PREFIX $@"
|
|
||||||
}
|
|
||||||
|
|
||||||
function dependencies() {
|
|
||||||
maybe_sudo
|
|
||||||
|
|
||||||
if ! test -f /usr/local/bin/forgejo-curl.sh ; then
|
|
||||||
$SUDO curl --fail -sS https://code.forgejo.org/forgejo/forgejo-curl/raw/branch/main/forgejo-curl.sh -o /usr/local/bin/forgejo-curl.sh
|
|
||||||
$SUDO chmod +x /usr/local/bin/forgejo-curl.sh
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! which curl daemon jq git-lfs > /dev/null ; then
|
|
||||||
export DEBIAN_FRONTEND=noninteractive
|
|
||||||
$SUDO apt-get update -qq
|
|
||||||
$SUDO apt-get install -y -qq curl daemon git-lfs jq sqlite3 gettext-base
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! test -f /usr/local/bin/mc || ! test -f /usr/local/bin/minio ; then
|
|
||||||
$SUDO curl --fail -sS https://dl.min.io/client/mc/release/linux-amd64/mc -o /usr/local/bin/mc
|
|
||||||
$SUDO curl --fail -sS https://dl.min.io/server/minio/release/linux-amd64/minio -o /usr/local/bin/minio
|
|
||||||
fi
|
|
||||||
if ! test -x /usr/local/bin/mc || ! test -x /usr/local/bin/minio ; then
|
|
||||||
$SUDO chmod +x /usr/local/bin/mc
|
|
||||||
$SUDO chmod +x /usr/local/bin/minio
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! test -f /usr/local/bin/garage > /dev/null ; then
|
|
||||||
$SUDO curl --fail -sS https://garagehq.deuxfleurs.fr/_releases/v0.8.2/x86_64-unknown-linux-musl/garage -o /usr/local/bin/garage
|
|
||||||
fi
|
|
||||||
if ! test -x /usr/local/bin/garage > /dev/null ; then
|
|
||||||
$SUDO chmod +x /usr/local/bin/garage
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function build_all() {
|
|
||||||
for dev in $RELEASE_NUMBERS ; do
|
|
||||||
log_info $dev-dev
|
|
||||||
$SELF_DIR/../build.sh $dev $DIR
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
function retry() {
|
|
||||||
rm -f $DIR/wait-for.out
|
|
||||||
success=false
|
|
||||||
for delay in 1 1 5 5 15 ; do
|
|
||||||
if "$@" >> $DIR/wait-for.out 2>&1 ; then
|
|
||||||
success=true
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
cat $DIR/wait-for.out
|
|
||||||
echo waiting $delay
|
|
||||||
sleep $delay
|
|
||||||
done
|
|
||||||
if test $success = false ; then
|
|
||||||
cat $DIR/wait-for.out
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function full_version() {
|
|
||||||
local version=$1
|
|
||||||
local owner=$2
|
|
||||||
|
|
||||||
if [[ $version =~ ^[0-9]+\.[0-9]+$ ]] ; then
|
|
||||||
full_version=$(curl -sS https://codeberg.org/api/v1/repos/$owner/forgejo/releases | jq -r '.[] | .tag_name | select(startswith("v'$version'"))' | sort -r | head -1)
|
|
||||||
echo ${full_version#v}
|
|
||||||
else
|
|
||||||
echo $version
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function download() {
|
|
||||||
local version=$1
|
|
||||||
|
|
||||||
if ! test -f $DIR/forgejo-$version ; then
|
|
||||||
mkdir -p $DIR
|
|
||||||
for owner in forgejo forgejo-experimental forgejo-integration ; do
|
|
||||||
full_version=$(full_version $version $owner)
|
|
||||||
if test "$full_version" = "" ; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
if wget -O $DIR/forgejo-$version --quiet https://codeberg.org/$owner/forgejo/releases/download/v$full_version/forgejo-$full_version-linux-amd64 ; then
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
if test -s $DIR/forgejo-$version ; then
|
|
||||||
if test "$version" != "$full_version" ; then
|
|
||||||
log_info "downloaded $full_version for $version"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo unable to download Forgejo $version
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
chmod +x $DIR/forgejo-$version
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function cleanup_logs() {
|
|
||||||
local work_path=$DIR/forgejo-work-path
|
|
||||||
|
|
||||||
rm -f $DIR/*.log
|
|
||||||
rm -f $work_path/log/*.log
|
|
||||||
}
|
|
||||||
|
|
||||||
function clobber() {
|
|
||||||
rm -fr /tmp/forgejo-upgrades
|
|
||||||
}
|
|
||||||
|
|
||||||
function start_forgejo() {
|
|
||||||
local version=$1
|
|
||||||
|
|
||||||
download $version
|
|
||||||
local work_path=$DIR/forgejo-work-path
|
|
||||||
daemon --chdir=$DIR --unsafe --env="TERM=$TERM" --env="HOME=$HOME" --env="PATH=$PATH" --pidfile=$DIR/forgejo-pid --errlog=$DIR/forgejo-err.log --output=$DIR/forgejo-out.log -- $DIR/forgejo-$version --config $work_path/app.ini --work-path $work_path
|
|
||||||
if ! retry grep 'Starting server on' $work_path/log/forgejo.log ; then
|
|
||||||
grep '' $DIR/*.log
|
|
||||||
grep '' $work_path/log/*.log 2> /dev/null
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
create_user_and_login $version
|
|
||||||
}
|
|
||||||
|
|
||||||
function start_minio() {
|
|
||||||
mkdir -p $DIR/minio
|
|
||||||
daemon --chdir=$DIR --unsafe \
|
|
||||||
--env="PATH=$PATH" \
|
|
||||||
--env=MINIO_ROOT_USER=123456 \
|
|
||||||
--env=MINIO_ROOT_PASSWORD=12345678 \
|
|
||||||
--env=MINIO_VOLUMES=$DIR/minio \
|
|
||||||
--pidfile=$DIR/minio-pid --errlog=$DIR/minio-err.log --output=$DIR/minio-out.log -- /usr/local/bin/minio server
|
|
||||||
retry mc alias set testS3 http://127.0.0.1:9000 123456 12345678
|
|
||||||
}
|
|
||||||
|
|
||||||
function start_garage() {
|
|
||||||
mkdir -p $DIR/garage/{data,meta}
|
|
||||||
cat > $DIR/garage/garage.toml <<EOF
|
|
||||||
metadata_dir = "$DIR/garage/meta"
|
|
||||||
data_dir = "$DIR/garage/data"
|
|
||||||
db_engine = "lmdb"
|
|
||||||
|
|
||||||
replication_mode = "none"
|
|
||||||
|
|
||||||
rpc_bind_addr = "127.0.0.1:3901"
|
|
||||||
rpc_public_addr = "127.0.0.1:3901"
|
|
||||||
rpc_secret = "$(openssl rand -hex 32)"
|
|
||||||
|
|
||||||
[s3_api]
|
|
||||||
s3_region = "us-east-1"
|
|
||||||
api_bind_addr = "127.0.0.1:9000"
|
|
||||||
root_domain = ".s3.garage.localhost"
|
|
||||||
|
|
||||||
[s3_web]
|
|
||||||
bind_addr = "127.0.0.1:3902"
|
|
||||||
root_domain = ".web.garage.localhost"
|
|
||||||
index = "index.html"
|
|
||||||
|
|
||||||
[k2v_api]
|
|
||||||
api_bind_addr = "127.0.0.1:3904"
|
|
||||||
|
|
||||||
[admin]
|
|
||||||
api_bind_addr = "127.0.0.1:3903"
|
|
||||||
admin_token = "$(openssl rand -base64 32)"
|
|
||||||
EOF
|
|
||||||
|
|
||||||
daemon --chdir=$DIR --unsafe \
|
|
||||||
--env="PATH=$PATH" \
|
|
||||||
--env=RUST_LOG=garage_api=debug \
|
|
||||||
--pidfile=$DIR/garage-pid --errlog=$DIR/garage-err.log --output=$DIR/garage-out.log -- /usr/local/bin/garage -c $DIR/garage/garage.toml server
|
|
||||||
|
|
||||||
retry garage -c $DIR/garage/garage.toml status
|
|
||||||
garage -c $DIR/garage/garage.toml layout assign -z dc1 -c 1 $(garage -c $DIR/garage/garage.toml status | tail -1 | grep -o '[0-9a-z]*' | head -1)
|
|
||||||
ver=$(garage -c $DIR/garage/garage.toml layout show | grep -oP '(?<=Current cluster layout version: )\d+')
|
|
||||||
garage -c $DIR/garage/garage.toml layout apply --version $((ver+1))
|
|
||||||
garage -c $DIR/garage/garage.toml key info test || garage -c $DIR/garage/garage.toml key import -n test 123456 12345678
|
|
||||||
garage -c $DIR/garage/garage.toml key allow --create-bucket test
|
|
||||||
retry mc alias set testS3 http://127.0.0.1:9000 123456 12345678
|
|
||||||
}
|
|
||||||
|
|
||||||
function start_s3() {
|
|
||||||
local s3_backend=$1
|
|
||||||
|
|
||||||
start_$s3_backend
|
|
||||||
}
|
|
||||||
|
|
||||||
function start() {
|
|
||||||
local version=$1
|
|
||||||
local s3_backend=${2:-minio}
|
|
||||||
|
|
||||||
start_s3 $s3_backend
|
|
||||||
start_forgejo $version
|
|
||||||
}
|
|
||||||
|
|
||||||
function create_user_and_login() {
|
|
||||||
local version=$1
|
|
||||||
|
|
||||||
local work_path=$DIR/forgejo-work-path
|
|
||||||
local email="$FORGEJO_USER@example.com"
|
|
||||||
local cli="$DIR/forgejo-$version --config $work_path/app.ini --work-path $work_path"
|
|
||||||
if ! $cli admin user list | grep --quiet "$email" ; then
|
|
||||||
$cli admin user create --admin --username "$FORGEJO_USER" --password "$FORGEJO_PASSWORD" --email $email
|
|
||||||
fi
|
|
||||||
|
|
||||||
forgejo-curl.sh logout
|
|
||||||
local scopes='--scopes ["all"]'
|
|
||||||
if echo $version | grep --quiet 1.18 ; then
|
|
||||||
scopes=""
|
|
||||||
fi
|
|
||||||
forgejo-curl.sh --user "$FORGEJO_USER" --password "$FORGEJO_PASSWORD" $scopes login http://${HOST_PORT}
|
|
||||||
}
|
|
||||||
|
|
||||||
function stop_daemon() {
|
|
||||||
local daemon=$1
|
|
||||||
|
|
||||||
if test -f $DIR/$daemon-pid ; then
|
|
||||||
local pid=$(cat $DIR/$daemon-pid)
|
|
||||||
kill -TERM $pid
|
|
||||||
pidwait $pid || true
|
|
||||||
for delay in 1 1 2 2 5 5 ; do
|
|
||||||
if ! test -f $DIR/$daemon-pid ; then
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
sleep $delay
|
|
||||||
done
|
|
||||||
! test -f $DIR/$daemon-pid
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function stop() {
|
|
||||||
stop_daemon forgejo
|
|
||||||
stop_daemon minio
|
|
||||||
stop_daemon garage
|
|
||||||
|
|
||||||
cleanup_logs
|
|
||||||
}
|
|
||||||
|
|
||||||
function reset_forgejo() {
|
|
||||||
local config=$1
|
|
||||||
local work_path=$DIR/forgejo-work-path
|
|
||||||
rm -fr $work_path
|
|
||||||
mkdir -p $work_path
|
|
||||||
WORK_PATH=$work_path envsubst < $SELF_DIR/$config-app.ini > $work_path/app.ini
|
|
||||||
}
|
|
||||||
|
|
||||||
function reset_minio() {
|
|
||||||
rm -fr $DIR/minio
|
|
||||||
}
|
|
||||||
|
|
||||||
function reset_garage() {
|
|
||||||
rm -fr $DIR/garage
|
|
||||||
}
|
|
||||||
|
|
||||||
function reset() {
|
function reset() {
|
||||||
local config=$1
|
local config=$1
|
||||||
reset_forgejo $config
|
reset_forgejo $SELF_DIR/$config-app.ini
|
||||||
reset_minio
|
reset_minio
|
||||||
reset_garage
|
reset_garage
|
||||||
}
|
}
|
||||||
|
@ -337,6 +63,7 @@ function test_storage_stable_s3() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_successful_upgrades() {
|
function test_successful_upgrades() {
|
||||||
|
stop
|
||||||
for config in default specific ; do
|
for config in default specific ; do
|
||||||
log_info "using $config app.ini"
|
log_info "using $config app.ini"
|
||||||
reset $config
|
reset $config
|
||||||
|
@ -359,33 +86,17 @@ function test_forgejo_database_version() {
|
||||||
test "$expected_version" = "$actual_version"
|
test "$expected_version" = "$actual_version"
|
||||||
}
|
}
|
||||||
|
|
||||||
function run() {
|
|
||||||
local fun=$1
|
|
||||||
shift
|
|
||||||
|
|
||||||
echo Start running $fun
|
|
||||||
mkdir -p $DIR
|
|
||||||
> $DIR/$fun.out
|
|
||||||
tail --follow $DIR/$fun.out | sed --unbuffered -n -e "/^$PREFIX/s/^$PREFIX //p" &
|
|
||||||
pid=$!
|
|
||||||
if ! VERBOSE=true ${BASH_SOURCE[0]} $fun "$@" >& $DIR/$fun.out ; then
|
|
||||||
kill $pid
|
|
||||||
cat $DIR/$fun.out
|
|
||||||
echo Failure running $fun
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
kill $pid
|
|
||||||
echo Success running $fun
|
|
||||||
}
|
|
||||||
|
|
||||||
source $SELF_DIR/test-upgrade-1.20-storage.sh
|
source $SELF_DIR/test-upgrade-1.20-storage.sh
|
||||||
source $SELF_DIR/test-upgrade-forgejo-database-v3.sh
|
source $SELF_DIR/test-upgrade-forgejo-database-v3.sh
|
||||||
|
source $SELF_DIR/../../packages/packages.sh
|
||||||
|
|
||||||
function test_upgrades() {
|
function test_upgrades() {
|
||||||
run stop
|
run stop
|
||||||
run dependencies
|
run dependencies
|
||||||
run build_all
|
run build_all
|
||||||
|
|
||||||
|
test_packages
|
||||||
|
|
||||||
run test_successful_upgrades
|
run test_successful_upgrades
|
||||||
run test_storage_stable_s3 minio
|
run test_storage_stable_s3 minio
|
||||||
run test_storage_stable_s3 garage
|
run test_storage_stable_s3 garage
|
||||||
|
|
|
@ -10,7 +10,7 @@ version=$1
|
||||||
DIR=$2
|
DIR=$2
|
||||||
|
|
||||||
v=$(echo $version | sed -E -e 's/^([0-9]+\.[0-9]+).*/\1/')
|
v=$(echo $version | sed -E -e 's/^([0-9]+\.[0-9]+).*/\1/')
|
||||||
read url ref semver < $SELF_DIR/sources/$v
|
read url ref semver < $SELF_DIR/../forgejo/sources/$v
|
||||||
|
|
||||||
if ! test -d $DIR/src ; then
|
if ! test -d $DIR/src ; then
|
||||||
mkdir -p $DIR/src
|
mkdir -p $DIR/src
|
293
lib/lib.sh
293
lib/lib.sh
|
@ -2,7 +2,15 @@
|
||||||
# Copyright 2024 The Forgejo Authors
|
# Copyright 2024 The Forgejo Authors
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
LIB_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
|
if ${VERBOSE:-false} ; then
|
||||||
|
set -ex
|
||||||
|
PS4='${BASH_SOURCE[0]}:$LINENO: ${FUNCNAME[0]}: '
|
||||||
|
else
|
||||||
set -e
|
set -e
|
||||||
|
fi
|
||||||
|
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
export DEBIAN_FRONTEND=noninteractive
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
|
@ -11,4 +19,287 @@ if test $(id -u) != 0 ; then
|
||||||
SUDO=sudo
|
SUDO=sudo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PS4='${BASH_SOURCE[0]}:$LINENO: ${FUNCNAME[0]}: '
|
IP=$(hostname -I | cut -f1 -d' ')
|
||||||
|
|
||||||
|
#
|
||||||
|
# Forgejo releases for which a branch exists (7.0/forgejo etc.)
|
||||||
|
#
|
||||||
|
RELEASE_NUMBERS="7.0"
|
||||||
|
|
||||||
|
PREFIX===============
|
||||||
|
HOST_PORT=$IP:3000
|
||||||
|
DIR=/tmp/forgejo-end-to-end
|
||||||
|
export DOT_FORGEJO_CURL=$DIR/forgejo-curl
|
||||||
|
export DOT=$DOT_FORGEJO_CURL # for backward compatibility with forgejo-curl.sh 1.0.0
|
||||||
|
: ${FORGEJO_USER:=root}
|
||||||
|
: ${FORGEJO_PASSWORD:=admin1234}
|
||||||
|
RELEASE_NUMBERS_AND_DEV="$(for r in $RELEASE_NUMBERS ; do echo -n $r $r-dev ; done)"
|
||||||
|
|
||||||
|
function log_info() {
|
||||||
|
echo "$PREFIX $@"
|
||||||
|
}
|
||||||
|
|
||||||
|
function dependencies() {
|
||||||
|
|
||||||
|
if ! test -f /usr/local/bin/forgejo-curl.sh ; then
|
||||||
|
$SUDO curl --fail -sS https://code.forgejo.org/forgejo/forgejo-curl/raw/branch/main/forgejo-curl.sh -o /usr/local/bin/forgejo-curl.sh
|
||||||
|
$SUDO chmod +x /usr/local/bin/forgejo-curl.sh
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! which curl daemon jq git-lfs > /dev/null ; then
|
||||||
|
$SUDO apt-get update -qq
|
||||||
|
$SUDO apt-get install -y -qq curl daemon git-lfs jq sqlite3 gettext-base
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! test -f /usr/local/bin/mc || ! test -f /usr/local/bin/minio ; then
|
||||||
|
$SUDO curl --fail -sS https://dl.min.io/client/mc/release/linux-amd64/mc -o /usr/local/bin/mc
|
||||||
|
$SUDO curl --fail -sS https://dl.min.io/server/minio/release/linux-amd64/minio -o /usr/local/bin/minio
|
||||||
|
fi
|
||||||
|
if ! test -x /usr/local/bin/mc || ! test -x /usr/local/bin/minio ; then
|
||||||
|
$SUDO chmod +x /usr/local/bin/mc
|
||||||
|
$SUDO chmod +x /usr/local/bin/minio
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! test -f /usr/local/bin/garage > /dev/null ; then
|
||||||
|
$SUDO curl --fail -sS https://garagehq.deuxfleurs.fr/_releases/v0.8.2/x86_64-unknown-linux-musl/garage -o /usr/local/bin/garage
|
||||||
|
fi
|
||||||
|
if ! test -x /usr/local/bin/garage > /dev/null ; then
|
||||||
|
$SUDO chmod +x /usr/local/bin/garage
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function build_all() {
|
||||||
|
for dev in $RELEASE_NUMBERS ; do
|
||||||
|
log_info $dev-dev
|
||||||
|
$LIB_DIR/build.sh $dev $DIR
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
function retry() {
|
||||||
|
rm -f $DIR/wait-for.out
|
||||||
|
success=false
|
||||||
|
for delay in 1 1 5 5 15 ; do
|
||||||
|
if "$@" >> $DIR/wait-for.out 2>&1 ; then
|
||||||
|
success=true
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
cat $DIR/wait-for.out
|
||||||
|
echo waiting $delay
|
||||||
|
sleep $delay
|
||||||
|
done
|
||||||
|
if test $success = false ; then
|
||||||
|
cat $DIR/wait-for.out
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function full_version() {
|
||||||
|
local version=$1
|
||||||
|
local owner=$2
|
||||||
|
|
||||||
|
if [[ $version =~ ^[0-9]+\.[0-9]+$ ]] ; then
|
||||||
|
full_version=$(curl -sS https://codeberg.org/api/v1/repos/$owner/forgejo/releases | jq -r '.[] | .tag_name | select(startswith("v'$version'"))' | sort -r | head -1)
|
||||||
|
echo ${full_version#v}
|
||||||
|
else
|
||||||
|
echo $version
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function download() {
|
||||||
|
local version=$1
|
||||||
|
|
||||||
|
if ! test -f $DIR/forgejo-$version ; then
|
||||||
|
mkdir -p $DIR
|
||||||
|
for owner in forgejo forgejo-experimental forgejo-integration ; do
|
||||||
|
full_version=$(full_version $version $owner)
|
||||||
|
if test "$full_version" = "" ; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if wget -O $DIR/forgejo-$version --quiet https://codeberg.org/$owner/forgejo/releases/download/v$full_version/forgejo-$full_version-linux-amd64 ; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if test -s $DIR/forgejo-$version ; then
|
||||||
|
if test "$version" != "$full_version" ; then
|
||||||
|
log_info "downloaded $full_version for $version"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo unable to download Forgejo $version
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
chmod +x $DIR/forgejo-$version
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function cleanup_logs() {
|
||||||
|
local work_path=$DIR/forgejo-work-path
|
||||||
|
|
||||||
|
rm -f $DIR/*.log
|
||||||
|
rm -f $work_path/log/*.log
|
||||||
|
}
|
||||||
|
|
||||||
|
function clobber() {
|
||||||
|
rm -fr /tmp/forgejo-end-to-end
|
||||||
|
}
|
||||||
|
|
||||||
|
function start_forgejo() {
|
||||||
|
local version=$1
|
||||||
|
|
||||||
|
download $version
|
||||||
|
local work_path=$DIR/forgejo-work-path
|
||||||
|
daemon --chdir=$DIR --unsafe --env="TERM=$TERM" --env="HOME=$HOME" --env="PATH=$PATH" --pidfile=$DIR/forgejo-pid --errlog=$DIR/forgejo-err.log --output=$DIR/forgejo-out.log -- $DIR/forgejo-$version --config $work_path/app.ini --work-path $work_path
|
||||||
|
if ! retry grep 'Starting server on' $work_path/log/forgejo.log ; then
|
||||||
|
grep '' $DIR/*.log
|
||||||
|
grep '' $work_path/log/*.log 2> /dev/null
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
create_user_and_login $version
|
||||||
|
}
|
||||||
|
|
||||||
|
function start_minio() {
|
||||||
|
mkdir -p $DIR/minio
|
||||||
|
daemon --chdir=$DIR --unsafe \
|
||||||
|
--env="PATH=$PATH" \
|
||||||
|
--env=MINIO_ROOT_USER=123456 \
|
||||||
|
--env=MINIO_ROOT_PASSWORD=12345678 \
|
||||||
|
--env=MINIO_VOLUMES=$DIR/minio \
|
||||||
|
--pidfile=$DIR/minio-pid --errlog=$DIR/minio-err.log --output=$DIR/minio-out.log -- /usr/local/bin/minio server
|
||||||
|
retry mc alias set testS3 http://127.0.0.1:9000 123456 12345678
|
||||||
|
}
|
||||||
|
|
||||||
|
function start_garage() {
|
||||||
|
mkdir -p $DIR/garage/{data,meta}
|
||||||
|
cat > $DIR/garage/garage.toml <<EOF
|
||||||
|
metadata_dir = "$DIR/garage/meta"
|
||||||
|
data_dir = "$DIR/garage/data"
|
||||||
|
db_engine = "lmdb"
|
||||||
|
|
||||||
|
replication_mode = "none"
|
||||||
|
|
||||||
|
rpc_bind_addr = "127.0.0.1:3901"
|
||||||
|
rpc_public_addr = "127.0.0.1:3901"
|
||||||
|
rpc_secret = "$(openssl rand -hex 32)"
|
||||||
|
|
||||||
|
[s3_api]
|
||||||
|
s3_region = "us-east-1"
|
||||||
|
api_bind_addr = "127.0.0.1:9000"
|
||||||
|
root_domain = ".s3.garage.localhost"
|
||||||
|
|
||||||
|
[s3_web]
|
||||||
|
bind_addr = "127.0.0.1:3902"
|
||||||
|
root_domain = ".web.garage.localhost"
|
||||||
|
index = "index.html"
|
||||||
|
|
||||||
|
[k2v_api]
|
||||||
|
api_bind_addr = "127.0.0.1:3904"
|
||||||
|
|
||||||
|
[admin]
|
||||||
|
api_bind_addr = "127.0.0.1:3903"
|
||||||
|
admin_token = "$(openssl rand -base64 32)"
|
||||||
|
EOF
|
||||||
|
|
||||||
|
daemon --chdir=$DIR --unsafe \
|
||||||
|
--env="PATH=$PATH" \
|
||||||
|
--env=RUST_LOG=garage_api=debug \
|
||||||
|
--pidfile=$DIR/garage-pid --errlog=$DIR/garage-err.log --output=$DIR/garage-out.log -- /usr/local/bin/garage -c $DIR/garage/garage.toml server
|
||||||
|
|
||||||
|
retry garage -c $DIR/garage/garage.toml status
|
||||||
|
garage -c $DIR/garage/garage.toml layout assign -z dc1 -c 1 $(garage -c $DIR/garage/garage.toml status | tail -1 | grep -o '[0-9a-z]*' | head -1)
|
||||||
|
ver=$(garage -c $DIR/garage/garage.toml layout show | grep -oP '(?<=Current cluster layout version: )\d+')
|
||||||
|
garage -c $DIR/garage/garage.toml layout apply --version $((ver+1))
|
||||||
|
garage -c $DIR/garage/garage.toml key info test || garage -c $DIR/garage/garage.toml key import -n test 123456 12345678
|
||||||
|
garage -c $DIR/garage/garage.toml key allow --create-bucket test
|
||||||
|
retry mc alias set testS3 http://127.0.0.1:9000 123456 12345678
|
||||||
|
}
|
||||||
|
|
||||||
|
function start_s3() {
|
||||||
|
local s3_backend=$1
|
||||||
|
|
||||||
|
start_$s3_backend
|
||||||
|
}
|
||||||
|
|
||||||
|
function start() {
|
||||||
|
local version=$1
|
||||||
|
local s3_backend=${2:-minio}
|
||||||
|
|
||||||
|
start_s3 $s3_backend
|
||||||
|
start_forgejo $version
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset_forgejo() {
|
||||||
|
local config=$1
|
||||||
|
local work_path=$DIR/forgejo-work-path
|
||||||
|
rm -fr $work_path
|
||||||
|
mkdir -p $work_path
|
||||||
|
WORK_PATH=$work_path envsubst < $config > $work_path/app.ini
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset_minio() {
|
||||||
|
rm -fr $DIR/minio
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset_garage() {
|
||||||
|
rm -fr $DIR/garage
|
||||||
|
}
|
||||||
|
|
||||||
|
function create_user_and_login() {
|
||||||
|
local version=$1
|
||||||
|
|
||||||
|
local work_path=$DIR/forgejo-work-path
|
||||||
|
local email="$FORGEJO_USER@example.com"
|
||||||
|
local cli="$DIR/forgejo-$version --config $work_path/app.ini --work-path $work_path"
|
||||||
|
if ! $cli admin user list | grep --quiet "$email" ; then
|
||||||
|
$cli admin user create --admin --username "$FORGEJO_USER" --password "$FORGEJO_PASSWORD" --email $email
|
||||||
|
fi
|
||||||
|
|
||||||
|
forgejo-curl.sh logout
|
||||||
|
local scopes='--scopes ["all"]'
|
||||||
|
if echo $version | grep --quiet 1.18 ; then
|
||||||
|
scopes=""
|
||||||
|
fi
|
||||||
|
forgejo-curl.sh --user "$FORGEJO_USER" --password "$FORGEJO_PASSWORD" $scopes login http://${HOST_PORT}
|
||||||
|
}
|
||||||
|
|
||||||
|
function stop_daemon() {
|
||||||
|
local daemon=$1
|
||||||
|
|
||||||
|
if test -f $DIR/$daemon-pid ; then
|
||||||
|
local pid=$(cat $DIR/$daemon-pid)
|
||||||
|
kill -TERM $pid
|
||||||
|
pidwait $pid || true
|
||||||
|
for delay in 1 1 2 2 5 5 ; do
|
||||||
|
if ! test -f $DIR/$daemon-pid ; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
sleep $delay
|
||||||
|
done
|
||||||
|
! test -f $DIR/$daemon-pid
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function stop() {
|
||||||
|
stop_daemon forgejo
|
||||||
|
stop_daemon minio
|
||||||
|
stop_daemon garage
|
||||||
|
|
||||||
|
cleanup_logs
|
||||||
|
}
|
||||||
|
|
||||||
|
function run() {
|
||||||
|
local fun=$1
|
||||||
|
shift
|
||||||
|
|
||||||
|
echo Start running $fun
|
||||||
|
mkdir -p $DIR
|
||||||
|
> $DIR/$fun.out
|
||||||
|
tail --follow $DIR/$fun.out | sed --unbuffered -n -e "/^$PREFIX/s/^$PREFIX //p" &
|
||||||
|
local pid=$!
|
||||||
|
if ! VERBOSE=true $SELF $fun "$@" >& $DIR/$fun.out ; then
|
||||||
|
kill $pid
|
||||||
|
cat $DIR/$fun.out
|
||||||
|
echo Failure running $fun
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
kill $pid
|
||||||
|
echo Success running $fun
|
||||||
|
}
|
||||||
|
|
30
packages/alpine-app.ini
Normal file
30
packages/alpine-app.ini
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
RUN_MODE = prod
|
||||||
|
WORK_PATH = ${WORK_PATH}
|
||||||
|
|
||||||
|
[server]
|
||||||
|
APP_DATA_PATH = ${WORK_PATH}/data
|
||||||
|
HTTP_PORT = 3000
|
||||||
|
SSH_LISTEN_PORT = 2222
|
||||||
|
LFS_START_SERVER = true
|
||||||
|
|
||||||
|
[database]
|
||||||
|
DB_TYPE = sqlite3
|
||||||
|
PATH = ${WORK_PATH}/forgejo.db
|
||||||
|
|
||||||
|
[log]
|
||||||
|
MODE = file
|
||||||
|
LEVEL = trace
|
||||||
|
ROUTER = file
|
||||||
|
|
||||||
|
[log.file]
|
||||||
|
FILE_NAME = forgejo.log
|
||||||
|
|
||||||
|
[security]
|
||||||
|
INSTALL_LOCK = true
|
||||||
|
|
||||||
|
[repository]
|
||||||
|
ENABLE_PUSH_CREATE_USER = true
|
||||||
|
DEFAULT_PUSH_CREATE_PRIVATE = false
|
||||||
|
|
||||||
|
[actions]
|
||||||
|
ENABLED = true
|
|
@ -2,16 +2,18 @@
|
||||||
# Copyright 2024 The Forgejo Authors
|
# Copyright 2024 The Forgejo Authors
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
function test_packages_alpine_v1.21() {
|
||||||
|
stop_daemon forgejo
|
||||||
|
reset_forgejo $PACKAGES_DIR/alpine-app.ini
|
||||||
|
start_forgejo 1.21
|
||||||
|
|
||||||
source $SELF_DIR/../lib/lib.sh
|
local d=$PACKAGES_DIR/alpine
|
||||||
|
local token=$(cat $DIR/forgejo-curl/token)
|
||||||
function main() {
|
local url=http://${HOST_PORT}
|
||||||
local d=$SELF_DIR/alpine
|
|
||||||
local token=$(cat $DIR/forgejo-token)
|
|
||||||
local url=$(cat $DIR/forgejo-url)
|
|
||||||
|
|
||||||
docker run --rm --volume $d:$d:ro --workdir $d docker.io/alpine:3.19 ash -c "./test.sh $url $token"
|
docker run --rm --volume $d:$d:ro --workdir $d docker.io/alpine:3.19 ash -c "./test.sh $url $token"
|
||||||
}
|
}
|
||||||
|
|
||||||
"${@:-main}"
|
function test_packages_alpine() {
|
||||||
|
test_packages_alpine_v1.21
|
||||||
|
}
|
||||||
|
|
11
packages/packages.sh
Normal file
11
packages/packages.sh
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# Copyright 2024 The Forgejo Authors
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
PACKAGES_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
|
source $PACKAGES_DIR/alpine.sh
|
||||||
|
|
||||||
|
function test_packages() {
|
||||||
|
run test_packages_alpine
|
||||||
|
}
|
|
@ -1,80 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
# Copyright 2024 The Forgejo Authors
|
|
||||||
# SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
||||||
|
|
||||||
source $SELF_DIR/../lib/lib.sh
|
|
||||||
|
|
||||||
function run() {
|
|
||||||
local package=$1
|
|
||||||
|
|
||||||
bash -ex $SELF_DIR/$package.sh
|
|
||||||
}
|
|
||||||
|
|
||||||
function packages_v1_21() {
|
|
||||||
echo 'alpine'
|
|
||||||
}
|
|
||||||
|
|
||||||
function packages_v7_0() {
|
|
||||||
packages_v1_21
|
|
||||||
}
|
|
||||||
|
|
||||||
function setup() {
|
|
||||||
local binary=$1
|
|
||||||
forgejo-binary.sh setup root admin1234 $binary
|
|
||||||
}
|
|
||||||
|
|
||||||
function teardown() {
|
|
||||||
forgejo-curl.sh logout
|
|
||||||
forgejo-binary.sh teardown
|
|
||||||
}
|
|
||||||
|
|
||||||
function main() {
|
|
||||||
local binary="$1"
|
|
||||||
shift
|
|
||||||
export full_version="$1"
|
|
||||||
shift
|
|
||||||
export version="$1"
|
|
||||||
shift
|
|
||||||
|
|
||||||
export DOT=$DIR/forgejo-curl
|
|
||||||
|
|
||||||
teardown
|
|
||||||
|
|
||||||
if test "$#" = 0 ; then
|
|
||||||
packages=$(packages_${version/./_})
|
|
||||||
else
|
|
||||||
packages="$@"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if test "$packages" = "none" ; then
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
setup $binary
|
|
||||||
|
|
||||||
if ! test -f "$DIR/forgejo-auth-url" ; then
|
|
||||||
echo "DIR=$DIR must be a directory with a forgejo-auth-url file"
|
|
||||||
fi
|
|
||||||
|
|
||||||
export url=$(cat $DIR/forgejo-auth-url)
|
|
||||||
export token=$(cat $DIR/forgejo-token)
|
|
||||||
|
|
||||||
for package in $packages ; do
|
|
||||||
echo "======================== BEGIN package-$package ==================="
|
|
||||||
if ! time run $package >& /tmp/run.out ; then
|
|
||||||
sed -e 's/^/[RUN] /' < /tmp/run.out
|
|
||||||
echo "======================== FAIL package-$package ==================="
|
|
||||||
sleep 5 # hack for Forgejo v1.21 to workaround a bug by which the last lines of the output are moved to the next step
|
|
||||||
false
|
|
||||||
else
|
|
||||||
if test "$VERBOSE" = true ; then
|
|
||||||
sed -e 's/^/[RUN] /' < /tmp/run.out
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
echo "======================== END package-$package ==================="
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
main "$@"
|
|
Loading…
Add table
Reference in a new issue