204 lines
6.8 KiB
YAML
204 lines
6.8 KiB
YAML
name: Build and Push Docker Images
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
tags:
|
|
- '*'
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Install system dependencies
|
|
shell: sh
|
|
run: |
|
|
apt-get update && apt-get install -y git python3 python3-pip gcc libpq-dev python3-dev
|
|
|
|
- name: Checkout code
|
|
shell: sh
|
|
run: |
|
|
git clone http://gitea.gitea.svc.cluster.local/${{ gitea.repository }}.git .
|
|
git checkout ${{ gitea.sha }}
|
|
|
|
- name: Install Python dependencies
|
|
shell: sh
|
|
run: |
|
|
pip3 install -r requirements.txt ruff
|
|
|
|
# - name: Run ruff linter
|
|
# shell: sh
|
|
# run: |
|
|
# ruff check SPARC/ tests/
|
|
|
|
- name: Install Node.js and check TypeScript types
|
|
shell: sh
|
|
run: |
|
|
apt-get install -y nodejs npm
|
|
cd frontend
|
|
npm ci
|
|
npm run generate:local
|
|
if ! git diff --quiet src/api/schema.d.ts; then
|
|
echo "ERROR: src/api/schema.d.ts is out of date. Run 'npm run generate:local' and commit the result."
|
|
git diff src/api/schema.d.ts
|
|
exit 1
|
|
fi
|
|
npx tsc --noEmit
|
|
|
|
# - name: Run pytest
|
|
# shell: sh
|
|
# env:
|
|
# DATABASE_URL: "sqlite://"
|
|
# API_KEY: "test-key"
|
|
# OPENROUTER_API_KEY: "test-key"
|
|
# JWT_SECRET: "test-secret-for-ci"
|
|
# APP_ENV: "development"
|
|
# run: |
|
|
# python3 -m pytest tests/ -v --tb=short -x
|
|
|
|
build-api:
|
|
needs: test
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Install dependencies
|
|
shell: sh
|
|
run: |
|
|
apt-get update && apt-get install -y git docker-ce
|
|
|
|
- name: Checkout code
|
|
shell: sh
|
|
run: |
|
|
git clone http://gitea.gitea.svc.cluster.local/${{ gitea.repository }}.git .
|
|
git checkout ${{ gitea.sha }}
|
|
|
|
- name: Determine image tags
|
|
id: tags
|
|
shell: sh
|
|
run: |
|
|
REGISTRY="gitea.gitea.svc.cluster.local:80"
|
|
REPO_OWNER="${{ gitea.repository_owner }}"
|
|
REPO_NAME="${{ gitea.repository }}"
|
|
|
|
REPO_NAME_ONLY=$(echo "$REPO_NAME" | cut -d'/' -f2)
|
|
REPO_OWNER_LOWER=$(echo "$REPO_OWNER" | tr '[:upper:]' '[:lower:]')
|
|
REPO_NAME_LOWER=$(echo "$REPO_NAME_ONLY" | tr '[:upper:]' '[:lower:]')
|
|
|
|
IMAGE_BASE="${REGISTRY}/${REPO_OWNER_LOWER}/${REPO_NAME_LOWER}"
|
|
|
|
case "${{ gitea.ref }}" in
|
|
refs/tags/*)
|
|
TAG_NAME="${{ gitea.ref_name }}"
|
|
echo "IMAGE_TAG=${IMAGE_BASE}:${TAG_NAME}" >> $GITHUB_OUTPUT
|
|
echo "PUSH_LATEST=true" >> $GITHUB_OUTPUT
|
|
;;
|
|
refs/heads/main)
|
|
TIMESTAMP=$(date -u +%Y%m%d%H%M%S)
|
|
SHORT_SHA=$(echo "${{ gitea.sha }}" | cut -c1-7)
|
|
echo "IMAGE_TAG=${IMAGE_BASE}:${TIMESTAMP}-${SHORT_SHA}" >> $GITHUB_OUTPUT
|
|
echo "PUSH_LATEST=true" >> $GITHUB_OUTPUT
|
|
;;
|
|
*)
|
|
BRANCH_TAG=$(echo "${{ gitea.ref_name }}" | sed 's/\//-/g')
|
|
echo "IMAGE_TAG=${IMAGE_BASE}:${BRANCH_TAG}" >> $GITHUB_OUTPUT
|
|
echo "PUSH_LATEST=false" >> $GITHUB_OUTPUT
|
|
;;
|
|
esac
|
|
|
|
echo "IMAGE_LATEST=${IMAGE_BASE}:latest" >> $GITHUB_OUTPUT
|
|
|
|
- name: Login to registry
|
|
shell: sh
|
|
run: |
|
|
echo "${{ secrets.PERSONAL_TOKEN }}" | docker login gitea.gitea.svc.cluster.local:80 -u "${{ gitea.actor }}" --password-stdin
|
|
|
|
- name: Build and push API image
|
|
shell: sh
|
|
run: |
|
|
echo "Building API image..."
|
|
docker build -t ${{ steps.tags.outputs.IMAGE_TAG }} .
|
|
|
|
echo "Pushing API image..."
|
|
docker push ${{ steps.tags.outputs.IMAGE_TAG }}
|
|
|
|
if [ "${{ steps.tags.outputs.PUSH_LATEST }}" = "true" ]; then
|
|
echo "Tagging and pushing latest..."
|
|
docker tag ${{ steps.tags.outputs.IMAGE_TAG }} ${{ steps.tags.outputs.IMAGE_LATEST }}
|
|
docker push ${{ steps.tags.outputs.IMAGE_LATEST }}
|
|
fi
|
|
|
|
echo "API image available at ${{ steps.tags.outputs.IMAGE_TAG }}"
|
|
|
|
build-frontend:
|
|
needs: test
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Install dependencies
|
|
shell: sh
|
|
run: |
|
|
apt-get update && apt-get install -y git docker-ce
|
|
|
|
- name: Checkout code
|
|
shell: sh
|
|
run: |
|
|
git clone http://gitea.gitea.svc.cluster.local/${{ gitea.repository }}.git .
|
|
git checkout ${{ gitea.sha }}
|
|
|
|
- name: Determine image tags
|
|
id: tags
|
|
shell: sh
|
|
run: |
|
|
REGISTRY="gitea.gitea.svc.cluster.local:80"
|
|
REPO_OWNER="${{ gitea.repository_owner }}"
|
|
REPO_NAME="${{ gitea.repository }}"
|
|
|
|
REPO_NAME_ONLY=$(echo "$REPO_NAME" | cut -d'/' -f2)
|
|
REPO_OWNER_LOWER=$(echo "$REPO_OWNER" | tr '[:upper:]' '[:lower:]')
|
|
REPO_NAME_LOWER=$(echo "$REPO_NAME_ONLY" | tr '[:upper:]' '[:lower:]')
|
|
|
|
IMAGE_BASE="${REGISTRY}/${REPO_OWNER_LOWER}/${REPO_NAME_LOWER}"
|
|
|
|
case "${{ gitea.ref }}" in
|
|
refs/tags/*)
|
|
TAG_NAME="${{ gitea.ref_name }}"
|
|
echo "IMAGE_TAG=${IMAGE_BASE}:frontend-${TAG_NAME}" >> $GITHUB_OUTPUT
|
|
echo "PUSH_LATEST=true" >> $GITHUB_OUTPUT
|
|
;;
|
|
refs/heads/main)
|
|
TIMESTAMP=$(date -u +%Y%m%d%H%M%S)
|
|
SHORT_SHA=$(echo "${{ gitea.sha }}" | cut -c1-7)
|
|
echo "IMAGE_TAG=${IMAGE_BASE}:frontend-${TIMESTAMP}-${SHORT_SHA}" >> $GITHUB_OUTPUT
|
|
echo "PUSH_LATEST=true" >> $GITHUB_OUTPUT
|
|
;;
|
|
*)
|
|
BRANCH_TAG=$(echo "${{ gitea.ref_name }}" | sed 's/\//-/g')
|
|
echo "IMAGE_TAG=${IMAGE_BASE}:frontend-${BRANCH_TAG}" >> $GITHUB_OUTPUT
|
|
echo "PUSH_LATEST=false" >> $GITHUB_OUTPUT
|
|
;;
|
|
esac
|
|
|
|
echo "IMAGE_LATEST=${IMAGE_BASE}:frontend-latest" >> $GITHUB_OUTPUT
|
|
|
|
- name: Login to registry
|
|
shell: sh
|
|
run: |
|
|
echo "${{ secrets.PERSONAL_TOKEN }}" | docker login gitea.gitea.svc.cluster.local:80 -u "${{ gitea.actor }}" --password-stdin
|
|
|
|
- name: Build and push frontend image
|
|
shell: sh
|
|
run: |
|
|
echo "Building frontend image..."
|
|
docker build -t ${{ steps.tags.outputs.IMAGE_TAG }} ./frontend
|
|
|
|
echo "Pushing frontend image..."
|
|
docker push ${{ steps.tags.outputs.IMAGE_TAG }}
|
|
|
|
if [ "${{ steps.tags.outputs.PUSH_LATEST }}" = "true" ]; then
|
|
echo "Tagging and pushing frontend-latest..."
|
|
docker tag ${{ steps.tags.outputs.IMAGE_TAG }} ${{ steps.tags.outputs.IMAGE_LATEST }}
|
|
docker push ${{ steps.tags.outputs.IMAGE_LATEST }}
|
|
fi
|
|
|
|
echo "Frontend image available at ${{ steps.tags.outputs.IMAGE_TAG }}"
|