Add multi-arch Docker builds (amd64/arm64), require tests to pass before Docker push

This commit is contained in:
Ollama
2026-03-12 10:13:21 +00:00
parent ff97919c98
commit 36c06cce89
6 changed files with 101 additions and 165 deletions

View File

@@ -1,32 +1,26 @@
# GitHub Actions Migration
# GitHub Actions
This document describes the migration from Travis CI to GitHub Actions.
This document describes the CI/CD workflows for OSPOS.
## What was migrated
## Build and Release Workflow (`.github/workflows/build-release.yml`)
The following Travis CI functionality has been converted to GitHub Actions:
### Build Process
- Setup PHP 8.2 with required extensions
- Setup Node.js 20
- Install composer dependencies
- Install npm dependencies
- Build frontend assets with Gulp
### Build and Test Workflow (`.github/workflows/build-release.yml`)
### Testing
- Run PHPUnit tests with MariaDB service container
1. **Build Process**
- Setup PHP 8.2 with required extensions
- Setup Node.js 20
- Install composer dependencies
- Install npm dependencies
- Build frontend assets with Gulp
### Docker Images
- Build `ospos:latest` Docker image for multiple architectures (linux/amd64, linux/arm64)
- Push to Docker Hub on master branch
2. **Testing**
- Run PHPUnit tests with MariaDB container
- Run Docker container tests
3. **Docker Images**
- Build `ospos:latest` Docker image
- Build `ospos_test:latest` Docker image
- Push to Docker Hub on master branch
4. **Releases**
- Create distribution archives (tar.gz, zip)
- Create/update GitHub "unstable" release on master
### Releases
- Create distribution archives (tar.gz, zip)
- Create/update GitHub "unstable" release on master
## Required Secrets
@@ -50,19 +44,11 @@ The `GITHUB_TOKEN` is automatically provided by GitHub Actions.
- **Push tags** - Runs build and test
- **Pull requests** - Runs build and test only
## Differences from Travis CI
1. **No SQL Docker image** - The Travis build created a `jekkos/opensourcepos:sql-$TAG` image. This workflow focuses on the main application image. If needed, a separate job can be added.
2. **Branch filtering** - GitHub Actions uses workflow triggers instead of Travis's `branches.except`
3. **Concurrency** - Added concurrency group to cancel in-progress runs on the same branch
## Existing Workflows
This repository also has these workflows:
- `.github/workflows/main.yml` - PHP linting with PHP-CS-Fixer
- `.github/workflows/phpunit.yml` - PHPUnit tests (already existed)
- `.github/workflows/phpunit.yml` - PHPUnit tests
- `.github/workflows/php-linter.yml` - PHP linting
- `.github/workflows/codeql-analysis.yml` - Security analysis

View File

@@ -20,12 +20,13 @@ permissions:
jobs:
build:
name: Build and Test
name: Build
runs-on: ubuntu-22.04
outputs:
version: ${{ steps.version.outputs.version }}
version-tag: ${{ steps.version.outputs.version-tag }}
short-sha: ${{ steps.version.outputs.short-sha }}
steps:
- name: Checkout
@@ -103,34 +104,6 @@ jobs:
- name: Build frontend assets
run: npm run build
- name: Run PHPUnit tests
run: |
cp .env.example .env
docker run -d --name mysql \
-e MYSQL_ROOT_PASSWORD=root \
-e MYSQL_DATABASE=ospos \
-e MYSQL_USER=admin \
-e MYSQL_PASSWORD=pointofsale \
-p 3306:3306 \
mariadb:10.5
# Wait for MariaDB
until docker exec mysql mysqladmin ping -h 127.0.0.1 -u root -proot --silent; do
echo "Waiting for MariaDB..."
sleep 2
done
# Initialize database
docker exec -i mysql mysql -u root -proot ospos < app/Database/database.sql || true
# Run tests
vendor/bin/phpunit --testdox || true
docker stop mysql && docker rm mysql
- name: Build Docker image
run: docker build . --target ospos -t ospos:latest
- name: Create distribution archives
run: |
gulp compress
@@ -147,27 +120,92 @@ jobs:
path: dist/
retention-days: 7
- name: Upload build context for Docker
uses: actions/upload-artifact@v4
with:
name: build-context-${{ steps.version.outputs.short-sha }}
path: |
.
!.git
!node_modules
retention-days: 1
test:
name: PHPUnit Tests
runs-on: ubuntu-22.04
needs: build
steps:
- name: Download build context
uses: actions/download-artifact@v4
with:
name: build-context-${{ needs.build.outputs.short-sha }}
path: .
- name: Start MariaDB
run: |
docker run -d --name mysql \
-e MYSQL_ROOT_PASSWORD=root \
-e MYSQL_DATABASE=ospos \
-e MYSQL_USER=admin \
-e MYSQL_PASSWORD=pointofsale \
-p 3306:3306 \
mariadb:10.5
until docker exec mysql mysqladmin ping -h 127.0.0.1 -u root -proot --silent; do
echo "Waiting for MariaDB..."
sleep 2
done
- name: Initialize database
run: docker exec -i mysql mysql -u root -proot ospos < app/Database/database.sql || true
- name: Run PHPUnit tests
run: vendor/bin/phpunit --testdox
- name: Stop MariaDB
if: always()
run: docker stop mysql && docker rm mysql
docker:
name: Build Docker Image
runs-on: ubuntu-22.04
needs: [build, test]
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- name: Download build context
uses: actions/download-artifact@v4
with:
name: build-context-${{ needs.build.outputs.short-sha }}
path: .
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Push Docker images
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
run: |
TAG="${{ steps.version.outputs.version-tag }}"
docker tag ospos:latest jekkos/opensourcepos:$TAG
docker push jekkos/opensourcepos:$TAG
# Also push latest tag for master
docker tag ospos:latest jekkos/opensourcepos:latest
docker push jekkos/opensourcepos:latest
- name: Build and push Docker images
uses: docker/build-push-action@v5
with:
context: .
target: ospos
platforms: linux/amd64,linux/arm64
push: true
tags: |
jekkos/opensourcepos:${{ needs.build.outputs.version-tag }}
jekkos/opensourcepos:latest
release:
name: Create Release
needs: build
needs: [build, test]
runs-on: ubuntu-22.04
if: github.event_name == 'push' && github.ref == 'refs/heads/master'