Skip to content

CI/CD GitHub Actions Automation, Helper Scripts, Container Creation Updates, Bug Fixes, Etc.#8

Merged
maxklema merged 25 commits intomieweb:mainfrom
maxklema:main
Aug 11, 2025
Merged

CI/CD GitHub Actions Automation, Helper Scripts, Container Creation Updates, Bug Fixes, Etc.#8
maxklema merged 25 commits intomieweb:mainfrom
maxklema:main

Conversation

@maxklema
Copy link
Contributor

@maxklema maxklema commented Jul 28, 2025

This PR contains all the related scripts for the implementation of the GitHub Actions CI/CD workflow and additions to the automation portion of the create container script.

Link to Proxmox Launchpad GH Action: https://github.com/marketplace/actions/proxmox-launchpad
NOTE: The README there will go over everything needed to get set up with the workflow.

YouTube Video going over how to use Proxmox Launchpad: https://www.youtube.com/watch?v=Xa2L1o-atEM
YouTube Video going over how to deploy projects to LXC containers automatically via the command line: https://www.youtube.com/watch?v=acDW-a32Yr8

Brief explanation of each file:

container creation/create-container-sh: Initial script called on the hypervisor to clone a container from a template if needed, install dependencies, public keys, and call deployment scripts
container creation/deployOnStart.sh: Helper script used for installing required dependencies into containers, writing environment variables, and any other installation commands to help deploy an application.
container creation/get-deployment-details.sh: Script located in Create Container LXC Container and is an extension of the create container script that collects user information about their repository to deploy it.
container creation/get-lxc-container-details.sh: Script called when users SSH to create-container@opensource.mieweb.org. Gathers basic information to create a container.
container creation/setup-runner.sh: If a user is using Proxmox Launchpad, this script is called to clone a container and install a GitHub runner on it to run future workflows/jobs in the repository.

container maintenance/helper-scripts/create-template.sh: If a user is using Proxmox Launchpad for automatic deployment, this script creates a LXC container template for future container clones to speed up the workflow.
container maintenance/helper-scripts/delete-runner.sh: If a user is using Proxmox Launchpad, and they delete a branch that is linked to a container, this script will remove the runner associated with that branch/container.
container maintenance/helper-scripts/PVE_user_authentication.sh: A script that verifies a user's Proxmox credentials.
container maintenance/helper-scripts/verify_container_ownership.sh: Verifies that the container the user is trying to access/modify rightfully belongs to them.
container maintenance/check-container-details.sh: Helper script used in Proxmox Launchpad to check if a container needs to be updated, or needs to clone the repository for the first time. This dictates whether to run the container update script or the container creation script.
container maintenance/delete-container.sh: Script called from Proxmox Launchpad to begin container/runner deletion process. Since the runner will be offline, it must call the delete-runner.sh.sh in a detached terminal session.
container maintenance/start_services.sh: Script that is called from create container to start services on the container and migrate the container if needed.
container maintenance/update-container.sh: Script used by Proxmox Launchpad to update containers, fetch new contents, and restart services.

@maxklema maxklema added the enhancement New feature or request label Jul 28, 2025
@maxklema maxklema self-assigned this Jul 28, 2025
Copy link
Collaborator

@cmyers-mieweb cmyers-mieweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a couple notes, mostly clarification points or ideas before merge. We can start with these and investigate more further after.

while [ "$REPOSITORY_BRANCH_EXISTS" != "200" ]; do
echo "⚠️ The branch you provided, \"$PROJECT_BRANCH\", does not exist on repository at \"$PROJECT_REPOSITORY\"."
read -p "🪾 Enter the project branch to deploy from (leave blank for \"main\") → " PROJECT_BRANCH
if [ "PROJECT_BRANCH" == "" ]; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This original conditional looks to be making a comparison with a a literal string, perhaps for better accuracy we can check the actual value of the $PROJECT_BRANCH var.

Suggested change
if [ "PROJECT_BRANCH" == "" ]; then
if [ -z "$PROJECT_BRANCH" ]; then

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I will re-factor these comparisons with empty strings to use the empty flag, -z.


source /root/bin/deployment-scripts/gatherEnvVars.sh # Gather Environment Variables
gatherSetupCommands "BUILD" "🏗️ Enter the build command (leave blank if no build command) → " # Gather Build Command(s)
gatherSetupCommands "INSTALL" "📦 Enter the install command (e.g., 'npm install') → " # Gather Install Command(s)echo "$INSTALL_COMMAND"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to guess that the addition of echo "$INSTALL_COMMAND" is a redundant comment addition? If it is intentional it can be kept, but marking this for script cleanup.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. It will be removed.

@@ -0,0 +1,37 @@
#!/bin/bash
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder with the addition of the user json argument in the container creation process if it will be more efficient to just iterate through port_map.json rather than rely on proxmox tags and checking the pct list which also may include containers with multiple tags? May also reduce this down to 1 or 2 jq commands to just grab the container hostname and user field.

Copy link
Contributor Author

@maxklema maxklema Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this idea. Prevents having to determine which Hypervisor the container belongs on and using conditional statements. Will refactor.

New re-factored code that checks port-map.json:

CONTAINER_NAME="${CONTAINER_NAME,,}"
CONTAINER_ID=$( { pct list; ssh root@10.15.0.5 'pct list'; } | awk -v name="$CONTAINER_NAME" '$3 == name {print $1}')

if [ -z "$CONTAINER_ID" ]; then
    echo "✅ Container with name \"$CONTAINER_NAME\" is available for use."
    return 1
fi

CONTAINER_OWNERSHIP=$(ssh root@10.15.20.69 -- "jq '.\"$CONTAINER_NAME\".user' /etc/nginx/port_map.json")
if [ "$TYPE_RUNNER" == "true" ] && (( $CONTAINER_ID % 2 == 0 )); then
    PVE1="false"
elif [ "$TYPE_RUNNER" == "true" ] && (( $CONTAINER_ID % 2 != 0 )); then
    PVE1="true"
fi

if [ "$CONTAINER_OWNERSHIP" == "null" ]; then
    echo "❌ You do not own the container with name \"$CONTAINER_NAME\"."
    outputError 1 "You do not own the container with name \"$CONTAINER_NAME\"."
fi


echo "🛎️ Installing Services..."

# SERVICE_COMMANDS=$(ssh -o SendEnv="LINUX_DISTRIBUTION SERVICES CUSTOM_SERVICES REQUIRE_SERVICES" \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this commented block have an ongoing purpose in the script? Or was it only used during the development cycle of making this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This block is uncommented now and fully implemented.

maxklema and others added 4 commits August 5, 2025 16:01
* LDAP configuration and prune scripts

* proxmox deployment changes

* updated container-creation scripts + re-organization

* READMEs in each directory, re-organization, updated ci-cd files

* READMEs in each directory, re-organization, updated ci-cd files

* proxmox launchpad submodule in ci-cd automation

* proxmox launchpad submodule

* proxmox launchpad submodule
* LDAP configuration and prune scripts

* proxmox deployment changes

* updated container-creation scripts + re-organization

* READMEs in each directory, re-organization, updated ci-cd files

* READMEs in each directory, re-organization, updated ci-cd files

* proxmox launchpad submodule in ci-cd automation

* proxmox launchpad submodule

* proxmox launchpad submodule

* Updated Root README + LDAP Folder

* UPDATED readme
@maxklema
Copy link
Contributor Author

maxklema commented Aug 5, 2025

I added a README to each folder and edited the existing README at the root directory. I also used AI to create a mermaid graph of how our cluster works at a high level. I thought it did a good job.

@maxklema maxklema requested a review from cmyers-mieweb August 5, 2025 22:22
@maxklema maxklema merged commit d7d780b into mieweb:main Aug 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants