Skip to content

Commit

Permalink
Merge pull request #38 from fetch4/37_regular_docker_build
Browse files Browse the repository at this point in the history
Set up regular Docker build
  • Loading branch information
jwallwork23 authored Jan 16, 2025
2 parents ecfbc57 + 2d585ca commit f119a98
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 35 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -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
56 changes: 23 additions & 33 deletions docker/Dockerfile.devenv
Original file line number Diff line number Diff line change
@@ -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: [[email protected]]' \
&& echo ' specs:' \
&& echo ' - [email protected]' \
&& echo ' - gmake' \
&& echo ' - [email protected]' \
&& echo ' - [email protected]+mpi+parallel-netcdf' \
&& echo ' - netcdf-fortran' \
&& echo ' - [email protected]' \
&& 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 '{}' \; | \
Expand All @@ -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" ]
4 changes: 2 additions & 2 deletions docker/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions docker/spack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
spack:
packages:
all:
compiler: [[email protected]]
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

0 comments on commit f119a98

Please sign in to comment.