add inputs.container that defaults to forgejo

This commit is contained in:
Earl Warren 2023-04-01 14:51:42 +02:00
parent 8fbab2d77d
commit 8fd60b424d
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
3 changed files with 20 additions and 11 deletions

View file

@ -41,6 +41,7 @@ It can only be run on the `self-hosted` platform, running on a host with LXC ins
| password | Administrator password | `false` | admin1234 |
| runner | Runner git repository | `false` | https://code.forgejo.org/forgejo/runner |
| runner-version | Runner version | `false` | v1.4.1 |
| container | Name of the container running the Forgejo instance | `false` | forgejo |
| lxc-ip-prefix | Class C IP prefix used by LXC | `false` | 10.0.23 |
<!-- action-docs-inputs -->

View file

@ -45,6 +45,9 @@ inputs:
runner-version:
description: 'Runner version'
default: 'v1.4.1'
container:
description: 'Name of the container running the Forgejo instance'
default: 'forgejo'
lxc-ip-prefix:
description: 'Class C IP prefix used by LXC'
default: '10.0.23'
@ -71,6 +74,7 @@ runs:
run: |
cd $(mktemp -d)
LXC_IP_PREFIX=${{ inputs.lxc-ip-prefix }} dependencies.sh
export CONTAINER=${{ inputs.container }}
forgejo.sh setup ${{ inputs.user }} "${{ inputs.password }}" ${{ inputs.image }}:${{ inputs.image-version }}
forgejo-runner.sh setup ${{ inputs.runner }} ${{ inputs.runner-version }} http://$(cat forgejo-ip):3000/
echo url="http://$(cat forgejo-ip):3000" >> $GITHUB_OUTPUT

View file

@ -1,7 +1,11 @@
#!/bin/bash
# SPDX-License-Identifier: MIT
set -ex
set -e
if ${VERBOSE:-false}; then set -x; fi
: ${CONTAINER:=forgejo}
function wait_for() {
rm -f /tmp/setup-forgejo.out
@ -24,7 +28,7 @@ function wait_for() {
function run() {
local image="$1"
docker run --name forgejo \
docker run --name ${CONTAINER} \
-e "RUN_MODE=dev" \
-e "FORGEJO__security__INSTALL_LOCK=true" \
-e "FORGEJO__log__LEVEL=debug" \
@ -33,10 +37,10 @@ function run() {
-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.actions" \
-d $image
local ip="$(docker inspect -f "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" forgejo)"
local ip="$(docker inspect -f "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" ${CONTAINER})"
echo $ip > forgejo-ip
docker exec forgejo sed -i -e "s|localhost|$ip|" /data/gitea/conf/app.ini
docker restart forgejo
docker exec ${CONTAINER} sed -i -e "s|localhost|$ip|" /data/gitea/conf/app.ini
docker restart ${CONTAINER}
}
function setup() {
@ -47,19 +51,19 @@ function setup() {
run $image
sleep 5 # for some reason trying to run "forgejo admin" while forgejo is booting will permanently break everything
if docker exec --user 1000 forgejo forgejo admin user list --admin | grep "$user" ; then
docker exec --user 1000 forgejo forgejo admin user change-password --username "$user" --password "$password"
if docker exec --user 1000 ${CONTAINER} forgejo admin user list --admin | grep "$user" ; then
docker exec --user 1000 ${CONTAINER} forgejo admin user change-password --username "$user" --password "$password"
else
wait_for docker exec --user 1000 forgejo forgejo admin user create --admin --username "$user" --password "$password" --email "$user@example.com"
wait_for docker exec --user 1000 ${CONTAINER} forgejo admin user create --admin --username "$user" --password "$password" --email "$user@example.com"
fi
docker exec --user 1000 forgejo forgejo admin user generate-access-token -u $user --raw --scopes 'all,sudo' > forgejo-token
docker exec --user 1000 ${CONTAINER} forgejo admin user generate-access-token -u $user --raw --scopes 'all,sudo' > forgejo-token
( echo -n 'Authorization: token ' ; cat forgejo-token ) > forgejo-header
( echo "#!/bin/sh" ; echo 'curl -sS -H "Content-Type: application/json" -H @'$(pwd)/forgejo-header' "$@"' ) > forgejo-api && chmod +x forgejo-api
}
function teardown() {
docker stop forgejo >& /dev/null || true
docker rm -f forgejo >& /dev/null || true
docker stop ${CONTAINER} >& /dev/null || true
docker rm -f ${CONTAINER} >& /dev/null || true
}
"$@"