mirror of
https://code.forgejo.org/actions/setup-forgejo.git
synced 2024-12-25 06:12:19 -05:00
0dee755317
for backward compatibility DIR defaults to $(pwd) also create the additional convenience files: * forgejocli * forgejo-url * forgejo-auth-url which includes the user and password
75 lines
2.9 KiB
Bash
Executable file
75 lines
2.9 KiB
Bash
Executable file
#!/bin/bash
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
set -e
|
|
|
|
SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
source $SELF_DIR/forgejo-lib.sh
|
|
|
|
if ${VERBOSE:-false}; then set -x; fi
|
|
: ${CONTAINER:=forgejo}
|
|
: ${DIR:=$(pwd)}
|
|
|
|
function run() {
|
|
local image="$1"
|
|
local version="$2"
|
|
|
|
if test "$version" != "1.19" && dpkg --compare-versions "$version" "lt" "1.19.0-3"; then
|
|
actions_unit="actions.actions"
|
|
else
|
|
actions_unit="repo.actions"
|
|
fi
|
|
|
|
docker run --restart unless-stopped --name ${CONTAINER} \
|
|
-e "RUN_MODE=dev" \
|
|
-e "FORGEJO__security__INSTALL_LOCK=true" \
|
|
-e "FORGEJO__log__LEVEL=trace" \
|
|
-e "FORGEJO__actions__ENABLED=true" \
|
|
-e "FORGEJO__queue__TYPE=immediate" \
|
|
-e "FORGEJO__queue.push_update__TYPE=immediate" \
|
|
-e "FORGEJO__repository__ENABLE_PUSH_CREATE_USER=true" \
|
|
-e "FORGEJO__repository__DEFAULT_PUSH_CREATE_PRIVATE=false" \
|
|
-e "FORGEJO__repository__DEFAULT_REPO_UNITS=repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki,repo.projects,repo.packages,$actions_unit" \
|
|
-d $image:$version
|
|
local ip="$(docker inspect -f "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" ${CONTAINER})"
|
|
echo 'docker exec --user 1000 '${CONTAINER}' forgejo "$@"' > $DIR/forgejocli
|
|
chmod +x $DIR/forgejocli
|
|
echo $ip > $DIR/forgejo-ip
|
|
echo "http://$(cat $DIR/forgejo-ip):3000" > $DIR/forgejo-url
|
|
docker exec ${CONTAINER} sed -i -e "s|localhost|$ip|" /data/gitea/conf/app.ini
|
|
docker restart ${CONTAINER}
|
|
}
|
|
|
|
function setup() {
|
|
local user="${1:-root}"
|
|
local password="${2:-admin1234}"
|
|
local image="${3:-codeberg.org/forgejo/forgejo}"
|
|
local version="${4:-1.20}"
|
|
|
|
run $image $version
|
|
|
|
sleep 5 # for some reason trying to run "forgejo admin" while forgejo is booting will permanently break everything
|
|
if $DIR/forgejocli admin user list --admin | grep "$user" ; then
|
|
$DIR/forgejocli admin user change-password --username "$user" --password "$password"
|
|
else
|
|
retry $DIR/forgejocli admin user create --admin --username "$user" --password "$password" --email "$user@example.com"
|
|
fi
|
|
#
|
|
# The 'sudo' scope was removed in Forgejo v1.20 and is ignored
|
|
#
|
|
echo "http://${user}:${password}@$(cat $DIR/forgejo-ip):3000" > $DIR/forgejo-auth-url
|
|
$DIR/forgejocli admin user generate-access-token -u $user --raw --scopes 'all,sudo' > $DIR/forgejo-token
|
|
retry forgejo-curl.sh --user "$user" --password "$password" --token @$DIR/forgejo-token login http://$(cat $DIR/forgejo-ip):3000
|
|
#
|
|
# Redundant with forgejo-curl.sh, kept around for backward compatibility 09/2023
|
|
#
|
|
( echo -n 'Authorization: token ' ; cat $DIR/forgejo-token ) > $DIR/forgejo-header
|
|
( echo "#!/bin/sh" ; echo 'curl -sS -H "Content-Type: application/json" -H @'$DIR/forgejo-header' "$@"' ) > $DIR/forgejo-api && chmod +x $DIR/forgejo-api
|
|
}
|
|
|
|
function teardown() {
|
|
docker stop ${CONTAINER} >& /dev/null || true
|
|
docker rm -f ${CONTAINER} >& /dev/null || true
|
|
}
|
|
|
|
"$@"
|