Skip to content

Commit

Permalink
add cicd
Browse files Browse the repository at this point in the history
  • Loading branch information
petercrocker committed Oct 30, 2024
1 parent d87a882 commit 22f0646
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 3 deletions.
13 changes: 13 additions & 0 deletions .github/file-filters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
ci_config: &ci_config
- ".github/workflows/ci.yml"
- ".github/file-filters.yml"

github_workflows: &github_workflows
- ".github/workflows/*.yml"

yaml_all: &yaml_all
- "**/*.{yml,yaml}"

markdown_all: &markdown_all
- "**/*.{md,mdx}"
114 changes: 114 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
---
# yamllint disable rule:truthy rule:truthy rule:line-length
name: "CI"
on:
pull_request:
push:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}

jobs:
files-changed:
name: Detect which file has changed
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
yaml: ${{ steps.changes.outputs.yaml_all }}
steps:
- name: "Check out repository code"
uses: "actions/checkout@v4"
- name: Check for file changes
uses: dorny/paths-filter@v3
id: changes
with:
token: ${{ github.token }}
filters: .github/file-filters.yml

yaml-lint:
if: needs.files-changed.outputs.yaml == 'true'
needs: ["files-changed"]
runs-on: "ubuntu-latest"
timeout-minutes: 5
steps:
- name: "Check out repository code"
uses: "actions/checkout@v4"
- name: "Setup environment"
run: "pip install yamllint==1.35.1"
- name: "Linting: yamllint"
run: "yamllint -s ."

E2E-testing-invoke-start:
needs:
- files-changed
- yaml-lint
if: |
always() && !cancelled() &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled')
runs-on:
group: huge-runners
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
submodules: true

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install Invoke
run: |
pip install toml invoke
- name: Set job name
run: echo JOB_NAME="$GITHUB_JOB" >> $GITHUB_ENV

- name: "Set environment variables"
run: echo INFRAHUB_BUILD_NAME=infrahub-${{ runner.name }} >> $GITHUB_ENV
- name: "Clear docker environment"
run: docker compose -p $INFRAHUB_BUILD_NAME down -v --remove-orphans --rmi local

- name: "Store start time"
run: echo TEST_START_TIME=$(date +%s)000 >> $GITHUB_ENV

- name: Run 'invoke start'
run: |
unset INFRAHUB_IMAGE_VER
invoke start load_schema
- name: Display server logs
if: always()
run: docker logs "${INFRAHUB_BUILD_NAME}-server-1"

- name: Display task worker 1 logs
if: always()
run: docker logs "${INFRAHUB_BUILD_NAME}-infrahub-git-1"

- name: Display task worker 2 logs
if: always()
run: docker logs "${INFRAHUB_BUILD_NAME}-infrahub-git-2"

- name: Display task manager logs
if: always()
run: docker logs "${INFRAHUB_BUILD_NAME}-task-manager-1"

- name: Display database logs
if: always()
run: docker logs "${INFRAHUB_BUILD_NAME}-database-1"

- name: Display message-queue logs
if: always()
run: docker logs "${INFRAHUB_BUILD_NAME}-message-queue-1"

- name: "Clear docker environment and force vmagent to stop"
if: always()
run: docker compose -p $INFRAHUB_BUILD_NAME down -v --remove-orphans --rmi local
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Schema Library
# Infrahub Schema Library

Welcome to the Schema Library for Infrahub! This repository offers a collection of schemas designed to streamline and standardize infrastructure-related data structures.

Expand All @@ -20,7 +20,7 @@ There are several ways to [load a schema in Infrahub](https://docs.infrahub.app/
This project is divided into three main parts:

- Base: This is the foundational layer required for any extension. It must be loaded before adding extensions.
- Extension: Designed to be simple and generic, this section offers various schema components for managing infrastructure. Note that extensions may have dependencies on each other.
- Extensions: Designed to be simple and generic, this section offers various schema components for managing infrastructure. Note that extensions may have dependencies on each other.
- Experimental: This section contains schema components that are not yet fully supported.

## Contributing
Expand Down
2 changes: 1 addition & 1 deletion experimental/peering/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# IX schema extension

This schema extension contains all you need to modelize anything revolving around internet peering (Exchange points ...)!
This schema extension contains all you need to model anything revolving around internet peering (Exchange points ...)!

## Nodes

Expand Down
33 changes: 33 additions & 0 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os

from pathlib import Path

from invoke import task, Context # type: ignore

# If no version is indicated, we will take the latest
VERSION = os.getenv("INFRAHUB_VERSION", None)
COMPOSE_COMMAND = f"curl https://infrahub.opsmill.io/{VERSION if VERSION else ''} | docker compose -f -"

@task
def start(context: Context) -> None:
context.run(f"{COMPOSE_COMMAND} up -d")

@task
def load_schema(context: Context, schema: Path=Path("./base/*.yml")) -> None:
context.run(f"infrahubctl schema load {schema}")

@task
def destroy(context: Context) -> None:
context.run(f"{COMPOSE_COMMAND} down -v")

@task
def stop(context: Context) -> None:
context.run(f"{COMPOSE_COMMAND} down")

@task
def restart(context: Context, component: str="")-> None:
if component:
context.run(f"{COMPOSE_COMMAND} restart {component}")
return

context.run(f"{COMPOSE_COMMAND} restart")

0 comments on commit 22f0646

Please sign in to comment.