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

[Docker, CI] Allow building pecan/depends from pecan/depends #3260

Merged
merged 19 commits into from
May 16, 2024
Merged
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
4 changes: 1 addition & 3 deletions .github/workflows/book.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ on:
branches:
- master
- develop

tags:
- '*'

pull_request:

merge_group:
workflow_dispatch:

jobs:
bookdown:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/ci-weekly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ name: Weekly Checks
on:
# every Monday at 4:30 AM
# (hopefully after the 1:30 AM `depends` build has completed)
schedule:
schedule:
- cron: '30 4 * * 1'
workflow_dispatch:

jobs:
test:
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ on:

tags:
- '*'

pull_request:

merge_group:

issue_comment:
types:
- created
workflow_dispatch:

env:
R_LIBS_USER: /usr/local/lib/R/site-library
Expand Down
20 changes: 16 additions & 4 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ on:
branches:
- master
- develop

pull_request:

merge_group:

issue_comment:
types:
- created
workflow_dispatch:

# Certain actions will only run when this is the master repo.
env:
Expand Down Expand Up @@ -74,14 +72,28 @@ jobs:
echo "PECAN_VERSION=develop" >> $GITHUB_ENV
echo "PECAN_TAGS=develop" >> $GITHUB_ENV
fi

# If any dependencies changed in this PR, try to update depends image
# Only runs on pull_request -- others it's not clear what base to compare to
- name: check for changed dependencies
if: github.base_ref != ''
uses: dorny/paths-filter@v3
id: findchanges
with:
filters: |
deps:
- docker/depends/**
- if: steps.findchanges.outputs.deps == 'true'
run: echo "UPDATE_DEPENDS_FROM_TAG=${GITHUB_BASE_REF##*/}" >> $GITHUB_ENV
env:
GITHUB_BASE_REF: ${{ github.base_ref }}
# use shell script to build, there is some complexity in this
- name: create images
run: ./docker.sh -i github
env:
PECAN_GIT_CHECKSUM: ${{ github.sha }}
PECAN_GIT_BRANCH: ${GITHUB_BRANCH}
VERSION: ${{ env.PECAN_VERSION }}
UPDATE_DEPENDS_FROM_TAG: ${{ env.UPDATE_DEPENDS_FROM_TAG }}

# push all images to github
- name: Publish to GitHub
Expand Down
3 changes: 2 additions & 1 deletion book_source/03_topical_pages/94_docker/04_models.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ docker build \
Example of a Dockerfile, in this case to build the ED2 model.

```dockerfile
ARG IMAGE_VERSION="latest"
# ----------------------------------------------------------------------
# BUILD MODEL BINARY
# ----------------------------------------------------------------------
FROM debian:stretch as model-binary
FROM pecan/models:${IMAGE_VERSION} as model-binary

# Some variables that can be used to set control the docker build
ARG MODEL_VERSION=git
Expand Down
14 changes: 14 additions & 0 deletions docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ echo "#"
echo "# The docker image for dependencies takes a long time to build. You"
echo "# can use a prebuilt version (default) or force a new version to be"
echo "# built locally using: DEPEND=build $0"
echo "#"
echo "# EXPERIMENTAL: To attempt updating an existing dependency image"
echo "# instead of building from scratch, use UPDATE_DEPENDS_FROM_TAG=<tag>"
echo "# ----------------------------------------------------------------------"

# not building dependencies image, following command will build this
Expand All @@ -125,6 +128,17 @@ if [ "${DEPEND}" == "build" ]; then
--build-arg R_VERSION=${R_VERSION} ${GITHUB_WORKFLOW_ARG} \
--tag pecan/depends:${IMAGE_VERSION} \
docker/depends
elif [ "${UPDATE_DEPENDS_FROM_TAG}" != "" ]; then
echo "# Attempting to update from existing pecan/depends:${UPDATE_DEPENDS_FROM_TAG}."
echo "# This is experimental. if it fails, please instead use"
echo "# 'DEPEND=build' to start from a known clean state."
${DEBUG} docker build \
--pull \
--secret id=github_token,env=GITHUB_PAT \
--build-arg FROM_IMAGE="pecan/depends" \
--build-arg R_VERSION=${UPDATE_DEPENDS_FROM_TAG} ${GITHUB_WORKFLOW_ARG} \
--tag pecan/depends:${IMAGE_VERSION} \
docker/depends
else
if [ "$( docker image ls -q pecan/depends:${IMAGE_VERSION} )" == "" ]; then
if [ "${PECAN_GIT_BRANCH}" != "master" ]; then
Expand Down
14 changes: 3 additions & 11 deletions docker/depends/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
ARG R_VERSION="4.0.2"
ARG R_VERSION="4.1"
ARG FROM_IMAGE="rocker/tidyverse"

infotroph marked this conversation as resolved.
Show resolved Hide resolved
# ----------------------------------------------------------------------
# PECAN FOR MODEL BASE IMAGE
# ----------------------------------------------------------------------
FROM rocker/tidyverse:${R_VERSION}
FROM ${FROM_IMAGE}:${R_VERSION}
MAINTAINER Rob Kooper <[email protected]>

# ----------------------------------------------------------------------
# UPDATE GIT
# This is needed for stretch and github actions
# ----------------------------------------------------------------------
RUN if [ "$(lsb_release -s -c)" = "stretch" ]; then \
echo 'deb http://deb.debian.org/debian stretch-backports main' >> /etc/apt/sources.list \
&& apt-get update \
&& apt-get -t stretch-backports upgrade -y git \
; fi

infotroph marked this conversation as resolved.
Show resolved Hide resolved
# ----------------------------------------------------------------------
# INSTALL BINARY/LIBRARY DEPENDENCIES
Expand Down
Loading