-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update to netcdf 0.8.1 and add rustler precompiled (#6)
- Loading branch information
1 parent
9aff800
commit 44bb77b
Showing
15 changed files
with
482 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
name: Elixir CI | ||
on: | ||
release: | ||
types: [published] | ||
|
||
env: | ||
RUST_TOOLCHAIN_VERSION: nightly-2022-08-16 | ||
MIX_ENV: prod | ||
NETCDF_BUILD: true | ||
|
||
jobs: | ||
build_release: | ||
name: Release ${{ matrix.nif }} - ${{ matrix.job.target }} | ||
runs-on: ${{ matrix.job.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
nif: ["2.15", "2.16"] | ||
job: | ||
- { target: x86_64-apple-darwin, os: macos-11 } | ||
- { target: x86_64-unknown-linux-gnu, os: ubuntu-20.04 } | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Install Conda | ||
uses: s-weigand/setup-conda@v1 | ||
with: | ||
conda-channels: conda-forge | ||
- name: Extract project version | ||
shell: bash | ||
run: | | ||
# Get the project version from mix.exs | ||
echo "PROJECT_VERSION=$(sed -n 's/^ @version "\(.*\)"/\1/p' mix.exs | head -n1)" >> $GITHUB_ENV | ||
- name: Install Rust toolchain | ||
uses: dtolnay/rust-toolchain@stable | ||
with: | ||
toolchain: stable | ||
target: ${{ matrix.job.target }} | ||
- name: Install dependencies | ||
if: ${{ matrix.job.os != 'macos-11' }} | ||
run: | | ||
conda install -y -c conda-forge libnetcdf=4.8.1 hdf5=1.12.1 | ||
echo "HDF5_DIR=${CONDA_PREFIX}" | ||
echo "NETCDF_DIR=${CONDA_PREFIX}" >> $GITHUB_ENV | ||
echo "RUSTFLAGS=-C link-args=-Wl,-rpath,$CONDA_PREFIX/lib" >> $GITHUB_ENV | ||
- name: Install dependencies (Mac) | ||
if: ${{ matrix.job.os == 'macos-11' }} | ||
run: brew install nco | ||
- name: Build the project | ||
id: build-crate | ||
uses: philss/[email protected] | ||
with: | ||
project-name: ex_netcdf | ||
project-version: ${{ env.PROJECT_VERSION }} | ||
target: ${{ matrix.job.target }} | ||
nif-version: ${{ matrix.nif }} | ||
use-cross: ${{ matrix.job.use-cross }} | ||
project-dir: "native/ex_netcdf" | ||
- name: Artifact upload | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: ${{ steps.build-crate.outputs.file-name }} | ||
path: ${{ steps.build-crate.outputs.file-path }} | ||
- name: Publish archives and packages | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
files: | | ||
${{ steps.build-crate.outputs.file-path }} | ||
if: startsWith(github.ref, 'refs/tags/') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,9 @@ erl_crash.dump | |
|
||
/priv | ||
/priv/native/libex_netcdf | ||
/release_build | ||
*.so.tar.gz | ||
|
||
|
||
### Elixir Patch ### | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# Find eligible builder and runner images on Docker Hub. We use Ubuntu/Debian | ||
# instead of Alpine to avoid DNS resolution issues in production. | ||
# | ||
# https://hub.docker.com/r/hexpm/elixir/tags?page=1&name=ubuntu | ||
# https://hub.docker.com/_/ubuntu?tab=tags | ||
# | ||
# This file is based on these images: | ||
# | ||
# - https://hub.docker.com/r/hexpm/elixir/tags - for the build image | ||
# - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20210902-slim - for the release image | ||
# - https://pkgs.org/ - resource for finding needed packages | ||
# - Ex: hexpm/elixir:1.14.2-erlang-25.0.2-debian-bullseye-20210902-slim | ||
# | ||
ARG ELIXIR_VERSION=1.14.2 | ||
ARG OTP_VERSION=25.0.2 | ||
ARG DEBIAN_VERSION=bullseye-20210902-slim | ||
|
||
ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}" | ||
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}" | ||
|
||
ARG RUSTLER_NIF_VERSION | ||
|
||
FROM ${BUILDER_IMAGE} as builder | ||
|
||
# install build dependencies | ||
RUN apt-get update -y && apt-get install -y cmake build-essential git curl wget \ | ||
&& apt-get clean && rm -f /var/lib/apt/lists/*_* | ||
|
||
# install Rust non-interactively, and put it in the $PATH so the netcdf Elixir dep can find it | ||
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain 1.66.1 | ||
ENV PATH="/root/.cargo/bin:$PATH" | ||
|
||
ENV CONDA_PREFIX=/opt/conda | ||
ENV PATH=${CONDA_PREFIX}/bin:$PATH | ||
RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-$(arch).sh -O ~/miniconda.sh && /bin/bash ~/miniconda.sh -b -p ${CONDA_PREFIX} | ||
RUN conda install -y -c conda-forge libnetcdf=4.8.1 hdf5=1.12.1 | ||
ENV HDF5_DIR=${CONDA_PREFIX} | ||
ENV NETCDF_DIR=${CONDA_PREFIX} | ||
ENV RUSTFLAGS="-C link-args=-Wl,-rpath,$CONDA_PREFIX/lib" | ||
ENV NETCDF_BUILD=true | ||
|
||
ENV MIX_ENV=prod | ||
|
||
# prepare build dir | ||
WORKDIR /app | ||
|
||
# install hex + rebar | ||
RUN mix local.hex --force && \ | ||
mix local.rebar --force | ||
|
||
# install mix dependencies | ||
COPY mix.exs mix.lock VERSION ./ | ||
RUN mix deps.get --only prod | ||
RUN mkdir config | ||
|
||
# copy compile-time config files before we compile dependencies | ||
# to ensure any relevant config change will trigger the dependencies | ||
# to be re-compiled. | ||
# COPY config/config.exs config/prod.exs config/ | ||
RUN mix deps.compile | ||
|
||
COPY lib lib | ||
COPY native native | ||
|
||
# Compile the release | ||
RUN mix compile | ||
|
||
# Changes to config/runtime.exs don't require recompiling the code | ||
# COPY config/runtime.exs config/ | ||
|
||
ENV RUSTLER_NIF_VERSION=${RUSTLER_NIF_VERSION} | ||
RUN mix release | ||
|
||
FROM ${RUNNER_IMAGE} | ||
|
||
WORKDIR "/app" | ||
|
||
COPY --from=builder --chown=nobody:nogroup /app/_build/prod/rel/netcdf ./ | ||
|
||
RUN mkdir /mnt/release | ||
RUN chown nobody:nogroup /mnt/release | ||
RUN chown nobody:nogroup /app | ||
|
||
USER nobody | ||
|
||
|
||
CMD ["/bin/bash"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Usage: | ||
# Run `make` or `make all` to generate all combinations of OS=linux/mac and NIF_VERSION=2.15/2.16 | ||
# for the host architecture. Mostly useful for aarch64 because CI takes care of x86_64 releases. | ||
|
||
VALID_NIF_VERSIONS := 2.15 2.16 | ||
|
||
VERSION_PATTERN := ^[0-9]+\.[0-9]+\.[0-9]+$$ | ||
|
||
# Set the VERSION environment variable using the contents of the VERSION file | ||
VERSION := $(shell cat VERSION) | ||
|
||
# Check that the VERSION variable matches the expected pattern | ||
ifeq ($(shell echo $(VERSION) | grep -Eo '$(VERSION_PATTERN)'),$(VERSION)) | ||
$(info VERSION is valid: '$(VERSION)') | ||
else | ||
$(error VERSION is invalid: '$(VERSION)') | ||
endif | ||
|
||
ifeq ($(shell uname -s), Darwin) | ||
TARGET_OS := apple-darwin | ||
else | ||
TARGET_OS := unknown-linux-gnu | ||
endif | ||
|
||
ifeq ($(shell uname -m), arm64) | ||
# Processor is Mac arm | ||
TARGET_ARCH := aarch64 | ||
else | ||
# Processor is not Mac arm | ||
TARGET_ARCH := x86_64 | ||
endif | ||
|
||
NETCDF_SO_PREFIX := libex_netcdf-v$(VERSION)-nif-$(NIF_VERSION)-$(TARGET_ARCH) | ||
NETCDF_SO := $(NETCDF_SO_PREFIX)-$(TARGET_OS).so | ||
GNU_NETCDF_SO := $(NETCDF_SO_PREFIX)-unknown-linux-gnu.so | ||
|
||
.PHONY: all | ||
all: | ||
@echo "Building targets for NIF versions: $(VALID_NIF_VERSIONS) and arch: $(TARGET_ARCH)" | ||
@$(foreach nif_version,$(VALID_NIF_VERSIONS), \ | ||
$(MAKE) gnu-docker-release NIF_VERSION=$(nif_version); \ | ||
$(MAKE) host-release NIF_VERSION=$(nif_version); \ | ||
) | ||
|
||
.PHONY: validate_nif_env | ||
validate_nif_env: | ||
@if [ -z "$$NIF_VERSION" ]; then \ | ||
echo "NIF_VERSION is not set"; \ | ||
exit 1; \ | ||
fi | ||
@if [ -z "$(filter ${NIF_VERSION}, ${VALID_NIF_VERSIONS})" ]; then \ | ||
echo "NIF_VERSION is set to ${NIF_VERSION}, but it should be one of: ${VALID_NIF_VERSIONS}"; \ | ||
exit 1; \ | ||
fi | ||
@echo "NIF_VERSION is set to ${NIF_VERSION} and is valid" | ||
|
||
.PHONY: gnu-docker-release | ||
gnu-docker-release: validate_nif_env | ||
docker build --tag netcdf-release --build-arg RUSTLER_NIF_VERSION=$(NIF_VERSION) -f Dockerfile.gnu-linux . | ||
docker run --mount type=bind,source="$(shell pwd)",target=/mnt/release netcdf-release cp /app/lib/netcdf-$(VERSION)/priv/native/libex_netcdf.so /mnt/release/$(GNU_NETCDF_SO) | ||
tar -czvf $(GNU_NETCDF_SO).tar.gz $(GNU_NETCDF_SO) | ||
rm $(GNU_NETCDF_SO) | ||
|
||
.PHONY: host-release | ||
host-release: validate_nif_env | ||
mix deps.get --only=prod | ||
RUSTLER_NIF_VERSION=$(NIF_VERSION) MIX_ENV=prod NETCDF_BUILD=true mix release --overwrite --force | ||
mv _build/prod/rel/netcdf/lib/netcdf-$(VERSION)/priv/native/libex_netcdf.so $(NETCDF_SO) | ||
tar -czvf $(NETCDF_SO).tar.gz $(NETCDF_SO) | ||
rm $(NETCDF_SO) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.