diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index b7469e05e2..8db8d6be22 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -12,7 +12,8 @@ env: LIBRARY_NAME: 'ansys-stk-core' LIBRARY_NAMESPACE: 'ansys.stk.core' DOCUMENTATION_CNAME: 'stk.docs.pyansys.com' - + STK_DOCKER_IMAGE: 'ansys/stk:latest-centos7' + LICENSE_SERVER_PORT: '1055' concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -30,7 +31,7 @@ jobs: python-version: ${{ env.MAIN_PYTHON_VERSION }} doc-style: - name: "Documentation style checks" + name: "Doc style checks" runs-on: ubuntu-latest steps: - name: "Run code style checks" @@ -39,7 +40,7 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} doc-build: - name: "Build project documentation" + name: "Doc build" runs-on: ubuntu-latest needs: doc-style steps: @@ -48,92 +49,68 @@ jobs: with: python-version: ${{ env.MAIN_PYTHON_VERSION }} - doc-deploy-dev: - name: "Deploy developers documentation" - runs-on: ubuntu-latest - if: github.event_name == 'push' && contains(github.ref, 'refs/heads/main') - needs: doc-build - steps: - - name: "Deploy development documentation" - uses: pyansys/actions/doc-deploy-dev@v4 - with: - cname: ${{ env.DOCUMENTATION_CNAME }} - token: ${{ secrets.GITHUB_TOKEN }} - - doc-deploy-stable: - name: "Deploy stable documentation" - runs-on: ubuntu-latest - if: github.event_name == 'push' && contains(github.ref, 'refs/tags') - needs: doc-deploy-dev - steps: - - name: "Deploy stable documentation" - uses: pyansys/actions/doc-deploy-stable@v4 - with: - cname: ${{ env.DOCUMENTATION_CNAME }} - token: ${{ secrets.GITHUB_TOKEN }} - tests: - name: "Test Python ${{ matrix.cfg.python-version }} in ${{ matrix.os }} " - runs-on: ${{ matrix.os }} - needs: code-style + name: "Tests Python ${{ matrix.python }}" + runs-on: [self-hosted, pystk] + # needs: code-style strategy: matrix: - os: [windows-latest, ubuntu-latest] - cfg: - - {python-version: '3.7', extra-args: ''} - - {python-version: '3.8', extra-args: ''} - - {python-version: '3.9', extra-args: ''} - - {python-version: '3.10', extra-args: '--cov=ansys.stk --cov-report=term --cov-report=html:.cov/html'} - + python: ["3.8", "3.9", "3.10"] fail-fast: false steps: - - name: "Run test suite with pytest" - uses: pyansys/actions/tests-pytest@v4 - with: - python-version: ${{ matrix.cfg.python-version }} - pytest-extra-args: ${{ matrix.cfg.extra-args }} - - - name: "Upload coverage results" - uses: actions/upload-artifact@v3 - if: matrix.cfg.python-version == env.MAIN_PYTHON_VERSION && matrix.os == 'ubuntu-latest' - with: - name: coverage-html - path: .cov/html - retention-days: 7 + - name: "Checkout the project" + uses: actions/checkout@v3 + + - name: "Generate the name of the docker image and the container" + run: | + python_image_name=${{ env.STK_DOCKER_IMAGE }}-python${{ matrix.python }} + container_name=stk-python${{ matrix.python }} + echo "STK_PYTHON_IMAGE=$python_image_name" >> $GITHUB_ENV + echo "STK_CONTAINER=$container_name" >> $GITHUB_ENV + + - name: "Start the container from the desired image" + run: | + docker run \ + --detach -it \ + --name ${{ env.STK_CONTAINER }} \ + --env ANSYSLMD_LICENSE_FILE=${{ env.LICENSE_SERVER_PORT }}@${{ secrets.LICENSE_SERVER }} \ + --volume ${PWD}:/home/stk/pystk \ + ${{ env.STK_PYTHON_IMAGE }} + + - name: "Install the project" + run: | + docker exec ${{ env.STK_CONTAINER }} /bin/bash -c \ + "python -m pip install /home/stk/pystk" + + - name: "Show the version of the engine" + run: | + docker exec ${{ env.STK_CONTAINER }} /bin/bash -c \ + "python -c 'from ansys.stk.core.stkengine import STKEngine; print(STKEngine.StartApplication().Version)'" + + - name: "Stop the container" + if: always() + run: | + docker stop ${{ env.STK_CONTAINER }} + docker logs ${{ env.STK_CONTAINER }} + docker rm ${{ env.STK_CONTAINER }} build-library: - name: "Build library artifacts" + name: "Build library" runs-on: ubuntu-latest - needs: [doc-deploy-stable, tests] + needs: [doc-build, tests] steps: - - name: "Build library source and wheel artifacts" - uses: pyansys/actions/build-library@v4 + - uses: pyansys/actions/build-library@v4 with: library-name: ${{ env.LIBRARY_NAME }} - # release: - # name: "Release to private and public PyPI and to GitHub" - # if: github.event_name == 'push' && contains(github.ref, 'refs/tags') - # runs-on: ubuntu-latest - # needs: [build-library] - # steps: - - # - name: "Release to the private PyPI repository" - # uses: pyansys/actions/release-pypi-private@v1 - # with: - # library-name: ${{ env.LIBRARY_NAME }} - # twine-username: "__token__" - # twine-token: ${{ secrets.PYANSYS_PYPI_PRIVATE_PAT }} - - # - name: "Release to the public PyPI repository" - # uses: pyansys/actions/release-pypi-public@main - # with: - # library-name: ${{ env.LIBRARY_NAME }} - # twine-username: "__token__" - # twine-token: ${{ secrets.PYPI_TOKEN }} - - # - name: "Release to GitHub" - # uses: pyansys/actions/release-github@main - # with: - # library-name: ${{ env.LIBRARY_NAME }} + doc-deploy-dev: + name: "Deploy dev docs" + runs-on: ubuntu-latest + needs: build-library + if: github.event_name == 'push' && contains(github.ref, 'refs/heads/main') + steps: + - uses: pyansys/actions/doc-deploy-dev@v4 + with: + cname: ${{ env.DOCUMENTATION_CNAME }} + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 852dd37586..4d65aa93bc 100644 --- a/.gitignore +++ b/.gitignore @@ -157,3 +157,6 @@ cython_debug/ #.idea/ # End of https://www.toptal.com/developers/gitignore/api/python + +# Ignore any distributions directory to prevent accidental publications +distributions/ diff --git a/docker/linux/docker-compose.yml b/docker/linux/docker-compose.yml new file mode 100644 index 0000000000..d24b42934c --- /dev/null +++ b/docker/linux/docker-compose.yml @@ -0,0 +1,63 @@ +version: '3.8' +services: + + stk: + image: ansys/stk:latest-centos7 + container_name: stk + build: + context: ./stk-engine + args: + baseImage: centos:7 + environment: + - ANSYSLMD_LICENSE_FILE=$ANSYSLMD_LICENSE_FILE + + stk-pybase: + image: ansys/stk:latest-centos7-pybase + depends_on: + - stk + container_name: stk-pybase + build: + context: ./stk-engine-pybase + args: + baseImage: ansys/stk:latest-centos7 + environment: + - ANSYSLMD_LICENSE_FILE=$ANSYSLMD_LICENSE_FILE + + stk-python3.8: + image: ansys/stk:latest-centos7-python3.8 + depends_on: + - stk-pybase + container_name: stk-python3.8 + build: + context: ./stk-engine-py38 + args: + baseImage: ansys/stk:latest-centos7 + basePythonImage: ansys/stk:latest-centos7-pybase + environment: + - ANSYSLMD_LICENSE_FILE=$ANSYSLMD_LICENSE_FILE + + stk-python3.9: + image: ansys/stk:latest-centos7-python3.9 + depends_on: + - stk-pybase + container_name: stk-python3.9 + build: + context: ./stk-engine-py39 + args: + baseImage: ansys/stk:latest-centos7 + basePythonImage: ansys/stk:latest-centos7-pybase + environment: + - ANSYSLMD_LICENSE_FILE=$ANSYSLMD_LICENSE_FILE + + stk-python3.10: + image: ansys/stk:latest-centos7-python3.10 + depends_on: + - stk-pybase + container_name: stk-python3.10 + build: + context: ./stk-engine-py310 + args: + baseImage: ansys/stk:latest-centos7 + basePythonImage: ansys/stk:latest-centos7-pybase + environment: + - ANSYSLMD_LICENSE_FILE=$ANSYSLMD_LICENSE_FILE diff --git a/docker/linux/stk-engine-py310/Dockerfile b/docker/linux/stk-engine-py310/Dockerfile new file mode 100644 index 0000000000..701ab26686 --- /dev/null +++ b/docker/linux/stk-engine-py310/Dockerfile @@ -0,0 +1,44 @@ +# By default, start from the base STK Engine Python image +ARG baseImage=ansys/stk:latest-centos7 +ARG basePythonImage=ansys/stk:latest-centos7-pybase +FROM ${basePythonImage} as builder + +############################################## +# 1) Build Python into its own builder stage +############################################## + +# Install Python 3.10 and create a symbolic link named "python". +# This overrides the default Python 2.7 in CentOS7. +USER root +RUN cd /tmp && \ + wget https://www.python.org/ftp/python/3.10.10/Python-3.10.10.tgz && \ + tar xzf Python-3.10.10.tgz && \ + cd Python-3.10.10 && \ + ./configure --enable-optimizations && \ + make altinstall + +############################################################# +# 2) Copy the Python build to the system in the second stage +############################################################# + +# Switch back to non-root user +FROM ${baseImage} +USER root + +# Copy the Python interpreter, the standard library and pip to the final image +COPY --from=builder /usr/local/bin/python3.10 /usr/local/bin/python3.10 +COPY --from=builder /usr/local/lib/python3.10 /usr/local/lib/python3.10 +COPY --from=builder /usr/local/bin/pip3.10 /usr/local/bin/pip3.10 + +RUN ln -sfn /usr/local/bin/python3.10 /usr/bin/python && \ + ln -sfn /usr/local/bin/pip3.10 /usr/bin/pip + +# Switch back to non-root user +USER stk + +# Update the path to include Python executables +ENV PATH="${STK_USER_HOME}/.local/bin:${PATH}" \ + PIP_DEFAULT_TIMEOUT=600 \ + PIP_RETRY=50 + +ENTRYPOINT [ "python3.10" ] diff --git a/docker/linux/stk-engine-py310/docker-compose.yml b/docker/linux/stk-engine-py310/docker-compose.yml new file mode 100644 index 0000000000..d227e6d29e --- /dev/null +++ b/docker/linux/stk-engine-py310/docker-compose.yml @@ -0,0 +1,12 @@ +version: '3.8' +services: + stk-python3.10: + image: ansys/stk:latest-centos7-python3.10 + container_name: stk-python3.10 + build: + context: . + args: + baseImage: ansys/stk:latest-centos7 + basePythonImage: ansys/stk:latest-centos7-pybase + environment: + - ANSYSLMD_LICENSE_FILE=$ANSYSLMD_LICENSE_FILE diff --git a/docker/linux/stk-engine-py38/Dockerfile b/docker/linux/stk-engine-py38/Dockerfile new file mode 100644 index 0000000000..7683260251 --- /dev/null +++ b/docker/linux/stk-engine-py38/Dockerfile @@ -0,0 +1,44 @@ +# By default, start from the base STK Engine Python image +ARG baseImage=ansys/stk:latest-centos7 +ARG basePythonImage=ansys/stk:latest-centos7-pybase +FROM ${basePythonImage} as builder + +############################################## +# 1) Build Python into its own builder stage +############################################## + +# Install Python 3.8 and create a symbolic link named "python". +# This overrides the default Python 2.7 in CentOS7. +USER root +RUN cd /tmp && \ + wget https://www.python.org/ftp/python/3.8.16/Python-3.8.16.tgz && \ + tar xzf Python-3.8.16.tgz && \ + cd Python-3.8.16 && \ + ./configure --enable-optimizations && \ + make altinstall + +############################################################# +# 2) Copy the Python build to the system in the second stage +############################################################# + +# Switch back to non-root user +FROM ${baseImage} +USER root + +# Copy the Python interpreter, the standard library and pip to the final image +COPY --from=builder /usr/local/bin/python3.8 /usr/local/bin/python3.8 +COPY --from=builder /usr/local/lib/python3.8 /usr/local/lib/python3.8 +COPY --from=builder /usr/local/bin/pip3.8 /usr/local/bin/pip3.8 + +RUN ln -sfn /usr/local/bin/python3.8 /usr/bin/python && \ + ln -sfn /usr/local/bin/pip3.8 /usr/bin/pip + +# Switch back to non-root user +USER stk + +# Update the path to include Python executables +ENV PATH="${STK_USER_HOME}/.local/bin:${PATH}" \ + PIP_DEFAULT_TIMEOUT=600 \ + PIP_RETRY=50 + +ENTRYPOINT [ "python3.8" ] diff --git a/docker/linux/stk-engine-py38/docker-compose.yml b/docker/linux/stk-engine-py38/docker-compose.yml new file mode 100644 index 0000000000..bea1591982 --- /dev/null +++ b/docker/linux/stk-engine-py38/docker-compose.yml @@ -0,0 +1,14 @@ +version: '3.8' +services: + stk-python3.8: + image: ansys/stk:latest-centos7-python3.8 + container_name: stk-python3.8 + build: + context: . + args: + baseImage: ansys/stk:latest-centos7 + basePythonImage: ansys/stk:latest-centos7-pybase + environment: + - ANSYSLMD_LICENSE_FILE=$ANSYSLMD_LICENSE_FILE + environment: + - ANSYSLMD_LICENSE_FILE=$ANSYSLMD_LICENSE_FILE diff --git a/docker/linux/stk-engine-py39/Dockerfile b/docker/linux/stk-engine-py39/Dockerfile new file mode 100644 index 0000000000..6cd5d05eb1 --- /dev/null +++ b/docker/linux/stk-engine-py39/Dockerfile @@ -0,0 +1,44 @@ +# By default, start from the base STK Engine Python image +ARG baseImage=ansys/stk:latest-centos7 +ARG basePythonImage=ansys/stk:latest-centos7-pybase +FROM ${basePythonImage} as builder + +############################################## +# 1) Build Python into its own builder stage +############################################## + +# Install Python 3.9 and create a symbolic link named "python". +# This overrides the default Python 2.7 in CentOS7. +USER root +RUN cd /tmp && \ + wget https://www.python.org/ftp/python/3.9.16/Python-3.9.16.tgz && \ + tar xzf Python-3.9.16.tgz && \ + cd Python-3.9.16 && \ + ./configure --enable-optimizations && \ + make altinstall + +############################################################# +# 2) Copy the Python build to the system in the second stage +############################################################# + +# Switch back to non-root user +FROM ${baseImage} +USER root + +# Copy the Python interpreter, the standard library and pip to the final image +COPY --from=builder /usr/local/bin/python3.9 /usr/local/bin/python3.9 +COPY --from=builder /usr/local/lib/python3.9 /usr/local/lib/python3.9 +COPY --from=builder /usr/local/bin/pip3.9 /usr/local/bin/pip3.9 + +RUN ln -sfn /usr/local/bin/python3.9 /usr/bin/python && \ + ln -sfn /usr/local/bin/pip3.9 /usr/bin/pip + +# Switch back to non-root user +USER stk + +# Update the path to include Python executables +ENV PATH="${STK_USER_HOME}/.local/bin:${PATH}" \ + PIP_DEFAULT_TIMEOUT=600 \ + PIP_RETRY=50 + +ENTRYPOINT [ "python3.9" ] diff --git a/docker/linux/stk-engine-py39/docker-compose.yml b/docker/linux/stk-engine-py39/docker-compose.yml new file mode 100644 index 0000000000..f0e3cf865f --- /dev/null +++ b/docker/linux/stk-engine-py39/docker-compose.yml @@ -0,0 +1,12 @@ +version: '3.8' +services: + stk-python3.9: + image: ansys/stk:latest-centos7-python3.9 + container_name: stk-python3.9 + build: + context: . + args: + baseImage: ansys/stk:latest-centos7 + basePythonImage: ansys/stk:latest-centos7-pybase + environment: + - ANSYSLMD_LICENSE_FILE=$ANSYSLMD_LICENSE_FILE diff --git a/docker/linux/stk-engine-pybase/Dockerfile b/docker/linux/stk-engine-pybase/Dockerfile new file mode 100644 index 0000000000..4579426710 --- /dev/null +++ b/docker/linux/stk-engine-pybase/Dockerfile @@ -0,0 +1,36 @@ +# By default, start from the base STK Engine image +ARG baseImage=ansys/stk:latest-centos7 +FROM ${baseImage} + +# Install system dependencies +USER root +RUN set -e; \ + + # Install basic development utilities + yum groupinstall -y development; \ + yum -y install gcc make tar wget; \ + + # Install OpenSSL 1.1 dependencies + yum -y install perl-core pcre-devel; \ + + # Install required dependencies for Python 3.X + yum -y install bzip2-devel libffi-devel tk-devel; \ + yum -y install zlib-devel ncurses-devel sqlite-devel; \ + yum -y install readline-devel gdbm-devel db4-devel libpcap-devel xz-devel; \ + + # Clean all unnecessary files + yum clean all; \ + rm -rf /var/cache/yum + +# Install OpenSSL 1.1 +RUN set -e; \ + wget --no-check-certificate https://ftp.openssl.org/source/openssl-1.1.1k.tar.gz; \ + tar -xzvf openssl-1.1.1k.tar.gz; \ + cd openssl-1.1.1k; \ + ./config --prefix=/usr --openssldir=/etc/ssl --libdir=lib no-shared zlib-dynamic; \ + make && make install; \ + echo "export LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64:${LD_LIBRARY_PATH}" > /etc/profile.d/openssl.sh; \ + echo "export LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64:${LD_LIBRARY_PATH}" >> .bashrc + + +CMD echo 'Extend this container by installing Python.' diff --git a/docker/linux/stk-engine-pybase/docker-compose.yml b/docker/linux/stk-engine-pybase/docker-compose.yml new file mode 100644 index 0000000000..eb6396bfc5 --- /dev/null +++ b/docker/linux/stk-engine-pybase/docker-compose.yml @@ -0,0 +1,11 @@ +version: '3.8' +services: + stk-python-common: + image: ansys/stk:latest-centos7-python-common + container_name: stk-python-common + build: + context: . + args: + baseImage: ansys/stk:latest-centos7 + environment: + - ANSYSLMD_LICENSE_FILE=$ANSYSLMD_LICENSE_FILE diff --git a/docker/linux/stk-engine/Dockerfile b/docker/linux/stk-engine/Dockerfile new file mode 100644 index 0000000000..0a9c8eef40 --- /dev/null +++ b/docker/linux/stk-engine/Dockerfile @@ -0,0 +1,50 @@ +ARG baseImage=centos:7 +FROM ${baseImage} AS builder + +# Add the engine packages to the builder stage +COPY distributions/stk*.tgz /tmp/ + +# Unpack engine +RUN set -e; \ + mkdir -p /stk; \ + find /tmp -name stk*.tgz -exec tar -zxf {} --strip-components=1 -C /stk \; + +# Reduce image size by removing unnecessary components +RUN set -e; \ + rm -rf /stk/Data/ExampleScenarios/; \ + rm -rf /stk/Data/HtmlInterface/; \ + rm -rf /stk/Data/HtmlUtilities/; \ + rm -rf /stk/Data/LicAndReg/; \ + rm -rf /stk/Data/Resources/; \ + rm -rf /stk/Data/Viewer/; \ + rm -rf /stk/STKData/VO; \ + rm -rf /stk/licensingclient/linx64/ClientSettings + +# Set the base image for the next stage +FROM ${baseImage} + +LABEL ANSYSLMD_LICENSE_FILE='Specifies the location of the Ansys Licensing Server. The format should be PORT@FQDN. If using a triad of license servers, list all servers in the same format separated by semicolons. Required.' + +# Define STK user home directory +ENV STK_USER_HOME=/home/stk + +# Setup non-root STK user +RUN useradd -ms /bin/bash stk + +# Switch to STK user +WORKDIR "${STK_USER_HOME}" +USER stk + +# Copy files from the builder stage +COPY --from=builder --chown=stk /stk/ "${STK_USER_HOME}"/ + +# Configure environment +ENV LD_LIBRARY_PATH="${STK_USER_HOME}/bin" \ + PATH="${STK_USER_HOME}/bin:${PATH}" \ + STK_CONFIG_DIR="${STK_USER_HOME}/config" \ + STK_INSTALL_DIR="${STK_USER_HOME}" + +# Run new user install +RUN stkxnewuser /force /allowOnline=yes + +CMD echo 'STK Engine requires a host application to run. Shutting down this container.' diff --git a/docker/linux/stk-engine/docker-compose.yml b/docker/linux/stk-engine/docker-compose.yml new file mode 100644 index 0000000000..e327e6500e --- /dev/null +++ b/docker/linux/stk-engine/docker-compose.yml @@ -0,0 +1,11 @@ +version: '3.8' +services: + stk: + image: ansys/stk:latest-centos7 + container_name: stk + build: + context: . + args: + baseImage: centos:7 + environment: + - ANSYSLMD_LICENSE_FILE=$ANSYSLMD_LICENSE_FILE