Skip to content
Merged
2 changes: 1 addition & 1 deletion .github/workflows/auto-approve.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Auto Approve

on:
workflow_run:
workflows: [Tests, Build Docker Image]
workflows: [Tests]
types: [completed]

jobs:
Expand Down
25 changes: 0 additions & 25 deletions .github/workflows/docker.yml

This file was deleted.

122 changes: 70 additions & 52 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,65 +1,83 @@
name: Tests

on:
workflow_dispatch:
push:
branches: [main, develop]
branches:
- main
- develop
pull_request:
branches: [main, develop]

branches:
- main
- develop
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.13', '3.14']

os:
- ubuntu-latest
- macos-latest
- windows-latest
python-version:
- '3.13'
- '3.14'
steps:
- uses: actions/checkout@v5

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"

- name: Run linters
run: |
ruff check src tests
mypy src --ignore-missing-imports

- name: Run tests with coverage
run: |
pytest --cov=src --cov-report=xml --cov-report=term --cov-fail-under=80

- name: Upload coverage reports
uses: codecov/codecov-action@v5
with:
files: ./coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false

- uses: actions/checkout@v5
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Run linters
run: |
ruff check src tests
mypy src --ignore-missing-imports
- name: Run tests with coverage
run: pytest --cov=src --cov-report=xml --cov-report=term --cov-fail-under=80
- name: Upload coverage reports
uses: codecov/codecov-action@v5
with:
files: ./coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5

- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.14'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install bandit safety

- name: Run security checks
run: |
bandit -r src -f json -o bandit-report.json || true
safety check --json || true
- uses: actions/checkout@v5
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.14'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install bandit safety
- name: Run security checks
run: |
bandit -r src -f json -o bandit-report.json || true
safety check --json || true
push-to-gitlab:
name: Push to GitLab
runs-on: ubuntu-latest
needs:
- test
if: always() && needs.test.result == 'success'
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Push to GitLab
env:
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
Comment thread
surrealwolf marked this conversation as resolved.
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git remote add gitlab https://gitlab.com/dk-raas/dkai/high-command/high-command-api.git || true
git config credential.helper '!f() { echo "username=oauth2"; echo "password=${GITLAB_TOKEN}"; }; f'
git fetch gitlab main || true
git push gitlab HEAD:main || echo "GitLab push failed"
39 changes: 39 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
stages:
- build

variables:
HARBOR_REGISTRY: harbor.dataknife.net
HARBOR_PROJECT: library
IMAGE_NAME: high-command-api

docker-build:
stage: build
image: docker:latest
services:
- docker:dind
before_script:
- echo "$HARBOR_PASSWORD" | docker login -u "$HARBOR_USERNAME" --password-stdin $HARBOR_REGISTRY
script:
- |
# Build image once
docker build -t $HARBOR_REGISTRY/$HARBOR_PROJECT/$IMAGE_NAME:latest .

# Tag with commit SHA
docker tag $HARBOR_REGISTRY/$HARBOR_PROJECT/$IMAGE_NAME:latest \
$HARBOR_REGISTRY/$HARBOR_PROJECT/$IMAGE_NAME:$CI_COMMIT_SHORT_SHA

# Push images
docker push $HARBOR_REGISTRY/$HARBOR_PROJECT/$IMAGE_NAME:latest
docker push $HARBOR_REGISTRY/$HARBOR_PROJECT/$IMAGE_NAME:$CI_COMMIT_SHORT_SHA

# Tag with version if tag exists
if [ -n "$CI_COMMIT_TAG" ]; then
docker tag $HARBOR_REGISTRY/$HARBOR_PROJECT/$IMAGE_NAME:latest \
$HARBOR_REGISTRY/$HARBOR_PROJECT/$IMAGE_NAME:$CI_COMMIT_TAG
docker push $HARBOR_REGISTRY/$HARBOR_PROJECT/$IMAGE_NAME:$CI_COMMIT_TAG
fi
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
- if: '$CI_COMMIT_TAG'
tags:
- docker
28 changes: 27 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: help install dev test lint format clean docker-build docker-run run check check-all commit-changes release venv
.PHONY: help install dev test lint format clean docker-build docker-login docker-push docker-pull docker-run run check check-all commit-changes release venv

# Force use of bash shell (required for make to work properly with line continuations)
SHELL := /bin/bash
Expand Down Expand Up @@ -29,6 +29,9 @@ help:
@echo " format Format code with black and ruff"
@echo " clean Remove build artifacts and cache files"
@echo " docker-build Build Docker image"
@echo " docker-login Login to Harbor registry (requires HARBOR_USERNAME and HARBOR_PASSWORD)"
@echo " docker-push Build and push image to Harbor registry"
@echo " docker-pull Pull image from Harbor registry"
@echo " docker-run Run Docker container"
@echo " check Run linters and tests"
@echo " check-all Format, lint, and test (quality gate)"
Expand Down Expand Up @@ -70,8 +73,31 @@ clean:
find . -type d -name "*.egg-info" -exec rm -rf {} + 2>/dev/null || true
rm -rf build dist .pytest_cache .mypy_cache htmlcov .ruff_cache .coverage

HARBOR_REGISTRY := harbor.dataknife.net
HARBOR_IMAGE := $(HARBOR_REGISTRY)/library/$(APP_NAME)
IMAGE_TAG ?= latest

docker-login:
Comment thread
surrealwolf marked this conversation as resolved.
@echo "Logging into Harbor registry..."
@if [ -z "$$HARBOR_USERNAME" ] || [ -z "$$HARBOR_PASSWORD" ]; then \
echo "Error: HARBOR_USERNAME and HARBOR_PASSWORD must be set"; \
exit 1; \
fi
@echo "$$HARBOR_PASSWORD" | docker login $(HARBOR_REGISTRY) \
-u "$$HARBOR_USERNAME" \
--password-stdin

docker-build:
docker build -t $(APP_NAME):latest .
docker tag $(APP_NAME):latest $(HARBOR_IMAGE):$(IMAGE_TAG)

# Ensure we are logged into Harbor before building/tagging and pushing the image.
docker-push: docker-login docker-build
docker push $(HARBOR_IMAGE):$(IMAGE_TAG)

docker-pull:
docker pull $(HARBOR_IMAGE):$(IMAGE_TAG)
docker tag $(HARBOR_IMAGE):$(IMAGE_TAG) $(APP_NAME):latest

docker-run: docker-build
docker run -it --rm -p $(PORT):5000 $(APP_NAME):latest
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3.8'

services:
api:
build: .
image: harbor.dataknife.net/library/high-command-api:latest
Comment thread
surrealwolf marked this conversation as resolved.
ports:
- "5000:5000"
environment:
Expand Down