Merge pull request 'wip-container' (#4) from earl-warren/setup-forgejo:wip-container into main

Reviewed-on: https://code.forgejo.org/actions/setup-forgejo/pulls/4
This commit is contained in:
earl-warren 2023-04-01 13:08:50 +00:00
commit 50da263fad
5 changed files with 21 additions and 12 deletions

View file

@ -1,4 +1,4 @@
on: [ push ] on: [ push, pull_request ]
jobs: jobs:
integration: integration:
runs-on: self-hosted runs-on: self-hosted

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 | | password | Administrator password | `false` | admin1234 |
| runner | Runner git repository | `false` | https://code.forgejo.org/forgejo/runner | | runner | Runner git repository | `false` | https://code.forgejo.org/forgejo/runner |
| runner-version | Runner version | `false` | v1.4.1 | | 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 | | lxc-ip-prefix | Class C IP prefix used by LXC | `false` | 10.0.23 |
<!-- action-docs-inputs --> <!-- action-docs-inputs -->

View file

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

View file

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