Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up regular Docker build #38

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: [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 '{}' \; | \
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: [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
Loading