mirror of
https://gitlab.com/Snogard/kaido.git
synced 2025-08-20 02:40:10 +02:00
added foundry build script, provided you have private repository
This commit is contained in:
parent
c60f32cad8
commit
0228e38f65
31
build/foundry/Dockerfile.10
Normal file
31
build/foundry/Dockerfile.10
Normal file
@ -0,0 +1,31 @@
|
||||
FROM docker.io/node:14-alpine3.13
|
||||
|
||||
LABEL name=foundry
|
||||
LABEL version=1.0
|
||||
|
||||
ENV UID=1000
|
||||
ENV GUID=1000
|
||||
|
||||
RUN apk --update --no-cache add jq
|
||||
RUN deluser node
|
||||
RUN addgroup -g $GUID foundry \
|
||||
&& adduser -u $UID -G foundry -s /bin/sh -D foundry
|
||||
|
||||
USER foundry
|
||||
|
||||
RUN mkdir -p /home/foundry/data
|
||||
|
||||
## try
|
||||
RUN mkdir -p /home/foundry/.local/share/FoundryVTT
|
||||
COPY src /home/foundry/src
|
||||
|
||||
RUN mkdir -p /home/foundry/tmp
|
||||
|
||||
COPY ./foundry /home/foundry/instance
|
||||
|
||||
WORKDIR /home/foundry/instance
|
||||
|
||||
EXPOSE 30000/TCP
|
||||
|
||||
ENTRYPOINT ["/home/foundry/src/entrypoint.sh"]
|
||||
CMD ["resources/app/main.js", "--headless", "--noupdate", "--dataPath=/home/foundry/data"]
|
31
build/foundry/Dockerfile.11
Normal file
31
build/foundry/Dockerfile.11
Normal file
@ -0,0 +1,31 @@
|
||||
FROM docker.io/node:18-alpine3.18
|
||||
|
||||
LABEL name=foundry
|
||||
LABEL version=1.0
|
||||
|
||||
ENV UID=1000
|
||||
ENV GUID=1000
|
||||
|
||||
RUN apk --update --no-cache add jq
|
||||
RUN deluser node
|
||||
RUN addgroup -g $GUID foundry \
|
||||
&& adduser -u $UID -G foundry -s /bin/sh -D foundry
|
||||
|
||||
USER foundry
|
||||
|
||||
RUN mkdir -p /home/foundry/data
|
||||
|
||||
## try
|
||||
RUN mkdir -p /home/foundry/.local/share/FoundryVTT
|
||||
COPY src /home/foundry/src
|
||||
|
||||
RUN mkdir -p /home/foundry/tmp
|
||||
|
||||
COPY ./foundry /home/foundry/instance
|
||||
|
||||
WORKDIR /home/foundry/instance
|
||||
|
||||
EXPOSE 30000/TCP
|
||||
|
||||
ENTRYPOINT ["/home/foundry/src/entrypoint.sh"]
|
||||
CMD ["resources/app/main.js", "--headless", "--noupdate", "--dataPath=/home/foundry/data"]
|
31
build/foundry/Dockerfile.9
Normal file
31
build/foundry/Dockerfile.9
Normal file
@ -0,0 +1,31 @@
|
||||
FROM docker.io/node:14-alpine3.13
|
||||
|
||||
LABEL name=foundry
|
||||
LABEL version=1.0
|
||||
|
||||
ENV UID=1000
|
||||
ENV GUID=1000
|
||||
|
||||
RUN apk --update --no-cache add jq
|
||||
RUN deluser node
|
||||
RUN addgroup -g $GUID foundry \
|
||||
&& adduser -u $UID -G foundry -s /bin/sh -D foundry
|
||||
|
||||
USER foundry
|
||||
|
||||
RUN mkdir -p /home/foundry/data
|
||||
|
||||
## try
|
||||
RUN mkdir -p /home/foundry/.local/share/FoundryVTT
|
||||
COPY src /home/foundry/src
|
||||
|
||||
RUN mkdir -p /home/foundry/tmp
|
||||
|
||||
COPY ./foundry /home/foundry/instance
|
||||
|
||||
WORKDIR /home/foundry/instance
|
||||
|
||||
EXPOSE 30000/TCP
|
||||
|
||||
ENTRYPOINT ["/home/foundry/src/entrypoint.sh"]
|
||||
CMD ["resources/app/main.js", "--headless", "--noupdate", "--dataPath=/home/foundry/data"]
|
18
build/foundry/src/entrypoint.sh
Executable file
18
build/foundry/src/entrypoint.sh
Executable file
@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
|
||||
optionsPath=/home/foundry/data/Config/options.json
|
||||
|
||||
if [ -f "${optionsPath}" ]; then
|
||||
echo "${optionsPath} found"
|
||||
echo $(jq ".hostname=\"$HOSTNAME\"" "${optionsPath}") > "${optionsPath}"
|
||||
echo $(jq ".routePrefix=\"$ROUTE_PREFIX\"" "${optionsPath}") > "${optionsPath}"
|
||||
echo $(jq ".proxySSL=true" "${optionsPath}") > "${optionsPath}"
|
||||
echo $(jq ".proxyPort=443" "${optionsPath}") > "${optionsPath}"
|
||||
else
|
||||
echo "${optionsPath} not found the settings will be applied on next restart"
|
||||
fi
|
||||
|
||||
|
||||
node "$@"
|
||||
|
||||
exit 0
|
@ -25,6 +25,7 @@ every configuration must be under /etc/kaido.
|
||||
- system (not implemented)
|
||||
- user (not implemented)
|
||||
- update.conf
|
||||
- envs.sh
|
||||
### /etc/kaido/update.conf
|
||||
this file contains the definitions of what must be installed/configured/built when using the "kaido update" command
|
||||
|
||||
@ -44,6 +45,13 @@ regardless of the order in the file, the execution is in this order:
|
||||
|
||||
warning: No parameters are supported yet
|
||||
|
||||
### /etc/kaido/envs.sh
|
||||
This file will be sourced to overrwrite default envs
|
||||
|
||||
CONTAINERS_FOLDER: where container folders are created by default
|
||||
BUILDS_FOLDER: where files are downloaded for build purposes
|
||||
KAIDO_CONFIG_FOLDER: where kaido will look for a kaido-config repository (not fully implemented)
|
||||
|
||||
# Container Installation:
|
||||
|
||||
### gitlab-runner
|
||||
|
33
src/commands/build.sh
Executable file
33
src/commands/build.sh
Executable file
@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
source /opt/kaido/src/libs/bash/lib.sh
|
||||
|
||||
prefix=build
|
||||
|
||||
rootFolder="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||
scriptFolder=${rootFolder}/${prefix}
|
||||
|
||||
|
||||
scriptName=$1
|
||||
scriptPath=${scriptFolder}/${prefix}-${scriptName}.sh
|
||||
|
||||
buildPath="$BUILDS_FOLDER/$scriptName"
|
||||
|
||||
if [ -d "$buildPath" ]; then
|
||||
sudo rm -rf "$buildPath"
|
||||
fi
|
||||
|
||||
mkdir -p "$buildPath"
|
||||
|
||||
if test -f "$scriptPath"; then
|
||||
|
||||
if [[ ! -x "$scriptPath" ]]; then
|
||||
sudo chmod +x $scriptPath
|
||||
fi
|
||||
echo "Executing: $scriptPath $2 $3 $4 $5 $6 $7"
|
||||
echo "in folder: $buildPath"
|
||||
cp -ra "/opt/kaido/build/$scriptName/." "$buildPath"
|
||||
cd "$buildPath"
|
||||
$scriptPath $2 $3 $4 $5 $6 $7
|
||||
else
|
||||
echo "Error file not found: ${scriptPath}"
|
||||
fi
|
74
src/commands/build/build-foundry.sh
Executable file
74
src/commands/build/build-foundry.sh
Executable file
@ -0,0 +1,74 @@
|
||||
#!/bin/bash
|
||||
source /opt/kaido/src/libs/bash/lib.sh
|
||||
|
||||
|
||||
containerName=foundry
|
||||
version=$1
|
||||
|
||||
|
||||
# envs
|
||||
repository=https://example.com/user/foundry.git
|
||||
|
||||
if [ -f "$KAIDO_CONFIG_FOLDER/build/$containerName/envs.sh" ]; then
|
||||
source "$KAIDO_CONFIG_FOLDER/build/$containerName/envs.sh"
|
||||
fi
|
||||
|
||||
#TODO: make a better check, this is dumb :)
|
||||
if [[ "$repository" == "https://example.com/user/foundry.git" ]]; then
|
||||
echo "ERROR: please set the 'repository' variable in '$KAIDO_CONFIG_FOLDER/build/$containerName/envs.sh'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
if [ -d "./foundry" ]; then
|
||||
if [ -d "./foundry/.git" ]; then
|
||||
echo "Repo already present"
|
||||
else
|
||||
echo "Removing old foundry folder"
|
||||
rm -r ./foundry
|
||||
git clone $repository
|
||||
fi
|
||||
else
|
||||
git clone $repository
|
||||
fi
|
||||
|
||||
cd foundry
|
||||
|
||||
git pull
|
||||
git fetch --tags
|
||||
|
||||
if [ ! -n "${version}" ]; then
|
||||
echo "Version not specified, selecting lastest version"
|
||||
version=$(git describe)
|
||||
fi
|
||||
|
||||
|
||||
IFS='.' read -ra TMP <<< "$version"
|
||||
major="${TMP[0]}"
|
||||
|
||||
|
||||
tag=$containerName:version-${version}
|
||||
dockerFile=Dockerfile
|
||||
if [[ $major -lt 1 ]]; then
|
||||
dockerFile="Dockerfile.9"
|
||||
else
|
||||
dockerFile="Dockerfile.$major"
|
||||
fi
|
||||
|
||||
if git tag | grep -qi $version ; then
|
||||
git checkout $version
|
||||
else
|
||||
echo "Version not found, please choose one of the available: "
|
||||
git tag
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -rf ./.git
|
||||
|
||||
cd ..
|
||||
|
||||
chmod +x -R ./src
|
||||
|
||||
podman build -f ./$dockerFile -t $tag
|
||||
|
||||
exit 0
|
@ -1,3 +1,13 @@
|
||||
#TODO: make envs configurable
|
||||
CONTAINERS_FOLDER="/mnt/storage/containers"
|
||||
MASTER_CONFIG_FOLDER="$HOME/.config/kaido"
|
||||
CONTAINERS_FOLDER="$HOME/.local/share/kaido/containers"
|
||||
BUILDS_FOLDER="$HOME/.cache/kaido/build"
|
||||
|
||||
#TODO check if this is used
|
||||
MASTER_CONFIG_FOLDER="$HOME/.config/kaido"
|
||||
|
||||
|
||||
if [ -f "/etc/kaido/envs.sh" ]; then
|
||||
source /etc/kaido/envs.sh
|
||||
fi
|
||||
|
||||
# keep here until fully implemented, maybe read it from kaido.conf?
|
||||
KAIDO_CONFIG_FOLDER="/etc/kaido"
|
102
src/libs/python/podman-generate-systemd.py
Normal file
102
src/libs/python/podman-generate-systemd.py
Normal file
@ -0,0 +1,102 @@
|
||||
import os
|
||||
import json
|
||||
|
||||
|
||||
VERSION="0.1"
|
||||
|
||||
#fake passed arguments
|
||||
|
||||
containerName="container-registry"
|
||||
|
||||
#systemd unit
|
||||
restart=always
|
||||
restartSec=60
|
||||
timoutStopSec=70
|
||||
serviceType=forking
|
||||
#----
|
||||
|
||||
#fake taken arguments
|
||||
|
||||
userId=1000
|
||||
userName=snogard
|
||||
|
||||
#----
|
||||
|
||||
|
||||
def command(command):
|
||||
return os.system(command) == 0
|
||||
|
||||
def createSystemdUnit(prefix,name,containerName,pidFilePath,wants="",after="",restartPolicy="always",restartSec=60,timeoutStopSec=60,timeoutStartSec=60):
|
||||
serviceFileName=f"{prefix}-{name}.service"
|
||||
serviceFilePath=f"/home/snogard/.config/systemd/user/{serviceFileName}"
|
||||
if os.path.isfile(serviceFilePath):
|
||||
os.remove(serviceFilePath)
|
||||
|
||||
command(f"echo '# {serviceFileName}' >> {serviceFilePath}")
|
||||
command(f"echo '# autogenerated by kaido's script {VERSION}' >> {serviceFilePath}")
|
||||
command(f"echo \"# $(date)\" >> {serviceFilePath}")
|
||||
command(f"echo '' >> {serviceFilePath}")
|
||||
command(f"echo '[Unit]' >> {serviceFilePath}")
|
||||
command(f"echo 'Description=Podman {serviceFileName}' >> {serviceFilePath}")
|
||||
command(f"echo 'Documentation=https://gitlab.com/Snogard/kaido' >> {serviceFilePath}")
|
||||
command(f"echo 'Wants=network-online.target {wants}' >> {serviceFilePath}")
|
||||
command(f"echo 'After=network-online.target {after}' >> {serviceFilePath}")
|
||||
command(f"echo 'RequiresMountsFor=/run/user/{userId}/containers' >> {serviceFilePath}")
|
||||
command(f"echo '' >> {serviceFilePath}")
|
||||
command(f"echo '[Service]' >> {serviceFilePath}")
|
||||
command(f"echo 'Environment=PODMAN_SYSTEMD_UNIT=%n' >> {serviceFilePath}")
|
||||
command(f"echo 'Restart={restartPolicy}' >> {serviceFilePath}")
|
||||
command(f"echo 'RestartSec={restartSec}' >> {serviceFilePath}")
|
||||
command(f"echo 'TimeoutStopSec={timeoutStopSec}' >> {serviceFilePath}")
|
||||
command(f"echo 'TimeoutStartSec={timeoutStartSec}' >> {serviceFilePath}")
|
||||
command(f"echo 'ExecStart=/usr/bin/podman start {containerName}' >> {serviceFilePath}")
|
||||
command(f"echo 'ExecStop=/usr/bin/podman stop -t 10 {containerName}' >> {serviceFilePath}")
|
||||
command(f"echo 'ExecStopPost=/usr/bin/podman stop -t 10 {containerName}' >> {serviceFilePath}")
|
||||
command(f"echo 'PIDFile={pidFilePath}' >> {serviceFilePath}")
|
||||
command(f"echo 'Type=forking' >> {serviceFilePath}")
|
||||
command(f"echo '' >> {serviceFilePath}")
|
||||
command(f"echo '[Install]' >> {serviceFilePath}")
|
||||
command(f"echo 'WantedBy=default.target' >> {serviceFilePath}")
|
||||
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
|
||||
tmpfolder=f"/tmp/kaido/podman/{containerName}"
|
||||
containerInfoPath=f"{tmpfolder}/{containerName}.json"
|
||||
|
||||
# TODO: remove if exists
|
||||
if not os.path.exists(tmpfolder):
|
||||
os.makedirs(tmpfolder)
|
||||
|
||||
|
||||
if command(f"podman pod inspect {containerName} > '{containerInfoPath}'"):
|
||||
print("i'm a pod")
|
||||
containerInfoFile=open(containerInfoPath,"r")
|
||||
podInfo=json.loads(containerInfoFile.read())
|
||||
containerInfoFile.close()
|
||||
|
||||
for item in podInfo["Containers"]:
|
||||
childName=item["Name"]
|
||||
jsonPath=f"{tmpfolder}/{childName}.json"
|
||||
command(f"podman container inspect {childName} > '{jsonPath}'")
|
||||
jsonFile=open(jsonPath,"r")
|
||||
info=json.loads(jsonFile.read())
|
||||
jsonFile.close()
|
||||
|
||||
pidFilePath=info["ConmonPidFile"]
|
||||
if "infra" in childName:
|
||||
createSystemdUnit("pod",containerName,childName,pidFilePath)
|
||||
else
|
||||
createSystemdUnit("container",childName,childName,pidFilePath)
|
||||
|
||||
|
||||
elif command(f"podman container inspect {containerName} > '{containerInfoPath}'"):
|
||||
print("i'm a container")
|
||||
|
||||
else:
|
||||
# print("container does not exists")
|
||||
quit(1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user