Compare commits
28
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
704176a80e | ||
|
|
7f4bf0efbd | ||
|
|
48c5456107 | ||
|
|
5aa2bfcf8b | ||
|
|
1a9c3b4ae5 | ||
|
|
16ce2e9bb2 | ||
|
|
4908d65971 | ||
|
|
c7b53d2707 | ||
|
|
d9a568ea47 | ||
|
|
e136ead3c7 | ||
|
|
60c10d68cb | ||
|
|
2291b2be8f | ||
|
|
506f2d35bf | ||
|
|
d74a637189 | ||
|
|
85f9bb3d26 | ||
|
|
81f8fe7df0 | ||
|
|
f6c4d722ef | ||
|
|
aead04bae0 | ||
|
|
3d5a23819b | ||
|
|
942f369f78 | ||
|
|
9b2bff61d8 | ||
|
|
1c1b51d37e | ||
|
|
99e5b939d4 | ||
|
|
c602ec6994 | ||
|
|
902e8517ff | ||
|
|
ecfd565a3b | ||
|
|
843f2e2c2a | ||
|
|
e580f90655 |
+6
-2
@@ -1,3 +1,7 @@
|
|||||||
## Manual deployment notes
|
## Deployment notes
|
||||||
### Gitea
|
### Gitea
|
||||||
1. Create admin user in web UI on initial setup
|
1. `cd ./gitea`
|
||||||
|
1. Run the script `./run-this-first.sh`
|
||||||
|
1. Bring up the gitea cluster `docker compose up -d`
|
||||||
|
1. Run the script `./initialize-gitea.sh`
|
||||||
|
1. Note the access token printed, it will be needed to publish packages.
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ networks:
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
server:
|
server:
|
||||||
image: gitea/gitea:1.17.1
|
image: gitea/gitea:1.19.0
|
||||||
container_name: gitea
|
|
||||||
environment:
|
environment:
|
||||||
- USER_UID=1000
|
- USER_UID=1000
|
||||||
- USER_GID=1000
|
- USER_GID=1000
|
||||||
@@ -19,6 +18,8 @@ services:
|
|||||||
- GITEA__server__HTTP_PORT=3000
|
- GITEA__server__HTTP_PORT=3000
|
||||||
- GITEA__server__LOCAL_ROOT_URL=http://gitea.local:3000/
|
- GITEA__server__LOCAL_ROOT_URL=http://gitea.local:3000/
|
||||||
- GITEA__server__ROOT_URL=http://gitea.local:3000/
|
- GITEA__server__ROOT_URL=http://gitea.local:3000/
|
||||||
|
- GITEA__actions__ENABLED=true
|
||||||
|
- GITEA__security__INSTALL_LOCK=true
|
||||||
restart: always
|
restart: always
|
||||||
networks:
|
networks:
|
||||||
- gitea
|
- gitea
|
||||||
@@ -40,7 +41,24 @@ services:
|
|||||||
- POSTGRES_USER=gitea
|
- POSTGRES_USER=gitea
|
||||||
- POSTGRES_PASSWORD=gitea
|
- POSTGRES_PASSWORD=gitea
|
||||||
- POSTGRES_DB=gitea
|
- POSTGRES_DB=gitea
|
||||||
|
# Workaround below for lack of docker uid mapping. Change the container's postgres user's uid/gid to match the host user's
|
||||||
|
entrypoint: bash
|
||||||
|
command: -c 'usermod -u ${CERC_HOST_UID:-1000} postgres;groupmod -g ${CERC_HOST_GID:-1000} postgres;exec /usr/local/bin/docker-entrypoint.sh postgres'
|
||||||
networks:
|
networks:
|
||||||
- gitea
|
- gitea
|
||||||
volumes:
|
volumes:
|
||||||
- ./postgres:/var/lib/postgresql/data
|
- ./postgres:/var/lib/postgresql/data
|
||||||
|
|
||||||
|
runner:
|
||||||
|
image: cerc/act-runner:local
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
- GITEA_INSTANCE_INSECURE=1
|
||||||
|
- GITEA_RUNNER_REGISTRATION_TOKEN=eMdEwIzSo87nBh0UFWZlbp308j6TNWr3WhWxQqIc
|
||||||
|
- GITEA_INSTANCE_URL=http://host.docker.internal:3000
|
||||||
|
- GITEA_RUNNER_LABELS=ubuntu-latest:docker://cerc/act-runner-task-executor:local,ubuntu-22.04:docker://cerc/act-runner-task-executor:local
|
||||||
|
networks:
|
||||||
|
- gitea
|
||||||
|
volumes:
|
||||||
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
- ./act_runner:/data
|
||||||
|
|||||||
Executable
+85
@@ -0,0 +1,85 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Run this script once after bringing up gitea in docker compose
|
||||||
|
# TODO: add a check to detect that gitea has not fully initialized yet (no user relation error)
|
||||||
|
GITEA_USER=gitea_admin
|
||||||
|
GITEA_PASSWORD=admin1234
|
||||||
|
GITEA_USER_EMAIL=${GITEA_USER}@example.com
|
||||||
|
GITEA_NEW_ORGANIZATION=cerc-io
|
||||||
|
GITEA_URL_PREFIX=http://localhost:3000
|
||||||
|
CERC_GITEA_TOKEN_NAME=laconic-so-publication-token
|
||||||
|
CERC_GITEA_RUNNER_REGISTRATION_TOKEN=eMdEwIzSo87nBh0UFWZlbp308j6TNWr3WhWxQqIc
|
||||||
|
if [[ -n "$CERC_SCRIPT_DEBUG" ]]; then
|
||||||
|
set -x
|
||||||
|
fi
|
||||||
|
# Create admin user
|
||||||
|
# First check if it already exists
|
||||||
|
if [[ -z ${CERC_SO_COMPOSE_PROJECT} ]] ; then
|
||||||
|
compose_command="docker compose"
|
||||||
|
else
|
||||||
|
compose_command="docker compose -p ${CERC_SO_COMPOSE_PROJECT}"
|
||||||
|
fi
|
||||||
|
sleep 15
|
||||||
|
${compose_command} exec --user git server gitea admin user list --admin | grep -v -e "^ID" | awk '{ print $2 }' | grep ${GITEA_USER} > /dev/null
|
||||||
|
if [[ $? == 1 ]] ; then
|
||||||
|
# Then create if it wasn't found
|
||||||
|
${compose_command} exec --user git server gitea admin user create --admin --username ${GITEA_USER} --password ${GITEA_PASSWORD} --email ${GITEA_USER_EMAIL}
|
||||||
|
fi
|
||||||
|
# HACK: sleep a bit because if we don't gitea will return empty responses
|
||||||
|
sleep 5
|
||||||
|
# Check if the token already exists
|
||||||
|
token_response=$( curl -s "${GITEA_URL_PREFIX}/api/v1/users/${GITEA_USER}/tokens" \
|
||||||
|
-u ${GITEA_USER}:${GITEA_PASSWORD} \
|
||||||
|
-H "Content-Type: application/json")
|
||||||
|
if [[ -n ${token_response} ]] ; then
|
||||||
|
echo ${token_response} | jq --exit-status -r 'to_entries[] | select(.value.name == "'${CERC_GITEA_TOKEN_NAME}'")'
|
||||||
|
if [[ $? == 0 ]] ; then
|
||||||
|
token_found=1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
if [[ ${token_found} != 1 ]] ; then
|
||||||
|
# Create access token if not found
|
||||||
|
# Note that we either create the token here, or we needed to be passed
|
||||||
|
# the token by the caller. This is because gitea won't release the token
|
||||||
|
# plaintext post-creation.
|
||||||
|
new_gitea_token=$( curl -s -X POST "${GITEA_URL_PREFIX}/api/v1/users/${GITEA_USER}/tokens" \
|
||||||
|
-u ${GITEA_USER}:${GITEA_PASSWORD} \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"name":"'${CERC_GITEA_TOKEN_NAME}'", "scopes": [ "sudo" ] }' \
|
||||||
|
| jq -r .sha1 )
|
||||||
|
echo "This is your gitea access token: ${new_gitea_token}. Keep it safe and secure, it can not be fetched again from gitea."
|
||||||
|
echo "To use with laconic-so set this environment variable: export CERC_NPM_AUTH_TOKEN=${new_gitea_token}"
|
||||||
|
CERC_GITEA_AUTH_TOKEN=${new_gitea_token}
|
||||||
|
else
|
||||||
|
# If the token exists, then we must have been passed its value.
|
||||||
|
# If we were not, then we fail hard here.
|
||||||
|
if [[ -z ${CERC_GITEA_AUTH_TOKEN} ]] ; then
|
||||||
|
echo "FATAL error: gitea auth token \"${CERC_GITEA_TOKEN_NAME}\" already exists but no CERC_GITEA_AUTH_TOKEN was provided"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
# Now that we're sure the token exists and is set in CERC_GITEA_AUTH_TOKEN,
|
||||||
|
# we can proceed with token-authenticated API requests below
|
||||||
|
# Create org
|
||||||
|
# First check if it already exists
|
||||||
|
curl -s "${GITEA_URL_PREFIX}/api/v1/admin/users/${GITEA_USER}/orgs" \
|
||||||
|
-H "Authorization: token ${CERC_GITEA_AUTH_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "accept: application/json" \
|
||||||
|
| jq --exit-status -r 'to_entries[] | select(.value.name == "'${GITEA_NEW_ORGANIZATION}'")' > /dev/null
|
||||||
|
if [[ $? != 0 ]] ; then
|
||||||
|
# If it doesn't exist, create it
|
||||||
|
# See: https://discourse.gitea.io/t/create-remove-organization-through-api/478
|
||||||
|
curl -s -X POST "${GITEA_URL_PREFIX}/api/v1/admin/users/${GITEA_USER}/orgs" \
|
||||||
|
-H "Authorization: token ${CERC_GITEA_AUTH_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "accept: application/json" \
|
||||||
|
-d '{"username": "'${GITEA_NEW_ORGANIZATION}'"}' > /dev/null
|
||||||
|
echo "Created the organization ${GITEA_NEW_ORGANIZATION}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Seed a token for act_runner registration.
|
||||||
|
docker compose -p ${CERC_SO_COMPOSE_PROJECT} exec db psql -U gitea -d gitea -c "INSERT INTO public.action_runner_token(token, owner_id, repo_id, is_active, created, updated, deleted) VALUES('${CERC_GITEA_RUNNER_REGISTRATION_TOKEN}', 0, 0, 'f', 1679000000, 1679000000, NULL);" >/dev/null
|
||||||
|
|
||||||
|
echo "Gitea was configured to use host name: gitea.local, ensure that this resolves to localhost, e.g. with sudo vi /etc/hosts"
|
||||||
|
echo "Success, gitea is properly initialized"
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/usr/bin/env bash
|
||||||
|
if [[ -n "$CERC_SCRIPT_DEBUG" ]]; then
|
||||||
|
set -x
|
||||||
|
fi
|
||||||
mkdir -p ./gitea
|
mkdir -p ./gitea
|
||||||
mkdir -p ./gitea/ssh
|
mkdir -p ./gitea/ssh
|
||||||
mkdir -p ./postgres
|
mkdir -p ./act_runner
|
||||||
|
|||||||
Reference in New Issue
Block a user