Skip to content

Commit

Permalink
Issue 6077 - Provide a Development Container
Browse files Browse the repository at this point in the history
Bug Description:
It would be nice if we had a quick, easy, repeatable, and portable way
to build and run this project - specifically in a container.

Fix Description:
A container specifically intended for getting contributors up and
running quickly from anywhere so they can test their PRs.

Fixes: #6077
  • Loading branch information
slominskir committed Feb 12, 2024
1 parent 8fe7586 commit 0bcfd69
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dockerComposeFile": "dev.yaml",
"service": "dirsrv",
"workspaceFolder": "/389-ds-base"
}
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,9 @@ vendor.tar.gz
.history
.vscode/launch.json
.cargo/config
/rs/
/rust-nsslapd-private.h
/rust-slapi-private.h
/src/lib389/setup.py
/.env
/dev-overrides.env
12 changes: 12 additions & 0 deletions Containerfile-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM quay.io/389ds/devcontainer
ARG CUSTOM_CRT_URL

ARG CUSTOM_CRT_URL

RUN if [ -z "$CUSTOM_CRT_URL" ] ; then echo "No custom cert needed"; else \
curl -o /etc/pki/ca-trust/source/anchors/customcert.crt $CUSTOM_CRT_URL \
&& update-ca-trust \
; fi \
&& dnf install -y openssl nss-tools libasan


45 changes: 45 additions & 0 deletions DEV_CONTAINER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 389 Directory Server Development Container

## What is this for?
The Development Container simplifies building and running the 389 Directory Server from anywhere including Windows, Mac, and Linux by leveraging a container. The environment is therefore already setup with the correct tools and tool versions to build and run.

## How does it work
You need to have a local container runtime such as [Docker Desktop](https://www.docker.com/products/docker-desktop/), [Podman](https://podman.io/), or [Kubernetes](https://kubernetes.io/). [Docker Compose](https://docs.docker.com/compose/) is recommended as well to simplify commands, and avoid long repetitive command lines, but not strictly required. If you don't have Docker Compose you will need to examine the `dev.yaml` and translate to container run commands. Container run commands with Kubernetes also [requires translation](https://kubernetes.io/docs/reference/kubectl/docker-cli-to-kubectl/).

By default, the project directory is bind mounted into the container such that changes can be made on the local workstation using your favorite IDE. Other modes of operation are possible such as editing in-container or using remote development tooling such as [VS Code](https://code.visualstudio.com/docs/remote/remote-overview) or [IntelliJ](https://www.jetbrains.com/remote-development/).

## Get and start development container:
```
git clone https://github.com/389ds/389-ds-base
cd 389-ds-base
docker compose -f dev.yaml up
```

## Build and Run inside the container:
```
docker exec -it bash dirsrv
cd 389-ds-base
./build.sh
/usr/libexec/dirsrv/dscontainer -r &
# Or run dsctl, etc.
```

## Configure:
You can configure the development container using environment variables. Create a [dev-overrides.env](https://docs.docker.com/compose/environment-variables/set-environment-variables/) file in the project root.

Container Runtime Environment Variables:

| Name | Description | Default |
|------------------|-------------------------------------------------------|-------------------|
| CC | C compiler | gcc |
| CXX | C++ compiler | g++ |
| CFLAGS | C compiler flags | "-O2 -g" |
| CXXFLAGS | C++ compiler flags | |
| LDFLAGS | Linker flags | |
| DS_BACKEND_NAME | Development database backend | example |
| DS_DM_PASSWORD | Development Directory Manager password | password |
| DS_START_TIMEOUT | Number of seconds to start dscontainer before timeout | 60 |
| DS_STOP_TIMEOUT | Number of seconds to stop dscontainer before timeout | 60 |
| DS_SUFFIX_NAME | Development database suffix | dc=example,dc=com |

The development container actually runs a container build and at container build-time you can set environment variables by creating a `.env` file. At the moment the only build time environment variable is "CUSTOM_CRT_URL", which can be used to set a self-signed cert URL to thwart corporate TLS proxies.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ Building

Note: **--enable-asan** is optional, and it should only be used for debugging/development purposes.

See also full [building guide](https://www.port389.org/docs/389ds/development/building.html).
See also:
- Full [Building Guide](https://www.port389.org/docs/389ds/development/building.html)
- Portable [Development Container guide](https://github.com/389ds/389-ds-base/blob/main/DEV_CONTAINER.md)

Testing
-------
Expand Down
9 changes: 9 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -e

autoreconf -fiv
./configure --enable-debug --with-openldap --enable-cmocka --enable-asan
make
make lib389
make install
make lib389-install
8 changes: 8 additions & 0 deletions dev-defaults.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CC=gcc
CXX=g++
CFLAGS="-O2 -g"
CXXFLAGS=""
LDFLAGS=""
DS_DM_PASSWORD=password
DS_SUFFIX_NAME=dc=example,dc=com
DS_BACKEND_NAME=example
23 changes: 23 additions & 0 deletions dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
services:
dirsrv:
build:
context: .
dockerfile: Containerfile-dev
args:
CUSTOM_CRT_URL: ${CUSTOM_CRT_URL}
hostname: dirsrv
container_name: dirsrv
ports:
- "3389:3389"
- "3636:3636"
init: true
entrypoint: ["sleep", "infinity"]
cap_add:
- SYS_PTRACE
env_file:
- path: ./dev-defaults.env
required: true
- path: ./dev-overrides.env
required: false
volumes:
- ./:/389-ds-base

0 comments on commit 0bcfd69

Please sign in to comment.