Skip to content

Commit

Permalink
chore: Use conda for libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisjared committed May 29, 2024
1 parent c4c8e2d commit 78491dc
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 186 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
type=schedule
type=ref,event=branch
type=ref,event=pr
type=raw,value=${{ env.WRF_VERSION }}
type=raw,value=${{ env.WRF_VERSION }},enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
- name: Build and push image
uses: docker/build-push-action@v5
id: build
Expand All @@ -66,3 +66,5 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
tags: ${{ steps.meta.outputs.tags }}
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
33 changes: 25 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,43 @@
FROM ubuntu:20.04 as base
FROM continuumio/miniconda3 as build

MAINTAINER Jared Lewis <[email protected]>

ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Etc/UTC

RUN apt-get update && \
apt-get install -y sudo curl build-essential gfortran m4 csh git jq wget aria2 imagemagick libmpich-dev file libnetcdff-dev && \
apt-get install -y curl m4 csh jq file && \
rm -rf /var/lib/apt/lists/*

FROM base as build
COPY environment.yml /opt/environment.yml
RUN conda env create -f /opt/environment.yml

ARG TARGETPLATFORM
ARG WRF_VERSION=4.5.1
ARG WPS_VERSION=4.5
# Install conda-pack:
RUN conda install -c conda-forge conda-pack

# Use conda-pack to create a standalone enviornment
# in /venv:
RUN conda-pack -n wrf -o /tmp/env.tar && \
mkdir /opt/venv && cd /opt/venv && tar xf /tmp/env.tar && \
rm /tmp/env.tar

# We've put venv in same path it'll be in final image,
# so now fix up paths:
RUN /opt/venv/bin/conda-unpack

COPY scripts /opt/wrf/build/scripts/
RUN PLATFORM=${TARGETPLATFORM} WRF_VERSION=${WRF_VERSION} WPS_VERSION=${WPS_VERSION} bash /opt/wrf/build/scripts/build_wrf.sh


FROM debian:bookworm AS runtime

ARG TARGETPLATFORM
ARG WRF_VERSION=4.5.1
ARG WPS_VERSION=4.5

WORKDIR /opt/wrf
COPY --from=build /opt/venv /opt/venv
COPY --from=build /opt/wrf /opt/wrf

RUN PLATFORM=${TARGETPLATFORM} bash /opt/wrf/build/scripts/install_deps.sh
RUN PLATFORM=${TARGETPLATFORM} WRF_VERSION=${WRF_VERSION} WPS_VERSION=${WPS_VERSION} bash /opt/wrf/build/scripts/build_wrf.sh

ENTRYPOINT ["/bin/bash"]
11 changes: 11 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: wrf
channels:
- conda-forge
- defaults
dependencies:
- hdf5=1.14.3
- jasper=4.2.4
- mpich=4.2.1
- netcdf-fortran=4.6.1
- wget
- gfortran=10.4
16 changes: 11 additions & 5 deletions scripts/build_wrf.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/usr/bin/env bash
# Builds WRF and WPS using the prebuilt dependencies

set -x
set -e
set -xe

# Setup
WRF_VERSION="${WRF_VERSION:-4.5.1}"
WPS_VERSION="${WPS_VERSION:-4.5}"
DIR=/opt/wrf/libs
DIR=/opt/venv

# Link to the compiled dependencies
export PATH=$DIR/bin:$PATH
Expand All @@ -21,10 +20,11 @@ export F77=gfortran
export FFLAGS="-m64 -fallow-argument-mismatch"
export NETCDF=$(nc-config --prefix)
export NETCDF4=1
#export HDF5=$DIR
export HDF5=$DIR
export JASPERLIB=$DIR/lib
export JASPERINC=$DIR/include
export J="-j 8"
export ARCH=$(uname -m)

pushd $DIR/..

Expand All @@ -33,7 +33,13 @@ if [ ! -f WRF-${WRF_VERSION}/run/real.exe ]; then
wget -nv https://github.com/wrf-model/WRF/releases/download/v${WRF_VERSION}/v${WRF_VERSION}.tar.gz -O WRF-v${WRF_VERSION}.tar.gz
tar -xzvf WRF-v${WRF_VERSION}.tar.gz
pushd WRFV${WRF_VERSION} || exit
echo "34\n1\n" | ./configure

if (( $ARCH == "aarch64" )); then
echo "12\n1\n" | ./configure
else
echo "34\n1\n" | ./configure
fi

./compile em_real
popd
ln -s WRFV${WRF_VERSION} WRF
Expand Down
154 changes: 0 additions & 154 deletions scripts/install_deps.sh

This file was deleted.

3 changes: 0 additions & 3 deletions scripts/install_system_deps.sh

This file was deleted.

15 changes: 0 additions & 15 deletions scripts/setup_logging.sh

This file was deleted.

0 comments on commit 78491dc

Please sign in to comment.