Skip to content

Merge pull request #25 from Healthcare-Monitoring-System/dev #63

Merge pull request #25 from Healthcare-Monitoring-System/dev

Merge pull request #25 from Healthcare-Monitoring-System/dev #63

Workflow file for this run

name: CI and Docker Image
on:
push:
branches: [dev, main]
tags:
- "v*"
paths-ignore:
- "infra/k8s/**"
pull_request:
branches: [dev, main]
workflow_dispatch:
inputs:
image_tag:
description: "Optional extra image tag, for example 0.1.0"
required: false
type: string
permissions:
contents: write
packages: write
jobs:
quality:
name: Test Python App
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: pip
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
pip install \
--index-url https://download.pytorch.org/whl/cpu \
--extra-index-url https://pypi.org/simple \
"torch==2.5.1+cpu"
pip install -r requirements.txt
pip install -e ".[dev]"
- name: Run tests
env:
PYTEST_DISABLE_PLUGIN_AUTOLOAD: "1"
run: pytest -p pytest_asyncio
docker:
name: Build Docker Image
runs-on: ubuntu-latest
needs: quality
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate image metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/healthcare-monitoring-system/d2-data-intelligence
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=sha,prefix=sha-,format=long
type=ref,event=tag
type=raw,value=${{ inputs.image_tag }},enable=${{ github.event_name == 'workflow_dispatch' && inputs.image_tag != '' }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: ${{ github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')) }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Pin Kubernetes manifests to immutable image tag
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
env:
IMAGE_TAG: sha-${{ github.sha }}
run: |
set -euo pipefail
perl -0pi -e "s#image: ghcr\\.io/healthcare-monitoring-system/d2-data-intelligence:[^\\s]+#image: ghcr.io/healthcare-monitoring-system/d2-data-intelligence:${IMAGE_TAG}#g" \
infra/k8s/base/api-deployment.yaml \
infra/k8s/base/worker-deployment.yaml \
infra/k8s/base/migrate-job.yaml
if git diff --quiet -- infra/k8s/base/api-deployment.yaml infra/k8s/base/worker-deployment.yaml infra/k8s/base/migrate-job.yaml; then
echo "Manifests already use ${IMAGE_TAG}"
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add infra/k8s/base/api-deployment.yaml infra/k8s/base/worker-deployment.yaml infra/k8s/base/migrate-job.yaml
git commit -m "chore: deploy d2 image ${IMAGE_TAG}"
git push