Skip to content

Commit

Permalink
Merge pull request #182 from compose-generator/release/v1.1.x
Browse files Browse the repository at this point in the history
Release of version 1.1.0
  • Loading branch information
marcauberer committed Oct 23, 2021
2 parents 0063a82 + f9c7d56 commit 8e4005f
Show file tree
Hide file tree
Showing 171 changed files with 2,524 additions and 995 deletions.
80 changes: 80 additions & 0 deletions .github/scripts/service-tester/predefined-service-tester.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"""Script to test all combinations of predefined service templates"""

from os.path import isdir, join
from os import listdir, system, remove
import sys
import itertools
import yaml

MAX_COMBINATION_SIZE = 1 # Careful! Runtime increases exponentially
TEMPLATES_PATH = "../../../predefined-services"
BIN_PATH = "../../../bin"

def get_all_template_names():
"""Returns a string array with all existing template names"""

template_tuples = []
template_types = ["backend", "database", "db-admin", "frontend"]
skipped_names = ["rocket", "faunadb", "gitea", "gitlab"]
for template_type in template_types:
template_type_path = TEMPLATES_PATH + '/' + template_type
services = [f for f in listdir(template_type_path) if isdir(join(template_type_path, f))]
for service in services:
if service not in skipped_names:
template_tuples.append((service, template_type))

return template_tuples

def test_combination(comb):
"""Tests one particular combination of services"""
# Create config file
services = []
for service in comb:
services.append({"name": service[0], "type": service[1]})
config = {"project_name": "Example project", "services": services}
with open(BIN_PATH + "/config.yml", "w", encoding='utf-8') as file:
yaml.dump(config, file, default_flow_style=False)

# Execute Compose Generator with the config file
if system(f"cd {BIN_PATH} && compose-generator -c config.yml -i") != 0:
sys.exit("Compose Generator failed when generating stack for combination " + str(comb))

# Delete config file
remove(BIN_PATH + "/config.yml")

# Execute Compose Generator with the config file
if system(f"cd {BIN_PATH} && docker compose up -d") != 0:
sys.exit("Docker failed when generating stack for combination " + str(comb))

if system(f"cd {BIN_PATH} && docker compose down") != 0:
sys.exit("Error on 'docker compose down' for " + str(comb))

def reset_environment():
"""Deletes all Docker related stuff. Should be executed after each test"""
system("docker system prune -af > /dev/null")
system(f"sudo rm -rf {BIN_PATH}/*")

# Initially reset the testing environment
print("Do initial cleanup ...", end='')
reset_environment()
print(" done")

# Find all possible template combinations
print("Collecting template names ...", end='')
templates = get_all_template_names()
combinations = []
for i in range(1, MAX_COMBINATION_SIZE +1):
combinations.extend(list(itertools.combinations(templates, i)))
print(" done")
print(combinations)

# Execute test for each combination
print("Execute tests ...")
for i, combination in enumerate(combinations):
print(f"Testing combination {i+1} of {len(combinations)}: {str(combination)} ...")
test_combination(combination)
reset_environment()
print("Done")

# Test was successful
print("Tested all combinations successfully!")
1 change: 1 addition & 0 deletions .github/scripts/service-tester/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyyaml
21 changes: 13 additions & 8 deletions .github/scripts/service-validator/predefined-service-validator.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
"""Script to validate the files of all predefined service templates"""

from os.path import isfile, isdir, join
from os import listdir
from cerberus import Validator
import sys
import yaml
import json
from cerberus import Validator
import yaml

def checkFileExistence():
def check_file_existence():
"""Checks if all required files exist"""
print('Checking file existence ...', end='')
status = True
template_path = '../../../predefined-services'
Expand All @@ -30,7 +33,8 @@ def checkFileExistence():
print(' done')
return status

def checkYamlValidity():
def check_yaml_validity():
"""Checks the validity of a YAML file"""
print('Checking YAML validity ...', end='')
status = True
schema = eval(open('./service-schema.py').read())
Expand All @@ -49,7 +53,8 @@ def checkYamlValidity():
print(' done')
return status

def checkJsonValidity():
def check_json_validity():
"""Checks the validity of a JSON file"""
print('Checking JSON validity ...', end='')
status = True
schema = eval(open('./config-schema.py').read())
Expand Down Expand Up @@ -83,9 +88,9 @@ def loadJsonDoc(path):
raise exception

# Execute checks
if not checkFileExistence():
if not check_file_existence():
sys.exit('File existence check failed.')
if not checkYamlValidity():
if not check_yaml_validity():
sys.exit('Yaml validation check failed.')
if not checkJsonValidity():
if not check_json_validity():
sys.exit('Json validation check failed.')
1 change: 1 addition & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
#- feature/**
#- service/**
#- fix/**
- chore/**
paths:
- docs/**
workflow_dispatch:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/misspell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ jobs:
uses: reviewdog/action-misspell@v1
with:
github_token: ${{ secrets.github_token }}
exclude: ./src/vendor/**
exclude: |
./src/vendor/**
locale: US
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: v0.181.1
version: v0.182.1
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/service-testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Predefined service testing
name: Service testing

on:
pull_request:
paths:
- predefined-services/**
branches:
- main
- release/**

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17.x

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.x

- name: Prepare environment.env
working-directory: .github/scripts/service-tester
run: pip install -r requirements.txt

- name: Install CCom
run: |
curl -fsSL https://server.chillibits.com/files/repo/gpg | sudo apt-key add -
sudo add-apt-repository "deb https://admin.repo.chillibits.com/repository/ubuntu-$(lsb_release -cs) $(lsb_release -cs) main"
sudo apt-get update
sudo apt-get install ccom
- name: Install CG
run: ./install.sh

- name: Run testing script
working-directory: .github/scripts/service-tester
run: python predefined-service-tester.py
env:
COMPOSE_GENERATOR_CI: 1
4 changes: 2 additions & 2 deletions .github/workflows/service-validation.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Predefined service validation

name: Service validation

on:
Expand All @@ -25,7 +24,8 @@ jobs:
python-version: 3.x

- name: Prepare environment.env
run: pip install -r ./.github/scripts/service-validator/requirements.txt
working-directory: .github/scripts/service-validator
run: pip install -r requirements.txt

- name: Run validation script
working-directory: .github/scripts/service-validator
Expand Down
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Ignore executables
bin/*
bin
compose-generator

# Ignore predefined services archive
predefined-services/*.tar.gz

# Ignore custom templates
templates/*
templates

# Ignore compose-generator output
./docker-compose.yml
Expand All @@ -22,4 +22,7 @@ node_modules/*
.venv/*

# Ignore test directory
test/*
test

# Ignore logs
log

0 comments on commit 8e4005f

Please sign in to comment.