Skip to content

Commit

Permalink
Docker will checkout PR if being run during PR CI
Browse files Browse the repository at this point in the history
  • Loading branch information
scrasmussen committed Jul 26, 2024
1 parent eb66477 commit 7d7b5b4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci_test_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on: [pull_request,workflow_dispatch]

env:
TEST_TAG: dtcenter/ccpp-scm:test
PR_NUMBER: ${{ github.event.number }}

jobs:
docker:
Expand All @@ -22,8 +23,9 @@ jobs:
file: docker/Dockerfile
load: true
tags: ${{ env.TEST_TAG }}
build-args: PR_NUMBER=${{ github.event.number }}
- name: Test
run: |
mkdir $HOME/output
chmod a+rw $HOME/output
docker run --rm -v $HOME/output:/home ${{ env.TEST_TAG }} ./run_scm.py -f ../../test/rt_test_cases.py --runtime_mult 0.1 -d -a
docker run --rm -v $HOME/output:/home ${{ env.TEST_TAG }} ./run_scm.py -f ../../test/rt_test_cases.py --runtime_mult 0.1 -d --stop_on_error
23 changes: 17 additions & 6 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
FROM debian:12
LABEL maintainer="Michael Kavulich <[email protected]>"

# Set up base OS environment
# arguments that can be passed in
ARG PR_NUMBER

# Set up base OS environment
RUN apt-get -y update

# Get "essential" tools and libraries
Expand Down Expand Up @@ -70,11 +72,20 @@ ENV sp_ROOT=/comsoftware/nceplibs
ENV w3emc_ROOT=/comsoftware/nceplibs

# Obtain CCPP SCM source code, build code, and download static data
RUN cd /comsoftware \
&& git clone --recursive -b main https://github.com/NCAR/ccpp-scm \
&& mkdir /comsoftware/ccpp-scm/scm/bin

RUN cd /comsoftware/ccpp-scm/scm/bin \
RUN if [ -z "$PR_NUMBER" ]; then \
cd /comsoftware \
&& git clone --recursive -b main https://github.com/NCAR/ccpp-scm; \
else \
cd /comsoftware \
&& git clone https://github.com/NCAR/ccpp-scm \
&& cd ccpp-scm \
&& git fetch origin pull/${PR_NUMBER}/head:test_pr \
&& git checkout test_pr \
&& git submodule update --init --recursive; \
fi

RUN mkdir /comsoftware/ccpp-scm/scm/bin \
&& cd /comsoftware/ccpp-scm/scm/bin \
&& cmake ../src \
&& make -j

Expand Down
12 changes: 6 additions & 6 deletions scm/src/run_scm.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
# Default command string to run MPI apps (number of processes should be 1 since SCM is not set up to use more than 1 yet)
DEFAULT_MPI_COMMAND = 'mpirun -np 1'


# Copy executable to run directory if true (otherwise it will be linked)
COPY_EXECUTABLE = False

Expand Down Expand Up @@ -120,7 +121,7 @@
parser.add_argument('--n_itt_out', help='period of instantaneous output (number of timesteps)', required=False, type=int)
parser.add_argument('--n_itt_diag', help='period of diagnostic output (number of timesteps)', required=False, type=int)
parser.add_argument('-dt', '--timestep', help='timestep (s)', required=False, type=float)
parser.add_argument('-a', '--actions', help='if running from Github Actions this will select correct configuration', required=False, action='store_true')
parser.add_argument('--stop_on_error', help='when running multiple SCM runs, stop on first error', required=False, action='store_true')
parser.add_argument('-v', '--verbose', help='set logging level to debug and write log to file', action='count', default=0)
parser.add_argument('-f', '--file', help='name of file where SCM runs are defined')
parser.add_argument('--mpi_command', help='command used to invoke the executable via MPI (including options)', required=False)
Expand Down Expand Up @@ -191,14 +192,14 @@ def parse_arguments():
bin_dir = args.bin_dir
timestep = args.timestep
mpi_command = args.mpi_command
github_actions = args.actions
stop_on_error = args.stop_on_error

if not sdf:
sdf = DEFAULT_SUITE

return (file, case, sdf, namelist, tracers, gdb, runtime, runtime_mult, docker, \
verbose, levels, npz_type, vert_coord_file, case_data_dir, n_itt_out, \
n_itt_diag, run_dir, bin_dir, timestep, mpi_command, github_actions)
n_itt_diag, run_dir, bin_dir, timestep, mpi_command, stop_on_error)

def find_gdb():
"""Detect gdb, abort if not found"""
Expand Down Expand Up @@ -767,7 +768,7 @@ def copy_outdir(exp_dir):
def main():
(file, case, sdf, namelist, tracers, use_gdb, runtime, runtime_mult, docker, \
verbose, levels, npz_type, vert_coord_file, case_data_dir, n_itt_out, \
n_itt_diag, run_dir, bin_dir, timestep, mpi_command, github_actions) = parse_arguments()
n_itt_diag, run_dir, bin_dir, timestep, mpi_command, stop_on_error) = parse_arguments()

setup_logging(verbose)

Expand Down Expand Up @@ -884,8 +885,7 @@ def main():
l_ignore_error = MULTIRUN_IGNORE_ERROR
else:
l_ignore_error = False
# need to correctly fail if running Github Actions
if github_actions:
if stop_on_error:
l_ignore_error = False

(status, time_elapsed) = launch_executable(use_gdb, gdb, mpi_command, ignore_error = l_ignore_error)
Expand Down

0 comments on commit 7d7b5b4

Please sign in to comment.