Skip to content

Commit

Permalink
Merge pull request #567 from jennydaman/podman
Browse files Browse the repository at this point in the history
Podman and GitHub Actions support
  • Loading branch information
jennydaman committed Aug 29, 2024
2 parents aef3de0 + 1b46878 commit 2478ee8
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ CHRIS_REMOTE_FS
swarm/prod/secrets
kubernetes/prod/base/secrets
dc.out

# created by `just prefer`
.preference
25 changes: 14 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@ on:
jobs:
test:
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
engine: [ 'docker', 'podman' ]
test-kind: [ 'unit', 'integration' ]
steps:
- uses: actions/checkout@v4
- name: Start podman daemon
if: matrix.engine == 'podman'
run: systemctl --user start podman.service
- uses: taiki-e/install-action@just
- name: Build development image
run: just build
- name: Pull other images
run: just pull
- name: Start ancillary services
run: just start-ancillary
- name: Run unit tests
run: just test-unit
- name: Run integration tests
run: just test-integration
- uses: actions/checkout@v4
- name: Run ${{ matrix.test-kind }} tests on ${{ matrix.engine }}
uses: ./
with:
engine: ${{ matrix.engine }}
command: test-${{ matrix.test-kind }}

build:
needs: [ test ]
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ venv
# created by dev container bc UBI sets HOME to the project src dir
chris_backend/.config
chris_backend/.bash_history

# created by `just prefer`
.preference
59 changes: 58 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The HTTP API primarily supports the [collection+json](http://amundsen.com/media-

Development is mainly supported on Linux. MacOS and WSL on Windows also work (because Docker Desktop is a Linux VM). You will need at least 8GM RAM, 20GB disk space, and a good internet connection.

Install Docker (version 27 or above), Docker Compose, and [just](https://github.com/casey/just?tab=readme-ov-file#installation).
Install Docker (version 27 or above) or Podman (version 5.2 or above), Docker Compose, and [just](https://github.com/casey/just?tab=readme-ov-file#installation).

<details>
<summary>
Expand All @@ -54,6 +54,28 @@ Docker Installation Instructions
</details>

<details>
<summary>
Podman Setup Instructions
</summary>

Rootless Podman is supported. You must install and configure Podman to use `docker-compose`, _not_ `podman-compose`. `podman-compose` is missing features, see issues [#575](https://github.com/containers/podman-compose/issues/575) and [#866](https://github.com/containers/podman-compose/issues/866).

A Podman daemon must be running, because _ChRIS_ runs containers of its own. To start the Podman daemon on Linux, run

```shell
systemctl --user start podman.service
```

If both Podman and Docker are installed, Podman will be used by default. A preference to use either Podman or Docker can be set by running

```shell
just prefer podman # or
just prefer docker
```

</details>

### Just Commands

Development is handled by [`just`](https://just.systems).
Expand Down Expand Up @@ -144,6 +166,41 @@ Old development scripts usage is described in [OLD_DEVELOP.md](./OLD_DEVELOP.md)

See https://chrisproject.org/docs/run/helm

## GitHub Actions

This repository can also be used as a GitHub Actions step for running _CUBE_ integration tests, e.g.

```yaml
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
test:
runs-on: ubuntu-24.04
steps:
- name: Build something else
uses: docker/build-push-action@v6
with:
tags: localhost/fnndsc/pman:dev
load: true
- name: Run ChRIS backend integration tests
uses: FNNDSC/ChRIS_ultron_backEnd@master
# all inputs are optional
with:
engine: docker # or podman
command: test-integration # or test-unit, ...
# optionally change image used for pman, pfcon, or cube
env:
CUBE_IMAGE: localhost/fnndsc/cube:dev
PFCON_IMAGE: localhost/fnndsc/pfcon:dev
PMAN_IMAGE: localhost/fnndsc/pman:dev
```
## Documentation
> [!CAUTION]
Expand Down
23 changes: 23 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: "ChRIS Backend Integration Tests"
description: "Run ChRIS_ultron_backEnd integration tests"
author: "FNNDSC"

inputs:
engine:
description: "Container engine to use (docker or podman)"
required: false
default: "docker"
command:
description: "Just command (e.g. test-all, test-integration, test-unit)"
required: false
default: "test-integration"

runs:
using: node20
pre: githubActions/pre.js
main: githubActions/main.js
post: githubActions/cleanup.js

branding:
color: "blue"
icon: "box"
4 changes: 2 additions & 2 deletions docker-compose_just.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
- tools
volumes:
- "./chrisomatic:/etc/chrisomatic:ro"
- "/var/run/docker.sock:/var/run/docker.sock"
- "${DOCKER_SOCK:-/var/run/docker.sock}:/var/run/docker.sock"
working_dir: /etc/chrisomatic
userns_mode: host
depends_on:
Expand Down Expand Up @@ -139,7 +139,7 @@ services:
SECRET_KEY: secret
REMOVE_JOBS: "yes"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- "${DOCKER_SOCK:-/var/run/docker.sock}:/var/run/docker.sock"
depends_on:
- pfcon
ports:
Expand Down
6 changes: 6 additions & 0 deletions githubActions/cleanup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const child_process = require('child_process');

child_process.execFileSync(
'just', ['nuke'],
{ stdio: 'inherit' }
);
18 changes: 18 additions & 0 deletions githubActions/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const child_process = require('child_process');

const CONTAINER_ENGINE = process.env.INPUT_ENGINE;
const JUST_COMMAND = process.env.INPUT_COMMAND;

const script = `
set -x
just prefer ${CONTAINER_ENGINE}
just ${JUST_COMMAND}
rc=$?
if [ "$rc" != '0' ]; then
just logs
fi
exit $rc
`;

child_process.execFileSync('bash', ['-c', script], { stdio: 'inherit' });

7 changes: 7 additions & 0 deletions githubActions/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const child_process = require('child_process');

child_process.execFileSync(
'sudo',
['apt-get', 'install', '-y', 'just'],
{ stdio: 'inherit' }
);
49 changes: 47 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ test *args:
test-all: test-unit test-integration

# Run unit tests.
test-unit: (run 'python manage.py test --force-color --exclude-tag integration')
test-unit: start-ancillary (run 'python manage.py test --force-color --exclude-tag integration')

# Run integration tests.
test-integration: start-ancillary (run 'python manage.py test --force-color --tag integration')
Expand Down Expand Up @@ -72,10 +72,55 @@ build: (docker-compose '--profile=cube build')
# Pull container images.
pull: (docker-compose 'pull')

# Get container logs.
logs *args:
@just docker-compose --profile=cube logs {{args}}

# docker-compose ... run helper function.
run +command:
@just docker-compose --profile=cube run --rm chris {{command}}

# docker-compose ... helper function.
docker-compose +command:
env UID=$(id -u) GID=$(id -g) docker compose -f '{{ compose_file }}' {{command}}
env UID=$(id -u) GID=$(id -g) DOCKER_SOCK=$(just get-socket) $(just get-engine) compose -f '{{ compose_file }}' {{command}}

# Get the container engine to use (docker or podman)
get-engine:
@if [ -f '.preference' ]; then \
cat .preference && exit 0; \
elif type podman > /dev/null 2>&1; then \
echo podman; \
else \
echo docker; \
fi \

# Get the docker daemon socket
get-socket:
@if [ "$(just get-engine)" = 'podman' ]; then \
just get-podman-socket; \
else \
echo '/var/run/docker.sock'; \
fi

get-podman-socket: check-podman-socket
@podman info --format '{{{{ .Host.RemoteSocket.Path }}'

# Ensure that the podman daemon is running.
check-podman-socket:
@if [ "$(podman info --format '{{{{ .Host.RemoteSocket.Exists }}')" != 'true' ]; then \
echo 'Podman daemon not running. Please run `systemctl --user start podman.service`'; \
exit 1; \
fi

# Set a preference for using either Docker or Podman.
prefer docker_or_podman:
@[ '{{docker_or_podman}}' = 'docker' ] || [ '{{docker_or_podman}}' = 'podman' ] \
|| ( \
>&2 echo 'argument must be either "docker" or "podman"'; \
exit 1 \
)
echo '{{docker_or_podman}}' > .preference

# Remove your preference for Docker or Podman.
unset-preference:
rm -f .preference

0 comments on commit 2478ee8

Please sign in to comment.