Skip to content
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
95 changes: 95 additions & 0 deletions .github/workflows/docker-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Docker CI

on:
pull_request:
paths:
- "Dockerfile"
- "docker-compose.yml"
- ".dockerignore"
- "entrypoint.sh"
- "start-jupyter.sh"
- "pyproject.toml"
- "sarpyx/**"
- "tests/**"
- "support/**"
- ".github/workflows/docker-ci.yml"
- ".github/workflows/docker-publish.yml"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
DOCKER_IMAGE: sirbastiano94/sarpyx
DOCKER_TEST_GRID: /workspace/grid/grid_smoke.geojson

jobs:
docker-smoke:
runs-on: ubuntu-latest
timeout-minutes: 180

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: v0.11.2

- name: Build Docker image
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
load: true
platforms: linux/amd64
tags: ${{ env.DOCKER_IMAGE }}:ci
cache-from: type=gha,scope=sarpyx-docker
cache-to: type=gha,mode=max,scope=sarpyx-docker

- name: Run mounted Docker smoke tests
run: |
docker run --rm \
-e GRID_PATH="${GRID_PATH}" \
-v "${GITHUB_WORKSPACE}/tests:/opt/smoke-tests:ro" \
-v "${GITHUB_WORKSPACE}/tests/fixtures:/workspace/grid:ro" \
${{ env.DOCKER_IMAGE }}:ci \
sh -lc "python3.11 -m pip install --no-cache-dir pytest==8.4.0 && python3.11 -m pytest /opt/smoke-tests/test_docker.py -q --tb=short"
env:
GRID_PATH: ${{ env.DOCKER_TEST_GRID }}
shell: bash

- name: Start Jupyter smoke container
run: |
docker run -d --rm \
--name sarpyx-jupyter-smoke \
-p 127.0.0.1:8888:8888 \
-e GRID_PATH="${GRID_PATH}" \
-e JUPYTER_TOKEN=ci-smoke-token \
-v "${GITHUB_WORKSPACE}/tests/fixtures:/workspace/grid:ro" \
${{ env.DOCKER_IMAGE }}:ci \
/usr/local/bin/start-jupyter.sh
env:
GRID_PATH: ${{ env.DOCKER_TEST_GRID }}
shell: bash

- name: Wait for Jupyter health check
run: |
for attempt in {1..30}; do
if curl -fsS "http://127.0.0.1:8888/lab?token=ci-smoke-token" >/dev/null; then
exit 0
fi
sleep 5
done
docker logs sarpyx-jupyter-smoke
exit 1
shell: bash

- name: Dump Jupyter smoke logs
if: always()
run: docker logs sarpyx-jupyter-smoke || true

- name: Remove Jupyter smoke container
if: always()
run: docker rm -f sarpyx-jupyter-smoke || true
Original file line number Diff line number Diff line change
@@ -1,27 +1,6 @@
# ──────────────────────────────────────────────────────────────
# CI/CD – Docker build, test, and publish
# ──────────────────────────────────────────────────────────────
# Triggers:
# • Pull requests touching Docker/runtime files → build + smoke test
# • Pushes to main touching Docker/runtime files → build + smoke test + push tested image
# • Manual dispatch → build + smoke test + optional push of tested image
# ──────────────────────────────────────────────────────────────

name: Docker Build & Publish
name: Docker Publish

on:
pull_request:
paths:
- "Dockerfile"
- "docker-compose.yml"
- ".dockerignore"
- "entrypoint.sh"
- "start-jupyter.sh"
- "pyproject.toml"
- "sarpyx/**"
- "tests/**"
- "support/**"
- ".github/workflows/docker.yml"
push:
branches: [main]
paths:
Expand All @@ -30,17 +9,12 @@ on:
- ".dockerignore"
- "entrypoint.sh"
- "start-jupyter.sh"
- "pyproject.toml"
- "sarpyx/**"
- "tests/**"
- "pyproject.toml"
- "support/**"
- ".github/workflows/docker.yml"
workflow_dispatch:
inputs:
push_image:
description: "Push image to Docker Hub after build?"
required: false
default: "false"
- ".github/workflows/docker-ci.yml"
- ".github/workflows/docker-publish.yml"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -51,7 +25,7 @@ env:
DOCKER_TEST_GRID: /workspace/grid/grid_smoke.geojson

jobs:
docker:
docker-publish:
runs-on: ubuntu-latest
timeout-minutes: 180

Expand Down Expand Up @@ -122,28 +96,15 @@ jobs:
run: docker rm -f sarpyx-jupyter-smoke || true

- name: Log in to Docker Hub
if: >-
(
github.event_name == 'push' ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.push_image == 'true')
)
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Tag and push tested Docker image
if: >-
(
github.event_name == 'push' ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.push_image == 'true')
)
run: |
docker tag "${{ env.DOCKER_IMAGE }}:ci" "${{ env.DOCKER_IMAGE }}:${GITHUB_SHA}"
docker push "${{ env.DOCKER_IMAGE }}:${GITHUB_SHA}"

if [ "${GITHUB_REF}" = "refs/heads/main" ]; then
docker tag "${{ env.DOCKER_IMAGE }}:ci" "${{ env.DOCKER_IMAGE }}:latest"
docker push "${{ env.DOCKER_IMAGE }}:latest"
fi
docker tag "${{ env.DOCKER_IMAGE }}:ci" "${{ env.DOCKER_IMAGE }}:latest"
docker push "${{ env.DOCKER_IMAGE }}:latest"
shell: bash
Loading
Loading