Skip to content

Update containers

Update containers #72

Workflow file for this run

name: Containers
on:
push:
branches:
- main
paths:
- 'dockerfiles/**'
pull_request:
branches:
- main
paths:
- 'dockerfiles/**'
concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
detect-changes:
runs-on: ubuntu-latest
name: Detect changes to Dockerfiles
permissions:
pull-requests: read
outputs:
modified_files_count: ${{ steps.changed-files.outputs.modified_files_count }}
other_modified_files_count: ${{ steps.changed-files.outputs.other_modified_files_count }}
directories: ${{ steps.format.outputs.directories }}
steps:
- uses: actions/checkout@v3
- name: Detect changed files
id: changed-files
uses: tj-actions/changed-files@v37
with:
path: dockerfiles
dir_names: true
dir_names_max_depth: 1
dir_names_exclude_current_dir: true
files: minimal-notebook/**
- id: format
run: |
echo "${{ steps.changed-files.outputs.other_modified_files }}" | python -c "import sys,json;d=json.dumps({'directories': sys.stdin.read().strip().split(' ')});print(f'directories={d}')" >> $GITHUB_OUTPUT
build-base-container:
if: needs.detect-changes.outputs.modified_files_count > 0
needs:
- detect-changes
runs-on: ubuntu-latest
name: Build base container
permissions:
packages: write
steps:
- uses: actions/checkout@v3
- uses: docker/setup-buildx-action@v2
- uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-python@v4
with:
python-version: '3.9'
- id: get-version
run: |
pip install tbump
pushd dockerfiles/minimal-notebook
echo "version=$(tbump current-version)" >> $GITHUB_OUTPUT
- uses: docker/build-push-action@v4
if: github.event_name == 'pull_request'
with:
cache-from: type=gha
cache-to: type=gha,mode=max
context: dockerfiles/minimal-notebook
pull: true
push: true
tags: ghcr.io/esgf-nimbus/minimal-notebook:cache
- uses: docker/build-push-action@v4
if: github.event_name == 'push'
with:
cache-from: type=gha
cache-to: type=gha,mode=max
context: dockerfiles/minimal-notebook
pull: true
push: true
tags: ghcr.io/esgf-nimbus/minimal-notebook:${{ steps.get-version.outputs.version }}
build-other-containers:
if: always() && needs.detect-changes.outputs.other_modified_files_count > 0
needs:
- detect-changes
- build-base-container
runs-on: ubuntu-latest
name: Build other containers
permissions:
packages: write
strategy:
matrix: ${{ fromJSON(needs.detect-changes.outputs.directories) }}
steps:
- uses: actions/checkout@v3
- uses: docker/setup-buildx-action@v2
- uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-python@v4
with:
python-version: '3.9'
- id: get-version
run: |
pip install tbump
pushd dockerfiles/${{ matrix.directories }}
echo "version=$(tbump current-version)" >> $GITHUB_OUTPUT
- uses: docker/build-push-action@v4
if: github.event_name == 'pull_request'
with:
cache-from: type=gha
cache-to: type=gha,mode=max
context: dockerfiles/${{ matrix.directories }}
build-args: ${{ (contains(matrix.directories, 'minimal-notebook') || contains(matrix.directories, 'nimbus')) && 'TAG=cache' || '' }}
pull: true
push: true
tags: ghcr.io/esgf-nimbus/${{ matrix.directories }}:cache
- uses: docker/build-push-action@v4
if: github.event_name == 'push'
with:
cache-from: type=gha
cache-to: type=gha,mode=max
context: dockerfiles/${{ matrix.directories }}
pull: true
push: true
tags: ghcr.io/esgf-nimbus/${{ matrix.directories }}:${{ steps.get-version.outputs.version }}