diff --git a/CT-Build/Alpine.Jenkinsfile b/CT-Build/Alpine.Jenkinsfile index c1224d1..02de0d9 100644 --- a/CT-Build/Alpine.Jenkinsfile +++ b/CT-Build/Alpine.Jenkinsfile @@ -1,4 +1,4 @@ -String[] ImgVariantList = ['minmal', 'default'] +String[] ImgVariantList = ['minmal', 'default' , 'gitea' ] pipeline { agent { label 'LXCBuilder' } diff --git a/CT-Build/Alpine.yaml b/CT-Build/Alpine.yaml index c5e9636..63fd23c 100644 --- a/CT-Build/Alpine.yaml +++ b/CT-Build/Alpine.yaml @@ -256,6 +256,21 @@ files: # Stuff to do before rebooting ::shutdown:/sbin/openrc shutdown + #Readme for FirstRunScript +- path: /root/ReadMe + generator: dump + content: |- + To setup this container edit and run the FirstRun script `/opt/Setup/Scripts/FirstRun.sh` + variants: + - gitea + +#FileForGitea +- path: /opt/Setup + generator: copy + source: CT-Files/gitea + variants: + - gitea + packages: manager: apk update: true @@ -271,6 +286,13 @@ packages: action: install variants: - default + - packages: + - py3-pip + - xz + - git + action: install + variants: + - gitea repositories: - name: /etc/apk/repositories @@ -307,5 +329,14 @@ actions: echo "Europe/Amsterdam" > /etc/timezone ln -s /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime +#Run provided init script +- trigger: post-files + action: |- + #!/bin/sh + ash /opt/Setup/Scripts/Init.sh + rm /opt/Setup/Scripts/Init.sh + variants: + - gitea + mappings: architecture_map: alpinelinux diff --git a/CT-Build/Debian.yaml b/CT-Build/Debian.yaml index 90ee0ba..30a3b14 100644 --- a/CT-Build/Debian.yaml +++ b/CT-Build/Debian.yaml @@ -862,14 +862,14 @@ files: variants: - imgbuilder - #Readme for imgbuilder + #Readme for FirstRunScript - path: /root/ReadMe generator: dump content: |- - To setup Jenkins on this system edit and run the FirstRun script `/opt/Setup/Scripts/FirstRun.sh` - Make sure a container with imgbuilder is all ready up and running + To setup this container run the FirstRun script `/opt/Setup/Scripts/FirstRun.sh` variants: - imgbuilder + - mysql #FilesForJenkinsVariant - path: /root/ReadMe diff --git a/CT-Files/gitea/Configs/app.ini b/CT-Files/gitea/Configs/app.ini new file mode 100644 index 0000000..8a5cb95 --- /dev/null +++ b/CT-Files/gitea/Configs/app.ini @@ -0,0 +1,86 @@ +APP_NAME = InstName +RUN_USER = git +RUN_MODE = prod + +[security] +INTERNAL_TOKEN = IntToken +INSTALL_LOCK = true +SECRET_KEY = SecKey + +[database] +DB_TYPE = mysql +HOST = DBServer +NAME = DBName +USER = DBUser +PASSWD = DBPass +SSL_MODE = disable +PATH = data/gitea.db + +[repository] +ROOT = /gitea-data/gitea-repositories + +[server] +SSH_DOMAIN = DOMAINname +DOMAIN = localhost +HTTP_PORT = 3000 +ROOT_URL = DomainProto +DISABLE_SSH = FALSE +SSH_PORT = 22 +LFS_START_SERVER = true +APP_DATA_PATH = /gitea-data +LFS_JWT_SECRET = LFSSecret +OFFLINE_MODE = false + +[mailer] +ENABLED = false + +[service] +REGISTER_EMAIL_CONFIRM = false +ENABLE_NOTIFY_MAIL = false +DISABLE_REGISTRATION = true +ALLOW_ONLY_EXTERNAL_REGISTRATION = false +ENABLE_CAPTCHA = false +REQUIRE_SIGNIN_VIEW = false +DEFAULT_KEEP_EMAIL_PRIVATE = false +DEFAULT_ALLOW_CREATE_ORGANIZATION = true +DEFAULT_ENABLE_TIMETRACKING = true +NO_REPLY_ADDRESS = noreply.localhost + +[picture] +DISABLE_GRAVATAR = false +ENABLE_FEDERATED_AVATAR = true + +[openid] +ENABLE_OPENID_SIGNIN = false +ENABLE_OPENID_SIGNUP = false + +[session] +PROVIDER = file + +[log] +MODE = console +LEVEL = Info + + +[i18n] +LANGS = en-US +NAMES = English + +[repository.upload] +; Whether repository file uploads are enabled. Defaults to `true` +ENABLED = true +; Path for uploads. Defaults to `data/tmp/uploads` (tmp gets deleted on gitea restart) +TEMP_PATH = data/tmp/uploads +; One or more allowed types, e.g. image/jpeg|image/png. Nothing means any file type +; ALLOWED_TYPES = +; Max size of each file in megabytes. Defaults to 3MB +FILE_MAX_SIZE = 40 +; Max number of files per upload. Defaults to 5 +MAX_FILES = 5 + +[oauth2] +JWT_SECRET = JWTSectet + +[ui] +THEMES = gitea,arc-green,arc-blue +DEFAULT_THEME = arc-blue \ No newline at end of file diff --git a/CT-Files/gitea/Configs/auto-update.ini b/CT-Files/gitea/Configs/auto-update.ini new file mode 100644 index 0000000..ddf5e1c --- /dev/null +++ b/CT-Files/gitea/Configs/auto-update.ini @@ -0,0 +1,10 @@ +[Gitea] +site=http://localhost:3000/api/v1/version +apiUrl=https://api.github.com/repos/go-gitea/gitea/releases/latest +system=linux-amd64 +file=/usr/local/bin/gitea +tmpDir=/tmp/ +buildFromSource= +sourceDir= +logFile=/var/log/gitupdate.log + diff --git a/CT-Files/gitea/Configs/gitea.service b/CT-Files/gitea/Configs/gitea.service new file mode 100644 index 0000000..8904002 --- /dev/null +++ b/CT-Files/gitea/Configs/gitea.service @@ -0,0 +1,14 @@ +#!/sbin/openrc-run + +supervisor=supervise-daemon +name=gitea +command="/usr/local/bin/gitea" +command_user="git" +command_args="web --config '${GITEA_CONF:-/etc/gitea/app.ini}'" +supervise_daemon_args="--env GITEA_WORK_DIR='${GITEA_WORK_DIR:-/var/lib/gitea}' --chdir '${GITEA_WORK_DIR:-/var/lib/gitea}' --stdout '${GITEA_LOG_FILE:-/var/log/gitea/gitea.log}' --stderr '${GITEA_LOG_FILE:-/var/log/gitea/gitea.log}'" +pidfile="/run/gitea.pid" + +depend() { + use logger dns + need net +} diff --git a/CT-Files/gitea/Scripts/FirstRun.sh b/CT-Files/gitea/Scripts/FirstRun.sh new file mode 100644 index 0000000..0306db3 --- /dev/null +++ b/CT-Files/gitea/Scripts/FirstRun.sh @@ -0,0 +1,37 @@ +#!/bin/ash +#UserSettings +ThisScriptConfigured=no +## Gitea Admin user +GiteaUsername= +GiteaUserEmail= +GiteaPassword= +##Gitea +GiteaName= +GiteaDomain= +GiteaWebProto=http +##DB +MysqlIP=127.0.0.1 +MysqlPort=3306 +MysqlUsername=gitea +MysqlDatabase=gitea +MysqlPassword= + +#Check if script is configured +if [ $ThisScriptConfigured = no ]; then + echo "Script is not configured" + exit +fi + +#Updateing gitea config +sed -i -e 's/DBServer/'$MysqlIP':'$MysqlPort'/' -e 's/DBName/'$MysqlDatabase'/' -e 's/DBUser/'$MysqlUsername'/' -e 's/DBPass/'$MysqlPassword'/' -e 's/DOMAINname/'$GiteaDomain'/' -e 's#DomainProto#'$GiteaWebProto'://'$GiteaDomain'#' -e 's/InstName/'$GiteaName'/' -e 's/IntToken/'$(/usr/local/bin/gitea generate secret INTERNAL_TOKEN)'/' -e 's/SecKey/'$(/usr/local/bin/gitea generate secret SECRET_KEY)'/' -e 's/JWTSectet/'$(/usr/local/bin/gitea generate secret JWT_SECRET)'/' -e 's/LFSSecret/'$(/usr/local/bin/gitea generate secret LFS_JWT_SECRET)'/' /etc/gitea/app.ini + +#generate all db tables +su git -c 'gitea --config /etc/gitea/app.ini migrate' + +#Create admin user +su git -c "gitea --config /etc/gitea/app.ini admin user create --admin --email $GiteaUserEmail --username $GiteaUsername --password $GiteaPassword" + +#Enable on boot +rc-update add gitea +#Start gitea +service gitea start \ No newline at end of file diff --git a/CT-Files/gitea/Scripts/Init.sh b/CT-Files/gitea/Scripts/Init.sh new file mode 100644 index 0000000..f2ec592 --- /dev/null +++ b/CT-Files/gitea/Scripts/Init.sh @@ -0,0 +1,54 @@ +#!/bin/ash +#Vars +apiUrl=https://api.github.com/repos/go-gitea/gitea/releases/latest + +#install Update tool +pip install install gitea-auto-update + +#Get latest gitea version info +#giteaver=$(python3 -c "import requests; print (requests.get('$apiUrl').json()['tag_name'])") +#giteaver=${giteaver//v} +giteaver=1.15.0 + +#Add gitea `git` service user +addgroup git +adduser -S -s /bin/ash -g 'Git Version Control' -h /home/git -D -G git git + +#Making Gitea Folders +mkdir -p /gitea-data +mkdir -p /var/lib/gitea/custom/public +mkdir -p /var/lib/gitea/data +mkdir -p /var/log/gitea +mkdir -p /etc/gitea + +#Download Gitea binary +echo "Downloading gitea binary..." +python3 -c "import requests; url = 'https://dl.gitea.io/gitea/"$giteaver"/gitea-"$giteaver"-linux-amd64'; r = requests.get(url, allow_redirects=True); open('/usr/local/bin/gitea', 'wb').write(r.content)" + +#Install custom theme +git clone https://git.bprieshof.nl/DarkTheme/Gitea-Arc_blue-Theme.git /opt/gitea_blue-theme/ +ln -sfn /opt/gitea_blue-theme/custom_public_bin/css /var/lib/gitea/custom/public/css +ln -sfn /opt/gitea_blue-theme/custom_public_bin/js /var/lib/gitea/custom/public/js + + +#Moving configs in place +mv /opt/Setup/Configs/app.ini /etc/gitea/app.ini +mv /opt/Setup/Configs/auto-update.ini /etc/gitea/auto-update.ini +mv /opt/Setup/Configs/gitea.service /etc/init.d/gitea + +#Set folder permissions +chown -R git:git /gitea-data +chown -R git:git /var/log/gitea +chown -R git:git /var/lib/gitea/ +chown -R root:git /etc/gitea +chmod -R 750 /var/lib/gitea/ +chmod +x /usr/local/bin/gitea +chmod +x /etc/init.d/gitea +chmod 750 /etc/gitea +chmod 640 /etc/gitea/app.ini + +#Fix Gitea-auto-updater to support OpenRC +sed -i -e 's/systemctl start gitea.service/service gitea start/' -e 's/systemctl stop gitea.service/service gitea stop/' /usr/lib/python3.*/site-packages/gitea_auto_update/update.py + +#Gitea update Sript +echo "gitea-auto-update --settings=/etc/gitea/auto-update.ini" > /opt/UpdateGitea.sh \ No newline at end of file diff --git a/Readme.md b/Readme.md index 1604edb..0ddbe6e 100644 --- a/Readme.md +++ b/Readme.md @@ -21,6 +21,33 @@ This can be done on a Minimal debian CT (make sure to enable nesting) on the new | jenkins | Debian | Jenkins server | | jenkinsBuilder | Debian | Basic node for Jenkins | | imgbuilder | Debian | LXC template builder node for Jenkins | +| mysql | Debian | Mysql server with PhpMyadmin | +| gitea | Alpine | Gitea server | + + +## TODO +Domoticz +Hass+Mqtt +Z2mqtt+zw2mqtt +SMB +iSCSI + +Nginx +Nextcloud + +JellyFin +AptCacherNG +NodeRed +Omada +Unifi +Docker +PiHole +dDNS +Colabora +MailBackup* +FileShelter/transfer.sh +WS(x2go-xfce) + # Container Setup @@ -33,7 +60,7 @@ This can be done on a Minimal debian CT (make sure to enable nesting) on the new 5. Create folders on mountpoint using `mkdir /LXCBuild/template/cache` 6. Set permissions on the folder `chmod o+w -R /LXCBuild` 7. Write down the ip of this server (for use in the jenkins container) -## Jenkins +## jenkins 1. In the container configure the setup script `nano /opt/Setup/Scripts/FirstRun.sh` 2. In the container run the setup script `bash /opt/Setup/Scripts/FirstRun.sh` 3. Acces Jenkins using `http://:8080` @@ -43,4 +70,9 @@ This can be done on a Minimal debian CT (make sure to enable nesting) on the new Under Credentials click 'Add', enter 'jenkins' as username, and set the password that was set in the imgbuilder CT Then select the created credential and click save 7. Click 'Relaunch agent' -8. Now you can build container images \ No newline at end of file +8. Now you can build container images +## mysql +1. To configure the MySQL root password in the container run the setup script `bash /opt/Setup/Scripts/FirstRun.sh` +## gitea +1. Edit the parameters in the FistRun script in the container `vi /opt/Setup/Scripts/FirstRun.sh` +2. Run the FistRun scipt in the container `ash /opt/Setup/Scripts/FirstRun.sh` \ No newline at end of file