diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000..f5fc676c70 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +# Ignore these +build \ No newline at end of file diff --git a/.github/workflows/run_docker.yml b/.github/workflows/run_docker.yml new file mode 100644 index 0000000000..a628ea60b7 --- /dev/null +++ b/.github/workflows/run_docker.yml @@ -0,0 +1,33 @@ +name: Docker + +on: [pull_request,workflow_dispatch] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref || github.run_id }} + cancel-in-progress: true + +jobs: + docker-build-and-test: + name: Build and Test - ${{ matrix.dockerfile }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + dockerfile: + - Dockerfile.intel + - Dockerfile.nvhpc + steps: + - name: Checkout code + uses: actions/checkout@v3 + + # Some base images, like nvidia or intel, are very large and cannot be built by github + # This tool cache folder is only necessary if you are building the image in the same runner + # Since we are only building docker images, we don't need it + - name: Delete huge unnecessary tools folder + run: rm -rf /opt/hostedtoolcache + + - name: Build Docker image + run: docker build -t netcdf -f docker/${{ matrix.dockerfile }} . + + - name: Run tests in container + run: docker run --name test-container -t netcdf bash -c 'make test ARGS="--rerun-failed --output-on-failure -j8"' \ No newline at end of file diff --git a/docker/Dockerfile.intel b/docker/Dockerfile.intel new file mode 100644 index 0000000000..959f8b9a0b --- /dev/null +++ b/docker/Dockerfile.intel @@ -0,0 +1,35 @@ +# versions and sizes from here: https://hub.docker.com/r/intel/oneapi-hpckit/tags +FROM intel/oneapi-hpckit:latest + +# Install necessary dependencies +RUN apt update -y && \ + apt install -y \ + bzip2 \ + cmake \ + libcurl4-openssl-dev \ + libhdf5-dev \ + git \ + m4 \ + make \ + unzip \ + wget \ + zlib1g-dev \ + && apt clean all + +# Set working directory +WORKDIR /usr/local/src + +COPY . netcdf-c + +# Set environment variables for Intel compilers +ENV CC=icx +ENV CXX=icpx +ENV FC=ifx + +# Build and install NetCDF +WORKDIR /usr/local/src/netcdf-c +RUN cmake -S . -B build && \ + cd build && make -j && \ + make install + +WORKDIR /usr/local/src/netcdf-c/build \ No newline at end of file diff --git a/docker/Dockerfile.nvhpc b/docker/Dockerfile.nvhpc new file mode 100644 index 0000000000..b04d2fb3fd --- /dev/null +++ b/docker/Dockerfile.nvhpc @@ -0,0 +1,40 @@ +# nvidia rate limits requests. You can get around this by restarting docker if for +# some reason you have to build this image many times +# https://stackoverflow.com/a/75757516/5217293 +# +# Container versions, and sizes, can be found at https://catalog.ngc.nvidia.com/orgs/nvidia/containers/nvhpc/tags +# +FROM nvcr.io/nvidia/nvhpc:23.7-devel-cuda12.2-ubuntu22.04 + +# Install necessary dependencies +RUN apt update -y && \ + apt install -y \ + bzip2 \ + cmake \ + libcurl4-openssl-dev \ + libhdf5-dev \ + git \ + m4 \ + make \ + unzip \ + wget \ + zlib1g-dev \ + && apt clean all + +# Set working directory +WORKDIR /usr/local/src + +COPY . netcdf-c + +# Set environment variables for nvidia compilers +ENV CXX=nvc++ +ENV CC=nvc +ENV FC=nvfortran + +# Build and install NetCDF +WORKDIR /usr/local/src/netcdf-c +RUN cmake -S . -B build && \ + cd build && make -j && \ + make install + +WORKDIR /usr/local/src/netcdf-c/build \ No newline at end of file