From 36c06cce89158311cdaddee49b6f463b5aea53db Mon Sep 17 00:00:00 2001 From: Ollama Date: Thu, 12 Mar 2026 10:13:21 +0000 Subject: [PATCH] Add multi-arch Docker builds (amd64/arm64), require tests to pass before Docker push --- .github/workflows/README.md | 50 +++++------- .github/workflows/build-release.yml | 120 ++++++++++++++++++---------- .travis.yml | 54 ------------- Dockerfile | 13 --- README.md | 8 +- docker-compose.test.yml | 21 ----- 6 files changed, 101 insertions(+), 165 deletions(-) delete mode 100644 .travis.yml delete mode 100644 docker-compose.test.yml diff --git a/.github/workflows/README.md b/.github/workflows/README.md index 3481f6199..958745bfc 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -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 diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index ce0828328..856e32516 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -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' diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 908983cfd..000000000 --- a/.travis.yml +++ /dev/null @@ -1,54 +0,0 @@ -sudo: required - -branches: - except: - - unstable - - weblate -services: - - docker - -dist: jammy -language: node_js -node_js: - - 20 -script: - - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin - - docker run --rm -u $(id -u) -v $(pwd):/app opensourcepos/composer:ci4 composer install - - version=$(grep application_version app/Config/App.php | sed "s/.*=\s'\(.*\)';/\1/g") - - cp .env.example .env && sed -i 's/production/development/g' .env - - sed -i "s/commit_sha1 = 'dev'/commit_sha1 = '$rev'/g" app/Config/OSPOS.php - - echo "$version-$branch-$rev" - - npm version "$version-$branch-$rev" --force || true - - sed -i 's/opensourcepos.tar.gz/opensourcepos.$version.tgz/g' package.json - - npm ci && npm install -g gulp && npm run build - - docker build . --target ospos -t ospos - - docker build . --target ospos_test -t ospos_test - - docker run --rm ospos_test /app/vendor/bin/phpunit --testdox - - docker build app/Database/ -t "jekkos/opensourcepos:sql-$TAG" -env: - global: - - BRANCH=$(echo ${TRAVIS_BRANCH} | sed s/feature\\///) - - TAG=$(echo "${TRAVIS_TAG:-$BRANCH}" | tr '/' '-') - - date=`date +%Y%m%d%H%M%S` && branch=${TRAVIS_BRANCH} && rev=`git rev-parse --short=6 HEAD` -after_success: - - docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" && docker tag "ospos:latest" - "jekkos/opensourcepos:$TAG" && docker push "jekkos/opensourcepos:$TAG" && docker push "jekkos/opensourcepos:sql-$TAG" - - gulp compress - - mv dist/opensourcepos.tar.gz "dist/opensourcepos.$version.$rev.tgz" - - mv dist/opensourcepos.zip "dist/opensourcepos.$version.$rev.zip" -deploy: - - provider: releases - edge: true - file: dist/opensourcepos.$version.$rev.zip - name: "Unstable OpensourcePos" - overwrite: true - release_notes: "This is a build of the latest master which might contain bugs. Use at your own risk. Check releases section for the latest official release" - prerelease: true - tag_name: unstable - user: jekkos - - api_key: - secure: "KOukL8IFf/uL/BjMyCSKjf2vylydjcWqgEx0eMqFCg3nZ4ybMaOwPORRthIfyT72/FvGX/aoxxEn0uR/AEtb+hYQXHmNS+kZdX72JCe8LpGuZ7FJ5X+Eo9mhJcsmS+smd1sC95DySSc/GolKPo+0WtJYONY/xGCLxm+9Ay4HREg=" - - on: - branch: master diff --git a/Dockerfile b/Dockerfile index 376b0834d..ca1b5a46c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,19 +11,6 @@ COPY . /app RUN ln -s /app/*[^public] /var/www && rm -rf /var/www/html && ln -nsf /app/public /var/www/html RUN chmod -R 770 /app/writable/uploads /app/writable/logs /app/writable/cache && chown -R www-data:www-data /app -FROM ospos AS ospos_test - -COPY --from=composer /usr/bin/composer /usr/bin/composer - -RUN apt-get install -y libzip-dev wget git -RUN wget https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh -O /bin/wait-for-it.sh && chmod +x /bin/wait-for-it.sh -RUN docker-php-ext-install zip -RUN composer install -d/app -#RUN sed -i 's/backupGlobals="true"/backupGlobals="false"/g' /app/tests/phpunit.xml -WORKDIR /app/tests - -CMD ["/app/vendor/phpunit/phpunit/phpunit", "/app/test/helpers"] - FROM ospos AS ospos_dev ARG USERID diff --git a/README.md b/README.md index 755c73f60..97e6a7a3c 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@

-Build Status +Build Status Join the chat at https://app.gitter.im Project Version Translation Status @@ -137,7 +137,7 @@ Any person or company found breaching the license agreement might find a bunch o ## 🙏 Credits -|

DigitalOcean
|
JetBrains
|
Travis CI
| +|
DigitalOcean
|
JetBrains
|
GitHub
| | --- | --- | --- | -|
DigitalOcean Logo
|
IntelliJ IDEA Logo
|
Travis CI Logo
| -| Many thanks to [DigitalOcean](https://www.digitalocean.com) for providing the project with hosting credits. | Many thanks to [JetBrains](https://www.jetbrains.com/) for providing a free license of [IntelliJ IDEA](https://www.jetbrains.com/idea/) to kindly support the development of OSPOS. | Many thanks to [Travis CI](https://www.travis-ci.com/) for providing a free continuous integration service for open source projects. | +|
DigitalOcean Logo
|
IntelliJ IDEA Logo
|
GitHub Actions Logo
| +| Many thanks to [DigitalOcean](https://www.digitalocean.com) for providing the project with hosting credits. | Many thanks to [JetBrains](https://www.jetbrains.com/) for providing a free license of [IntelliJ IDEA](https://www.jetbrains.com/idea/) to kindly support the development of OSPOS. | Many thanks to [GitHub](https://github.com) for providing free continuous integration via GitHub Actions for open source projects. | diff --git a/docker-compose.test.yml b/docker-compose.test.yml deleted file mode 100644 index 4ff0e18fe..000000000 --- a/docker-compose.test.yml +++ /dev/null @@ -1,21 +0,0 @@ -include: - - docker/docker-mysql.yml - -services: - test: - build: - context: . - target: ospos_test - depends_on: - - mysql - container_name: ospos_test - environment: - - CI_ENVIRONMENT=testing - - ENCRYPTION_KEY= - - MYSQL_HOST_NAME=mysql - - MYSQL_DATABASE=ospos - - MYSQL_USERNAME=admin - - MYSQL_PASSWORD=pointofsale - command: [ "/bin/wait-for-it.sh", "mysql:3306", "--", "/app/vendor/bin/phpunit", "/app/tests" ] - ports: - - "80:80"