mirror of
https://github.com/lklynet/hypermind.git
synced 2026-05-04 01:50:33 +00:00
129 lines
3.6 KiB
YAML
129 lines
3.6 KiB
YAML
name: Build
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
push-to-registry:
|
|
description: "Whether to push images to the container registry"
|
|
required: false
|
|
default: false
|
|
type: boolean
|
|
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ${{ matrix.runner }}
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- platform: linux/amd64
|
|
arch: amd64
|
|
runner: ubuntu-latest
|
|
test: true
|
|
- platform: linux/arm64
|
|
arch: arm64
|
|
runner: ubuntu-24.04-arm
|
|
test: true
|
|
- platform: linux/arm/v7
|
|
arch: armv7
|
|
runner: ubuntu-24.04-arm
|
|
test: false
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to the Container registry
|
|
if: inputs.push-to-registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Extract metadata (tags, labels) for Docker
|
|
if: inputs.push-to-registry
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
|
|
- name: Build Docker image
|
|
id: build
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
platforms: ${{ matrix.platform }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
load: ${{ matrix.test }}
|
|
tags: hypermind-test:${{ github.sha }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
- name: Run container for testing
|
|
if: matrix.test
|
|
run: docker run -d --name hypermind-test -p 3000:3000 hypermind-test:${{ github.sha }}
|
|
|
|
- name: Wait for server to be ready
|
|
if: matrix.test
|
|
run: |
|
|
for i in {1..30}; do
|
|
if curl -sf http://localhost:3000/api/stats; then
|
|
echo "Server is ready"
|
|
exit 0
|
|
fi
|
|
echo "Waiting for server... ($i/30)"
|
|
sleep 1
|
|
done
|
|
echo "Server failed to start"
|
|
docker logs hypermind-test
|
|
exit 1
|
|
|
|
- name: Verify API response
|
|
if: matrix.test
|
|
run: |
|
|
response=$(curl -sf http://localhost:3000/api/stats)
|
|
echo "Response: $response"
|
|
echo "$response" | jq -e '.count != null and .id != null'
|
|
|
|
- name: Cleanup test container
|
|
if: always() && matrix.test
|
|
run: docker rm -f hypermind-test || true
|
|
|
|
- name: Push by digest
|
|
if: inputs.push-to-registry
|
|
id: push
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
platforms: ${{ matrix.platform }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
|
|
cache-from: type=gha
|
|
|
|
- name: Export digest
|
|
if: inputs.push-to-registry
|
|
run: |
|
|
mkdir -p ${{ runner.temp }}/digests
|
|
digest="${{ steps.push.outputs.digest }}"
|
|
touch "${{ runner.temp }}/digests/${digest#sha256:}"
|
|
|
|
- name: Upload digest
|
|
if: inputs.push-to-registry
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: digests-${{ matrix.arch }}
|
|
path: ${{ runner.temp }}/digests/*
|
|
if-no-files-found: error
|
|
retention-days: 1
|