diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..558e4ab --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,42 @@ +name: Periodic Docker build + +on: + # Build the Docker container whenever commits are pushed to an open PR that changes one of the files listed + pull_request: + paths: + - .github/workflows/docker.yml + - docker/Dockerfile.devenv + - docker/spack.yaml + + # Build the Docker container at 00:00 on the first day of every 3 months + schedule: + - cron: '0 0 1 */3 *' + +jobs: + docker: + name: Build Docker container + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout the repo + uses: actions/checkout@v4 + + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v3 + + - name: Log into GitHub Container Repository + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + logout: true + + - name: Build container and push to ghcr + uses: docker/build-push-action@v5 + with: + push: true + file: docker/Dockerfile.devenv + tags: ghcr.io/fetch4/giss-gc-dev-env:latest diff --git a/docker/Dockerfile.devenv b/docker/Dockerfile.devenv index 0233a40..57d950e 100644 --- a/docker/Dockerfile.devenv +++ b/docker/Dockerfile.devenv @@ -1,32 +1,18 @@ # Build stage with Spack pre-installed and ready to be used FROM spack/ubuntu-jammy:0.21 AS builder -# What we want to install and how we want to install it -# is specified in a manifest file (spack.yaml) -RUN mkdir /opt/spack-environment \ -&& (echo spack: \ -&& echo ' packages:' \ -&& echo ' all:' \ -&& echo ' compiler: [gcc@11.4.0]' \ -&& echo ' specs:' \ -&& echo ' - cmake@3.27.7' \ -&& echo ' - gmake' \ -&& echo ' - hdf5@1.14.3' \ -&& echo ' - netcdf-c@4.9.2+mpi+parallel-netcdf' \ -&& echo ' - netcdf-fortran' \ -&& echo ' - openmpi@4.1.6' \ -&& echo ' concretizer:' \ -&& echo ' unify: true' \ -&& echo ' config:' \ -&& echo ' install_missing_compilers: true' \ -&& echo ' install_tree: /opt/software' \ -&& echo ' view: /opt/views/view') > /opt/spack-environment/spack.yaml - -# Install the software, remove unnecessary deps -RUN cd /opt/spack-environment && spack env activate . && spack install --fail-fast && spack gc -y +# Install software from spack.yaml +RUN mkdir /opt/spack-environment +COPY docker/spack.yaml /opt/spack-environment/spack.yaml +RUN cd /opt/spack-environment \ + && spack env activate . \ + && spack install --fail-fast \ + && spack gc -y # Install perl URI lib -RUN apt update && apt install -y libany-uri-escape-perl +RUN apt update \ + && apt install -y --no-install-recommends libany-uri-escape-perl \ + && rm -rf /var/lib/apt/lists/* # Strip all the binaries RUN find -L /opt/views/view/* -type f -exec readlink -f '{}' \; | \ @@ -36,27 +22,31 @@ RUN find -L /opt/views/view/* -type f -exec readlink -f '{}' \; | \ awk -F: '{print $1}' | xargs strip # Modifications to the environment that are necessary to run -RUN cd /opt/spack-environment && \ - spack env activate --sh -d . > activate.sh +RUN cd /opt/spack-environment \ + && spack env activate --sh -d . > activate.sh # Bare OS image to run the installed executables FROM ubuntu:22.04 +# Copy necessary files from the builder stage COPY --from=builder /opt/spack-environment /opt/spack-environment COPY --from=builder /opt/software /opt/software COPY --from=builder /usr /usr - # paths.view is a symlink, so copy the parent to avoid dereferencing and duplicating it COPY --from=builder /opt/views /opt/views +# Create entrypoint script RUN { \ - echo '#!/bin/sh' \ - && echo '.' /opt/spack-environment/activate.sh \ - && echo 'exec "$@"'; \ + echo '#!/bin/sh'; \ + echo '. /opt/spack-environment/activate.sh'; \ + echo 'exec "$@"'; \ } > /entrypoint.sh \ -&& chmod a+x /entrypoint.sh \ -&& ln -s /opt/views/view /opt/view \ -&& apt update && apt install -y ca-certificates cpp m4 + && chmod a+x /entrypoint.sh \ + && ln -s /opt/views/view /opt/view \ + && apt update \ + && apt install -y --no-install-recommends ca-certificates cpp m4 \ + && rm -rf /var/lib/apt/lists/* +# Set entrypoint and default command ENTRYPOINT [ "/entrypoint.sh" ] CMD [ "/bin/bash" ] diff --git a/docker/Makefile b/docker/Makefile index b26aa68..fd75b68 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -1,6 +1,6 @@ all: build -DOCKERFILE = Dockerfile.devenv +DOCKERFILE = ${GISS_HOME}/docker/Dockerfile.devenv NAMESPACE = ghcr.io/fetch4 IMAGE_NAME = giss-gc-dev-env TAG = latest @@ -11,7 +11,7 @@ pull: docker pull $(IMAGE) build: - docker build -f $(DOCKERFILE) -t $(IMAGE) --no-cache . + docker build -f $(DOCKERFILE) -t $(IMAGE) . run: docker run --rm -it -v ${HOME}:${HOME} $(IMAGE) diff --git a/docker/spack.yaml b/docker/spack.yaml new file mode 100644 index 0000000..97eb0d2 --- /dev/null +++ b/docker/spack.yaml @@ -0,0 +1,17 @@ +spack: + packages: + all: + compiler: [gcc@11.4.0] + specs: + - cmake + - gmake + - hdf5 + - netcdf-c+mpi+parallel-netcdf + - netcdf-fortran + - openmpi + concretizer: + unify: true + config: + install_missing_compilers: true + install_tree: /opt/software + view: /opt/views/view