[main] Git stuff
This commit is contained in:
@@ -18,16 +18,16 @@ jobs:
|
||||
- name: Build Docker Image
|
||||
run: |
|
||||
COMMIT_HASH=$(git rev-parse --short HEAD)
|
||||
docker build -t registry.i80.dk/gitea/portugalfaq:latest -t registry.i80.dk/gitea/portugalfaq:${COMMIT_HASH} .
|
||||
docker build -t registry.i80.dk/gitea/[[PROJECT_NAME]]:latest -t registry.i80.dk/gitea/[[PROJECT_NAME]]:${COMMIT_HASH} .
|
||||
|
||||
|
||||
- name: Push Docker Image
|
||||
run: |
|
||||
COMMIT_HASH=$(git rev-parse --short HEAD)
|
||||
echo "registry.i80.dk/gitea/portugalfaq:latest"
|
||||
echo "registry.i80.dk/gitea/portugalfaq:${COMMIT_HASH}"
|
||||
docker push registry.i80.dk/gitea/portugalfaq:${COMMIT_HASH}
|
||||
docker push registry.i80.dk/gitea/portugalfaq:latest
|
||||
echo "registry.i80.dk/gitea/[[PROJECT_NAME]]:latest"
|
||||
echo "registry.i80.dk/gitea/[[PROJECT_NAME]]:${COMMIT_HASH}"
|
||||
docker push registry.i80.dk/gitea/[[PROJECT_NAME]]:${COMMIT_HASH}
|
||||
docker push registry.i80.dk/gitea/[[PROJECT_NAME]]:latest
|
||||
|
||||
|
||||
- name: Validate Nomad Job
|
||||
@@ -38,7 +38,7 @@ jobs:
|
||||
- name: Stop old deployment
|
||||
env:
|
||||
NOMAD_ADDR: https://nomad.i80.dk
|
||||
run: nomad job stop -purge -no-shutdown-delay portugalfaq
|
||||
run: nomad job stop -purge -no-shutdown-delay [[PROJECT_NAME]]
|
||||
continue-on-error: true
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ jobs:
|
||||
run: nomad job run .gitea/workflows/nomad-job.hcl
|
||||
|
||||
- name: Update Nginx Configuration
|
||||
run: ssh runner@nomad sudo /opt/nginx_updater/venv/bin/python3 /opt/nginx_updater/nginx_updater.py portugalfaq
|
||||
run: ssh runner@nomad sudo /opt/nginx_updater/venv/bin/python3 /opt/nginx_updater/nginx_updater.py [[PROJECT_NAME]]
|
||||
|
||||
|
||||
|
||||
@@ -56,6 +56,6 @@ jobs:
|
||||
# env:
|
||||
# NOMAD_ADDR: https://nomad.i80.dk
|
||||
# run: |
|
||||
# nomad job stop portugalfaq
|
||||
# nomad job stop [[PROJECT_NAME]]
|
||||
# sleep 5 # Optional: Wait to ensure the old allocation is stopped
|
||||
# nomad job run .gitea/workflows/nomad-job.hcl
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
job "portugalfaq" {
|
||||
job "{{PROJECT_NAME}}" {
|
||||
region = "global"
|
||||
datacenters = ["dc1"]
|
||||
type = "service"
|
||||
@@ -9,19 +9,19 @@ job "portugalfaq" {
|
||||
progress_deadline = "6m"
|
||||
}
|
||||
|
||||
group "portugalfaq-group" {
|
||||
group "[[PROJECT_NAME]]-group" {
|
||||
count = 1
|
||||
|
||||
network {
|
||||
port "port-app" {
|
||||
to = 9912 # Internal application port
|
||||
to = [[PORT]] # Internal application port
|
||||
}
|
||||
}
|
||||
|
||||
# Register the service with Consul
|
||||
service {
|
||||
provider = "consul"
|
||||
name = "portugalfaq"
|
||||
name = "[[PROJECT_NAME]]"
|
||||
port = "port-app"
|
||||
|
||||
# Traefik-specific tags for routing
|
||||
@@ -38,11 +38,11 @@ job "portugalfaq" {
|
||||
}
|
||||
}
|
||||
|
||||
task "portugalfaq-task" {
|
||||
task "[[PROJECT_NAME]]-task" {
|
||||
driver = "docker"
|
||||
|
||||
config {
|
||||
image = "registry.i80.dk/gitea/portugalfaq:latest"
|
||||
image = "registry.i80.dk/gitea/{{PROJECT_NAME}}:latest"
|
||||
ports = ["port-app"]
|
||||
}
|
||||
|
||||
|
||||
61
project_installer.py
Normal file
61
project_installer.py
Normal file
@@ -0,0 +1,61 @@
|
||||
import os
|
||||
import random
|
||||
import pystache
|
||||
import argparse
|
||||
import re
|
||||
|
||||
def render_templates(template_dir, project_name):
|
||||
import pystache # Import after ensuring it's installed
|
||||
|
||||
# Generate a random port number
|
||||
port = random.randint(8900, 9400)
|
||||
|
||||
# Mustache data (dynamic placeholders)
|
||||
data = {
|
||||
"PROJECT_NAME": project_name,
|
||||
"PORT": port
|
||||
}
|
||||
|
||||
# Define a regex for detecting [[ ... ]] custom placeholders
|
||||
pattern = re.compile(r"\[\[(.*?)\]\]")
|
||||
|
||||
# Process all .tmpl files in the directory
|
||||
for root, _, files in os.walk(template_dir):
|
||||
for file in files:
|
||||
if file.endswith(".tmpl"):
|
||||
tmpl_file = os.path.join(root, file)
|
||||
output_file = os.path.join(root, file.replace(".tmpl", ""))
|
||||
|
||||
# Read the template file
|
||||
with open(tmpl_file, 'r') as f:
|
||||
template_content = f.read()
|
||||
|
||||
# Replace placeholders wrapped with [[ ... ]]
|
||||
def replace_placeholder(match):
|
||||
key = match.group(1)
|
||||
return str(data.get(key, match.group(0))) # Replace only if key exists
|
||||
|
||||
rendered_content = pattern.sub(replace_placeholder, template_content)
|
||||
|
||||
# Write to output file
|
||||
with open(output_file, 'w') as f:
|
||||
f.write(rendered_content)
|
||||
print(f"Generated: {output_file}")
|
||||
|
||||
|
||||
def main():
|
||||
# Parse arguments
|
||||
parser = argparse.ArgumentParser(description="Render Mustache templates in a directory.")
|
||||
parser.add_argument('--project-name', type=str, help='Project name (defaults to current directory name)')
|
||||
parser.add_argument('--template-dir', type=str, default='.gitea/workflows', help='Template directory')
|
||||
args = parser.parse_args()
|
||||
|
||||
# Get the project name (current directory name if not provided)
|
||||
project_name = args.project_name or os.path.basename(os.getcwd())
|
||||
|
||||
# Render templates
|
||||
render_templates(args.template_dir, project_name)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user