Skip to content

Commit

Permalink
podman: don't use podman in podman but pass a socket
Browse files Browse the repository at this point in the history
By setting `CONTAINER_SOCK` prior to running `podman-compose up` the
socket path is passed into the worker container and `CONTAINER_HOST` is
automatically set. The workers then use `podman` to build images instead
of running it *bare metal*. One should set `PUBLIC_PATH`, too, which
points to the place where to store images and json files.

Signed-off-by: Paul Spooren <mail@aparcar.org>
  • Loading branch information
aparcar committed Sep 20, 2023
1 parent 3026f15 commit 11987a4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ Once Podman works, install `podman-compose`:

Now it's possible to run all services via `podman-compose`:

mkdir -p ./asu-service/public/
# where to store images and json files
export PUBLIC_PATH=$(pwd)/public
# absolute path to podman socket mounted into worker containers
export CONTAINER_SOCK=/run/user/1001/podman/podman.sock
podman-compose up -d

This will start the server, the Podman API container and two workers. The first
Expand Down Expand Up @@ -105,6 +108,8 @@ the dependencies:

#### Running a worker

# podman unix socket (not path), no need to mount anything
export CONTAINER_HOST=unix:///run/user/1001/podman/podman.sock
poetry run rq worker
### API

Expand Down
38 changes: 15 additions & 23 deletions podman-compose.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,52 @@
version: "2"

volumes:
podman-sock:
redis:

services:
server:
image: "localhost/aparcar/asu:latest"
image: "asu:latest"
build:
context: ./
dockerfile: Containerfile
environment:
- REDIS_URL=redis://redis/
volumes:
- "./asu-service/public/:/app/public/:rw"
- ALLOW_DEFAULTS
- PUBLIC_PATH
ports:
- "127.0.0.1:8000:8000"
depends_on:
- redis

worker:
image: "localhost/aparcar/asu:latest"
image: "asu:latest"
build:
context: ./
dockerfile: Containerfile
command: rqworker --url "redis://redis"
command: rqworker
environment:
- CONTAINER_HOST=unix:///tmp/socket/podman.sock
- CONTAINER_HOST=unix://$CONTAINER_SOCK
- REDIS_URL=redis://redis/
volumes:
- ./asu-service/public/:/app/public/:rw
- podman-sock:/tmp/socket/:rw
- $PUBLIC_PATH:$PUBLIC_PATH:rw
- $CONTAINER_SOCK:$CONTAINER_SOCK:rw
depends_on:
- redis
- podman

worker2:
image: "localhost/aparcar/asu:latest"
image: "asu:latest"
build:
context: ./
dockerfile: Containerfile
command: rqworker --url "redis://redis"
command: rqworker
environment:
- CONTAINER_HOST=unix:///tmp/socket/podman.sock
- CONTAINER_HOST=unix://$CONTAINER_SOCK
- REDIS_URL=redis://redis/
volumes:
- ./asu-service/public/:/app/public/:rw
- podman-sock:/tmp/socket/:rw
- $PUBLIC_PATH:$PUBLIC_PATH:rw
- $CONTAINER_SOCK:$CONTAINER_SOCK:rw
depends_on:
- redis
- podman

podman:
image: quay.io/podman/stable
user: podman
volumes:
- podman-sock:/tmp/socket/
command: sh -c "mkdir -p /tmp/socket && podman system service --time=0 unix:///tmp/socket/podman.sock"

redis:
image: "docker.io/redis:alpine"
Expand Down

0 comments on commit 11987a4

Please sign in to comment.