initial working build
This commit is contained in:
		
							parent
							
								
									a85ca31b65
								
							
						
					
					
						commit
						03e91c5905
					
				
							
								
								
									
										34
									
								
								Containerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								Containerfile
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,34 @@ | |||||||
|  | # Caddy recommended way to build the custom image | ||||||
|  | FROM registry.belway.me/belwayhome/almalinux9-minimal:latest | ||||||
|  | 
 | ||||||
|  | ARG foundry_url | ||||||
|  | ARG nodejs_version | ||||||
|  | ENV foundry_url $foundry_url | ||||||
|  | ENV nodejs_version $nodejs_version | ||||||
|  | 
 | ||||||
|  | # Because pipeline is rootless | ||||||
|  | VOLUME /var/lib/containers | ||||||
|  | VOLUME /home/podman/.local/share/containers | ||||||
|  | 
 | ||||||
|  | RUN microdnf update \ | ||||||
|  |     && microdnf -y install \ | ||||||
|  |         openssl-devel \ | ||||||
|  |         tar \ | ||||||
|  |         unzip \ | ||||||
|  |         wget \ | ||||||
|  |     && rm -rf /var/cache/yum | ||||||
|  | 
 | ||||||
|  | RUN curl --silent --location https://rpm.nodesource.com/setup_${nodejs_version}.x | bash - \ | ||||||
|  |     && microdnf -y install \ | ||||||
|  |         nodejs \ | ||||||
|  |     && rm -rf /var/cache/yum | ||||||
|  | 
 | ||||||
|  | WORKDIR /foundryvtt/foundryvtt | ||||||
|  | RUN wget -O foundryvtt.zip ${foundry_url} && unzip foundryvtt.zip && rm foundryvtt.zip | ||||||
|  | 
 | ||||||
|  | WORKDIR /foundryvtt | ||||||
|  | 
 | ||||||
|  | VOLUME /foundryvtt/foundrydata | ||||||
|  | EXPOSE 30000 | ||||||
|  | 
 | ||||||
|  | ENTRYPOINT /usr/bin/node /foundryvtt/foundryvtt/resources/app/main.js --dataPath=/foundryvtt/foundrydata | ||||||
							
								
								
									
										36
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								README.md
									
									
									
									
									
								
							| @ -1,2 +1,38 @@ | |||||||
| # foundryvtt_container | # foundryvtt_container | ||||||
|  | ## Builidng the Container | ||||||
|  | Just run the script with the URL and Version declared as follows: | ||||||
|  | ```bash | ||||||
|  | ./build.sh -U $FOUNDRY_URL -I -v $VERSION | ||||||
|  | ``` | ||||||
| 
 | 
 | ||||||
|  | ## Running the Container | ||||||
|  | I'm using quadlets, so here's an example quadlet: | ||||||
|  | ```bash | ||||||
|  | # in your rootless podman container direction, ie: /etc/containers/systemd/users/${USER_UID}/ | ||||||
|  | # foundryvtt.container | ||||||
|  | [Unit] | ||||||
|  | Description=FoundryVTT Custom Container | ||||||
|  | Requires=var-mnt-data01.mount | ||||||
|  | 
 | ||||||
|  | [Container] | ||||||
|  | AutoUpdate=registry | ||||||
|  | HostName=${VM_HOSTNAME} | ||||||
|  | Image=registry.belway.me/public/foundryvtt_container:latest | ||||||
|  | Label=registry | ||||||
|  | Network=slirp4netns:port_handler=slirp4netns | ||||||
|  | PublishPort=30000:30000 | ||||||
|  | Timezone=America/Montreal | ||||||
|  | Volume=${YOUR_DATA_DIRECTORY_HERE}:/foundryvtt/foundrydata:z | ||||||
|  | 
 | ||||||
|  | [Service] | ||||||
|  | Restart=always | ||||||
|  | 
 | ||||||
|  | [Install] | ||||||
|  | WantedBy=multi-user.target default.target | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | Then as the user, run: | ||||||
|  | ```bash | ||||||
|  | systemctl --user daemon-reload | ||||||
|  | systemctl --user start foundryvtt | ||||||
|  | ``` | ||||||
|  | |||||||
							
								
								
									
										191
									
								
								build.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										191
									
								
								build.sh
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,191 @@ | |||||||
|  | #!/bin/bash | ||||||
|  | # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | ||||||
|  | # Name:         build.sh | ||||||
|  | # Author(s):    Thomas Belway | ||||||
|  | # Source:       https://gitea.belway.me/Public/foundryvtt_container.git | ||||||
|  | # Example:      ./build.sh -U $FOUNDRY_URL -I -v $VERSION | ||||||
|  | # Description:  Builds custom foundryvtt container and pushes to registry. | ||||||
|  | # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | ||||||
|  | 
 | ||||||
|  | #################################################################### | ||||||
|  | # Variables | ||||||
|  | #################################################################### | ||||||
|  | # General Variables | ||||||
|  | REGISTRY="registry.belway.me" | ||||||
|  | REGISTRY_NAMESPACE="public/foundryvtt_container" | ||||||
|  | 
 | ||||||
|  | ############################################################################################################################### | ||||||
|  | # Functions | ||||||
|  | ############################################################################################################################### | ||||||
|  | 
 | ||||||
|  | # Informational Functions | ||||||
|  | usage() { | ||||||
|  | cat << EOF | ||||||
|  | 
 | ||||||
|  | usage: ${SCRIPT_NAME} [options] | ||||||
|  | 
 | ||||||
|  | This script exports data from one database to be compared with data from another database | ||||||
|  | 
 | ||||||
|  | OPTIONS: | ||||||
|  |     -D      Enable DEBUG mode | ||||||
|  |     -f      Custom Containerfile with absolute or relative directory | ||||||
|  |     -F      Format of containerfile | ||||||
|  |     -h      Show this message | ||||||
|  |     -I      Initialize the registry | ||||||
|  |     -n      Node version | ||||||
|  |     -R      For rebuild the image. | ||||||
|  |     -S      Scheduled build, should only be used by automation (gitea actions). | ||||||
|  |     -U      Foundry URL for downloading the version | ||||||
|  |     -v      Version to build, defaults to 'latest' | ||||||
|  | EOF | ||||||
|  | exit 1 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | get_parameters() { | ||||||
|  |     while getopts "Df:F:hIRSU:v:" option_name; do | ||||||
|  |         case "$option_name" in | ||||||
|  |             "D") | ||||||
|  |                 DEBUG="YES" | ||||||
|  |                 ;; | ||||||
|  |             "f") | ||||||
|  |                 OPT_CONTAINERFILE="$OPTARG" | ||||||
|  |                 ;; | ||||||
|  |             "F") | ||||||
|  |                 OPT_FORMAT_TYPE="$OPTARG" | ||||||
|  |                 ;; | ||||||
|  |             "h") | ||||||
|  |                 usage | ||||||
|  |                 ;; | ||||||
|  |             "I") | ||||||
|  |                 INITIALIZE="TRUE" | ||||||
|  |                 ;; | ||||||
|  |             "n") | ||||||
|  |                 NODEJS_VERSION="$OPTARG" | ||||||
|  |                 ;; | ||||||
|  |             "R") | ||||||
|  |                 OPT_REBUILD="TRUE" | ||||||
|  |                 ;; | ||||||
|  |             "S") | ||||||
|  |                 OPT_SCHEDULED="TRUE" | ||||||
|  |                 ;; | ||||||
|  |             "U") | ||||||
|  |                 FOUNDRY_URL="$OPTARG" | ||||||
|  |                 ;; | ||||||
|  |             "v") | ||||||
|  |                 OPT_VERSION="$OPTARG" | ||||||
|  |                 ;; | ||||||
|  |             "?") | ||||||
|  |                 echo "Error: Unknown option $OPTARG" | ||||||
|  |                 usage | ||||||
|  |                 ;; | ||||||
|  |             ":") | ||||||
|  |                 echo "Error: No argument value for option $OPTARG" | ||||||
|  |                 usage | ||||||
|  |                 ;; | ||||||
|  |             *) | ||||||
|  |                 echo "Error: Unknown error while processing options" | ||||||
|  |                 usage | ||||||
|  |                 ;; | ||||||
|  |         esac | ||||||
|  |     done | ||||||
|  | 
 | ||||||
|  |     if [[ -z $FOUNDRY_URL ]]; then | ||||||
|  |         echo "Need the foundry URL, please try again..." | ||||||
|  |         exit 1 | ||||||
|  |     fi | ||||||
|  | 
 | ||||||
|  |     if [[ -z $OPT_CONTAINERFILE ]]; then | ||||||
|  |         OPT_CONTAINERFILE="Containerfile" | ||||||
|  |     fi | ||||||
|  | 
 | ||||||
|  |     if [[ -z $OPT_FORMAT_TYPE ]]; then | ||||||
|  |         OPT_FORMAT="--format docker" | ||||||
|  |     elif [[ $OPT_FORMAT_TYPE == "podman" ]]; then | ||||||
|  |         OPT_FORMAT="" | ||||||
|  |     else | ||||||
|  |         OPT_FORMAT="--format ${OPT_FORMAT_TYPE}" | ||||||
|  |     fi | ||||||
|  | 
 | ||||||
|  |     if [[ $DEBUG == "YES" ]]; then | ||||||
|  |         SILENCE_OUTPUT="" | ||||||
|  | 	    SILENCE_STOUT=" " | ||||||
|  |         echo "Debug mode enabled." | ||||||
|  |     fi | ||||||
|  | 
 | ||||||
|  |     if [[ -z $OPT_REBUILD ]]; then | ||||||
|  |         OPT_REBUILD="FALSE" | ||||||
|  |     fi | ||||||
|  | 
 | ||||||
|  |     if [[ -z $OPT_SCHEDULED ]]; then | ||||||
|  |         OPT_SCHEDULED="FALSE" | ||||||
|  |     fi | ||||||
|  | 
 | ||||||
|  |     if [[ -z $OPT_VERSION ]]; then | ||||||
|  |         OPT_VERSION="12.331" | ||||||
|  |     fi | ||||||
|  | 
 | ||||||
|  |     if [[ "${OPT_SCHEDULED}" == "TRUE" ]]; then | ||||||
|  |         OPT_REBUILD="FALSE" | ||||||
|  |     fi | ||||||
|  | 
 | ||||||
|  |     if [[ -z $NODEJS_VERSION ]]; then | ||||||
|  |         NODEJS_VERSION=$(curl https://foundryvtt.com/article/installation/ | grep nodesource | grep rpm | tr -d -c 0-9) | ||||||
|  |     fi | ||||||
|  | 
 | ||||||
|  | TAG="$OPT_VERSION" | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | # Build Functions | ||||||
|  | 
 | ||||||
|  | container_initialize() { | ||||||
|  |     echo "Initializing container build..." | ||||||
|  |     podman login ${REGISTRY} | ||||||
|  |     podman build -f ${OPT_CONTAINERFILE} -t ${REGISTRY}/${REGISTRY_NAMESPACE}:${TAG} -t ${REGISTRY}/${REGISTRY_NAMESPACE}:latest --build-arg foundry_url=${FOUNDRY_URL} --build-arg nodejs_version=${NODEJS_VERSION} | ||||||
|  |     podman push ${REGISTRY}/${REGISTRY_NAMESPACE}:${TAG} | ||||||
|  |     podman push ${REGISTRY}/${REGISTRY_NAMESPACE}:latest | ||||||
|  |     podman logout ${REGISTRY} | ||||||
|  |     echo "Container build initialized!" | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | container_scheduled_build() { | ||||||
|  |     echoo "Scheduled build starting..." | ||||||
|  |     if [[ "${CADDY_IMAGE_VERSION}" != "${CUSTOM_CADDY_IMAGE_VERSION}" ]]; then | ||||||
|  |         podman login ${REGISTRY} | ||||||
|  |         podman build -f ${OPT_CONTAINERFILE} -t ${REGISTRY}/${REGISTRY_NAMESPACE}:${TAG} -t ${REGISTRY}/${REGISTRY_NAMESPACE}:latest --build-arg foundry_url=${FOUNDRY_URL} | ||||||
|  |         podman push ${REGISTRY}/${REGISTRY_NAMESPACE}:${TAG} | ||||||
|  |         podman push ${REGISTRY}/${REGISTRY_NAMESPACE}:latest | ||||||
|  |         podman logout ${REGISTRY} | ||||||
|  |     else | ||||||
|  |         echo "No new version, exiting..." | ||||||
|  |         exit 1 | ||||||
|  |     fi | ||||||
|  |     echo "Scheduled build complete!" | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | container_rebuild() { | ||||||
|  |     echo "Rebuilding container..." | ||||||
|  |     podman login ${REGISTRY} | ||||||
|  |     podman build -f ${OPT_CONTAINERFILE} -t ${REGISTRY}/${REGISTRY_NAMESPACE}:${TAG} -t ${REGISTRY}/${REGISTRY_NAMESPACE}:latest --build-arg foundry_url=${FOUNDRY_URL} | ||||||
|  |     podman push ${REGISTRY}/${REGISTRY_NAMESPACE}:${TAG} | ||||||
|  |     podman push ${REGISTRY}/${REGISTRY_NAMESPACE}:latest | ||||||
|  |     podman logout ${REGISTRY} | ||||||
|  |     echo "Rebuild complete!" | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | ############################################################################################################################### | ||||||
|  | # Main Script | ||||||
|  | ############################################################################################################################### | ||||||
|  | get_parameters "$@" | ||||||
|  | 
 | ||||||
|  | if [[ "$OPT_SCHEDULED" == "TRUE" ]]; then | ||||||
|  |     container_scheduled_build | ||||||
|  | fi | ||||||
|  | 
 | ||||||
|  | if [[ "$OPT_REBUILD" == "TRUE" ]]; then | ||||||
|  |     container_rebuild | ||||||
|  | fi | ||||||
|  | 
 | ||||||
|  | if [[ "$INITIALIZE" == "TRUE" ]]; then | ||||||
|  |     container_initialize | ||||||
|  | fi | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user