Skip to content

docker: switch to a 2-stage build and provide an Alpine-based alternative#161

Open
jwarnier wants to merge 6 commits into
OpenSIPS:masterfrom
jwarnier:docker/multistage-build
Open

docker: switch to a 2-stage build and provide an Alpine-based alternative#161
jwarnier wants to merge 6 commits into
OpenSIPS:masterfrom
jwarnier:docker/multistage-build

Conversation

@jwarnier

@jwarnier jwarnier commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Switch to a 2-stage Docker build: a builder stage installs opensips-cli from latest master, the final stage receives only the installed library tree and script — git and build artifacts are not shipped in the published image
  • Pre-compile Python bytecode (compileall) in the final stage for ~30–40 ms faster startup
  • Add an Alpine-based variant (Dockerfile.alpine) following the same 2-stage pattern
  • Rename Makefile build target to build-debian, add build-alpine, keep build as a backwards-compatible alias
  • Update docker.md to document all build targets
  • Use --no-cache-dir for pip, COPY instead of ADD, drop redundant USER root and PYTHONPATH
  • Update CI workflow to build and push the Alpine image alongside the Debian one, tagged as alpine on both Docker Hub and GHCR
  • Remove bashisms from run.sh: switch shebang to #!/bin/sh, replace [[ ]] with [ ], here-strings with echo | cut, and glob matching with case
  • Drop bash from the Alpine image entirely — run.sh is now POSIX sh-compatible and requires no extra packages

Image size comparison (linux/amd64)

Image Size
Alpine 2-stage + compileall (Dockerfile.alpine) ~100 MB
Debian 2-stage + compileall (Dockerfile) 171 MB
Original single-stage Debian (before this PR) 299 MB

Test plan

  • make build-debian builds successfully
  • make build-alpine builds successfully
  • make build still works (backwards-compatible alias)
  • docker run opensips/opensips-cli:latest -x mi exits with "Is OpenSIPS running?" (not an import error)
  • docker run opensips/opensips-cli:alpine -x mi same
  • CI pushes both latest and alpine tags to Docker Hub and GHCR on merge

🤖 Generated with Claude Code

jwarnier and others added 6 commits June 24, 2026 17:59
Use a builder stage to install opensips-cli from latest master, then
copy only the installed library tree and script into the final image.
This avoids shipping git and build artifacts in the published image.

Also: use --no-cache-dir for pip, COPY instead of ADD, drop redundant
USER root and PYTHONPATH, and make the base image configurable via
--build-arg BASE_IMAGE=.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds ~30-40ms startup improvement measured on repeated runs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add Dockerfile.alpine using the same 2-stage pattern as the Debian
image, cutting the image size from 171 MB to 101 MB on amd64.

Rename Makefile 'build' target to 'build-debian', add 'build-alpine',
and keep 'build' as a backwards-compatible alias for 'build-debian'.

Update docker.md to document all build targets.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Switch shebang to #!/bin/sh and replace bash-specific constructs:
[[ ]] -> [ ], here-strings -> echo | cut, glob matching -> case.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
run.sh is now POSIX sh-compatible, so the Alpine image no longer needs
the bash package. Update docker.md to reflect that .sh scripts are run
via sh (not bash) and note the Alpine image ships no extra packages.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jwarnier jwarnier changed the title docker: switch to a 2-stage build docker: switch to a 2-stage build and provide an Alpine-based alternative Jun 24, 2026
@jwarnier jwarnier marked this pull request as ready for review June 24, 2026 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant