Skip to content

Docker images - Test build #45

Docker images - Test build

Docker images - Test build #45

name: Docker images - Test build
on:
workflow_dispatch:
release:
env:
MAIN_PYTHON_VERSION: '3.10'
ANSRV_GEO_IMAGE_WINDOWS_TAG: ghcr.io/ansys/geometry:windows-latest-tmp
ANSRV_GEO_IMAGE_LINUX_TAG: ghcr.io/ansys/geometry:linux-latest-tmp
ANSRV_GEO_PORT: 700
ANSRV_GEO_LICENSE_SERVER: ${{ secrets.LICENSE_SERVER }}
GEO_CONT_NAME: ans_geo
RESET_IMAGE_CACHE: 1
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# =================================================================================================
# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvv RUNNING ON SELF-HOSTED RUNNER vvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
# =================================================================================================
build-windows:
name: Building Geometry Service - Windows
runs-on: [self-hosted, Windows, pygeometry]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9' # use python3.9, self-hosted has an issue with 3.10
- name: Download Windows binaries
uses: dsaltares/fetch-gh-release-asset@master
with:
version: 'latest'
file: 'windows-binaries.zip'
token: ${{ secrets.GITHUB_TOKEN }}
target: 'docker/windows-binaries.zip'
- name: Build Docker image
working-directory: docker
run: |
docker build -f Dockerfile.windows -t ${{ env.ANSRV_GEO_IMAGE_WINDOWS_TAG }} .
- name: Check location of self-hosted runner and define license server accordingly
if: runner.name == 'pygeometry-ci-1' || runner.name == 'pygeometry-ci-2'
run:
echo "ANSRV_GEO_LICENSE_SERVER=${{ secrets.INTERNAL_LICENSE_SERVER }}" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Launch Geometry service
run: |
docker run --detach --name ${{ env.GEO_CONT_NAME }} -e LICENSE_SERVER=${{ env.ANSRV_GEO_LICENSE_SERVER }} -p ${{ env.ANSRV_GEO_PORT }}:50051 ${{ env.ANSRV_GEO_IMAGE_WINDOWS_TAG }}
- name: Validate connection using PyAnsys Geometry
run: |
python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
pip install -e .[tests]
python -c "from ansys.geometry.core.connection.validate import validate; validate()"
- name: Restore images cache
uses: actions/cache@v3
with:
path: .\tests\integration\image_cache
key: pyvista-image-cache-${{ runner.os }}-v-${{ env.RESET_IMAGE_CACHE }}-${{ hashFiles('pyproject.toml') }}
restore-keys: pyvista-image-cache-${{ runner.os }}-v-${{ env.RESET_IMAGE_CACHE }}
- name: Testing
run: |
.\.venv\Scripts\Activate.ps1
pytest -v --use-existing-service=yes
- name: Stop the Geometry service
if: always()
run: |
docker stop ${{ env.GEO_CONT_NAME }}
docker logs ${{ env.GEO_CONT_NAME }}
docker rm ${{ env.GEO_CONT_NAME }}
- name: Stop any remaining containers
if: always()
run: |
$dockerContainers = docker ps -a -q
if (-not [string]::IsNullOrEmpty($dockerContainers)) {
docker stop $dockerContainers
docker rm $dockerContainers
}
- name: Delete the Docker images (and untagged ones)
if: always()
run: |
docker image rm ${{ env.ANSRV_GEO_IMAGE_WINDOWS_TAG }}
docker system prune -f
# =================================================================================================
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ RUNNING ON SELF-HOSTED RUNNER ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# =================================================================================================
build-linux:
name: Building Geometry Service - Linux
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}
- name: Download Linux binaries
uses: dsaltares/fetch-gh-release-asset@master
with:
version: 'latest'
file: 'linux-binaries.zip'
token: ${{ secrets.GITHUB_TOKEN }}
target: 'docker/linux-binaries.zip'
- name: Build Docker image
working-directory: docker
run: |
docker build -f Dockerfile.linux -t ${{ env.ANSRV_GEO_IMAGE_LINUX_TAG }} .
- name: Launch Geometry service
run: |
docker run --detach --name ${{ env.GEO_CONT_NAME }} -e LICENSE_SERVER=${{ env.ANSRV_GEO_LICENSE_SERVER }} -p ${{ env.ANSRV_GEO_PORT }}:50051 ${{ env.ANSRV_GEO_IMAGE_LINUX_TAG }}
- name: Validate connection using PyAnsys Geometry
run: |
python -m pip install --upgrade pip
pip install -e .[tests]
python -c "from ansys.geometry.core.connection.validate import validate; validate()"
- name: Restore images cache
uses: actions/cache@v3
with:
path: .\tests\integration\image_cache
key: pyvista-image-cache-${{ runner.os }}-v-${{ env.RESET_IMAGE_CACHE }}-${{ hashFiles('pyproject.toml') }}
restore-keys: pyvista-image-cache-${{ runner.os }}-v-${{ env.RESET_IMAGE_CACHE }}
- name: Run pytest
uses: ansys/actions/tests-pytest@v4
env:
ALLOW_PLOTTING: true
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}
pytest-extra-args: "--service-os=linux --use-existing-service=yes"
checkout: false
requires-xvfb: true
- name: Stop the Geometry service
if: always()
run: |
docker stop ${{ env.GEO_CONT_NAME }}
docker logs ${{ env.GEO_CONT_NAME }}
docker rm ${{ env.GEO_CONT_NAME }}