mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-04-02 06:14:51 -04:00
Add multi-arch Docker builds (amd64/arm64), require tests to pass before Docker push
This commit is contained in:
50
.github/workflows/README.md
vendored
50
.github/workflows/README.md
vendored
@@ -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
|
||||
|
||||
|
||||
120
.github/workflows/build-release.yml
vendored
120
.github/workflows/build-release.yml
vendored
@@ -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'
|
||||
|
||||
|
||||
54
.travis.yml
54
.travis.yml
@@ -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
|
||||
13
Dockerfile
13
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
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://app.travis-ci.com/opensourcepos/opensourcepos" target="_blank"><img src="https://api.travis-ci.com/opensourcepos/opensourcepos.svg?branch=master" alt="Build Status"></a>
|
||||
<a href="https://github.com/opensourcepos/opensourcepos/actions/workflows/build-release.yml" target="_blank"><img src="https://github.com/opensourcepos/opensourcepos/actions/workflows/build-release.yml/badge.svg" alt="Build Status"></a>
|
||||
<a href="https://app.gitter.im/#/room/#opensourcepos_Lobby:gitter.im?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge" target="_blank"><img src="https://badges.gitter.im/jekkos/opensourcepos.svg" alt="Join the chat at https://app.gitter.im"></a>
|
||||
<a href="https://badge.fury.io/gh/opensourcepos%2Fopensourcepos" target="_blank"><img src="https://badge.fury.io/gh/opensourcepos%2Fopensourcepos.svg" alt="Project Version"></a>
|
||||
<a href="https://translate.opensourcepos.org/engage/opensourcepos/?utm_source=widget" target="_blank"><img src="https://translate.opensourcepos.org/widgets/opensourcepos/-/svg-badge.svg" alt="Translation Status"></a>
|
||||
@@ -137,7 +137,7 @@ Any person or company found breaching the license agreement might find a bunch o
|
||||
|
||||
## 🙏 Credits
|
||||
|
||||
| <div align="center">DigitalOcean</div> | <div align="center">JetBrains</div> | <div align="center">Travis CI</div> |
|
||||
| <div align="center">DigitalOcean</div> | <div align="center">JetBrains</div> | <div align="center">GitHub</div> |
|
||||
| --- | --- | --- |
|
||||
| <div align="center"><a href="https://www.digitalocean.com?utm_medium=opensource&utm_source=opensourcepos" target="_blank"><img src="https://github.com/user-attachments/assets/fbbf7433-ed35-407d-8946-fd03d236d350" alt="DigitalOcean Logo" height="50"></a></div> | <div align="center"><a href="https://www.jetbrains.com/idea/" target="_blank"><img src="https://github.com/opensourcepos/opensourcepos/assets/12870258/187f9bbe-4484-475c-9b58-5e5d5f931f09" alt="IntelliJ IDEA Logo" height="50"></a></div> | <div align="center"><a href="https://www.travis-ci.com/" target="_blank"><img src="https://github.com/opensourcepos/opensourcepos/assets/12870258/71cc2b44-83af-4510-a543-6358285f43c6" alt="Travis CI Logo" height="50"></a></div> |
|
||||
| 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. |
|
||||
| <div align="center"><a href="https://www.digitalocean.com?utm_medium=opensource&utm_source=opensourcepos" target="_blank"><img src="https://github.com/user-attachments/assets/fbbf7433-ed35-407d-8946-fd03d236d350" alt="DigitalOcean Logo" height="50"></a></div> | <div align="center"><a href="https://www.jetbrains.com/idea/" target="_blank"><img src="https://github.com/opensourcepos/opensourcepos/assets/12870258/187f9bbe-4484-475c-9b58-5e5d5f931f09" alt="IntelliJ IDEA Logo" height="50"></a></div> | <div align="center"><a href="https://github.com/features/actions" target="_blank"><img src="https://github.githubassets.com/images/modules/site/icons/eyebrow-panel/actions-icon.svg" alt="GitHub Actions Logo" height="50"></a></div> |
|
||||
| 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. |
|
||||
|
||||
@@ -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"
|
||||
Reference in New Issue
Block a user