Skip to content
Open
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
46 changes: 39 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ This repository contains a collection of source files for building Docker images

This directory contains the source files for building a Perforce Helix core server Docker image. The published Docker images are available as [`sourcegraph/helix-p4d` on Docker Hub](https://hub.docker.com/r/sourcegraph/helix-p4d).

### Default server configuration

- `security` : 2 instead of 4
- `server.depots.root` : `P4DEPOTS`
- `journalPrefix` : `P4CKP/JNL_PREFIX`

### Build the docker image

The `helix-p4d/build.sh` script will build the docker image for you. If you don't provide a tag to the script it will tag the image as `sourcegraph/helix-p4d:latest`
Expand All @@ -21,24 +27,23 @@ To have a disposable Perforce Helix core server running, simply do:
```sh
docker run --rm \
--publish 1666:1666 \
sourcegraph/helix-p4d:2023.1
sourcegraph/helix-p4d:latest
```

The above command makes the server avaialble locally at `:1666`, with a default super user `admin` and its password `pass12349ers`.

#### Environment variables
All available options and their default values:

```sh
NAME=perforce-server
P4HOME=/p4
P4NAME=master
P4NAME=perforce-server
P4TCP=1666
P4PORT=1666
P4USER=admin
P4PASSWD=pass12349ers
P4CASE=-C0
P4CHARSET=utf8
JNL_PREFIX=perforce-server
```

Use the `--env` flag to override default:
Expand All @@ -48,20 +53,25 @@ docker run --rm \
--publish 1666:1666 \
--env P4USER=amy \
--env P4PASSWD=securepassword \
sourcegraph/helix-p4d:2023.1
sourcegraph/helix-p4d:latest
```

> [!WARNING]
> Please be noted that although the server survives over restarts (i.e. data are kept), but it may break if you change the options after the initial bootstrap (i.e. the very first run of the image, at when options are getting hard-coded to the Perforce Helix core server own configuration).

`P4CASE` : `-C0` means Unix-style and `-C1` Windows-style (only these 2 values are valid)
`P4CHARSET` : `none` and `utf8` are the only valid values
`JNL_PREFIX` : prefix for the perforce journal file

#### Volumes
To start a long-running production container, do remember to volume the data directory (`P4HOME`) and replace the `--rm` flag with `-d` (detach):

```sh
docker run -d \
--publish 1666:1666 \
--env P4PASSWD=securepassword \
--volume ~/.helix-p4d-home:/p4 \
sourcegraph/helix-p4d:2023.1
sourcegraph/helix-p4d:latest
```

Now you have a running server, please read our handbook for [how to set up the client side](https://handbook.sourcegraph.com/departments/technical-success/support/process/p4-enablement/).
Expand Down Expand Up @@ -91,6 +101,28 @@ docker run --rm \
sourcegraph/helix-p4d:2023.1
```

### Restore from a checkpoint
With a journal and checkpoint, generate a gz file
Put them in the folder `/p4/checkpoints/` (`$P4CKP`)
Create a simlink to the gz file named latest in the folder `$P4CKP`
Run the container, it will generate the DB from the checkpoint and remove the sym link. The gz can be removed once you're good with it.
Triggers are removed.

## Credits

This repository is heavily inspired by https://github.com/p4paul/helix-docker and https://github.com/ambakshi/docker-perforce.
This repository is heavily inspired by https://github.com/p4paul/helix-docker and https://github.com/ambakshi/docker-perforce

## Fork

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To remove


The fork was done to allow some changes
- Update of the dependancies
- Ubuntu focal to noble (no support for racoon ATM)
- Helix perforce to 2026.1
- Removed helix swarm
- Changed the whole restore checkpoint logic
- Improvements
- Unified folder name
- Unified the use of the setup in each case to configure and start the server
- Use of p4dctl
- Fixes
- Charset when there is no one selected
39 changes: 21 additions & 18 deletions helix-p4d/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,55 +1,58 @@
# --------------------------------------------------------------------------------
# Docker configuration for P4D
# --------------------------------------------------------------------------------

FROM ubuntu:focal
# Ubuntu noble and 24.04 are the same, but noble is the codename for 24.04
FROM ubuntu:24.04

LABEL vendor="Sourcegraph"
LABEL maintainer="Joe Chen (joe@sourcegraph.com)"

# Update Ubuntu and add Perforce Package Source
RUN apt-get update && \
apt-get install -y wget gnupg2 && \
wget -qO - https://package.perforce.com/perforce.pubkey | apt-key add - && \
echo "deb http://package.perforce.com/apt/ubuntu focal release" > /etc/apt/sources.list.d/perforce.list && \
apt-get update
apt-get install -y wget gnupg2

# --------------------------------------------------------------------------------
# Docker BUILD
# --------------------------------------------------------------------------------

# Create perforce user and install Perforce Server
# Do in-page search over https://package.perforce.com/apt/ubuntu/dists/focal/release/binary-amd64/Packages
# for both "Package: helix-p4d" and "Package: helix-swarm-triggers".
RUN apt-get update && apt-get install -y helix-p4d=2024.1-2625008~focal helix-swarm-triggers=2024.3-2628402~focal
# Do in-page search over https://package.perforce.com/apt/ubuntu/dists/noble/release/binary-amd64/Packages
# for "Package: helix-p4d"
# Update Ubuntu and add Perforce Package Source
RUN apt-get update && apt-get install -y wget gnupg && \
wget -qO - https://package.perforce.com/perforce.pubkey | gpg --dearmor -o /etc/apt/keyrings/perforce.gpg && \
echo "deb [signed-by=/etc/apt/keyrings/perforce.gpg] http://package.perforce.com/apt/ubuntu noble release" > /etc/apt/sources.list.d/perforce.list && \
apt-get update && \
apt-get install -y helix-p4d=2026.1-2972966~noble

RUN apt-get remove -y wget gnupg2 && \
apt-get autoremove -y && \
apt-get clean -y && \
rm -rf /var/lib/apt/lists/*

# Add external files
COPY files/restore.sh /usr/local/bin/restore.sh
COPY files/setup.sh /usr/local/bin/setup.sh
COPY files/init.sh /usr/local/bin/init.sh
COPY files/latest_checkpoint.sh /usr/local/bin/latest_checkpoint.sh

RUN \
chmod +x /usr/local/bin/restore.sh && \
chmod +x /usr/local/bin/setup.sh && \
chmod +x /usr/local/bin/init.sh && \
chmod +x /usr/local/bin/latest_checkpoint.sh
chmod +x /usr/local/bin/init.sh

# --------------------------------------------------------------------------------
# Docker ENVIRONMENT
# --------------------------------------------------------------------------------

# Default Environment
ARG NAME=perforce-server
ARG P4NAME=master
ARG P4NAME=perforce-server
ARG P4TCP=1666
ARG P4USER=admin
ARG P4PASSWD=pass12349ers
ARG P4CASE=-C0
ARG P4CHARSET=utf8

# Dynamic Environment
ENV NAME=$NAME \
P4NAME=$P4NAME \
ENV P4NAME=$P4NAME \
P4TCP=$P4TCP \
P4PORT=$P4TCP \
P4USER=$P4USER \
Expand All @@ -76,7 +79,7 @@ VOLUME $P4HOME

ENTRYPOINT \
init.sh && \
/usr/bin/tail -F $P4ROOT/logs/log
/usr/bin/tail -F $P4HOME/logs/log

HEALTHCHECK \
--interval=2m \
Expand Down
29 changes: 18 additions & 11 deletions helix-p4d/files/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,28 @@ mkdir -p "$P4CKP"

# Restore checkpoint if symlink latest exists
if [ -L "$P4CKP/latest" ]; then
echo "Restoring checkpoint..."
echo "[INFO] Restoring checkpoint..."
restore.sh
rm "$P4CKP/latest"
else
echo "Create empty or start existing server..."
echo "[INFO] Server restored"

echo "[INFO] Configuring the server..."
setup.sh
echo "[INFO] Server configured, restart required"
exit 0
fi

# Configure the server on a fresh install when no instance is registered
# Header of p4dctl list and the message when there is no instance are ouput to stderr.
if [ -z "$(p4dctl list 2>/dev/null)" ]; then
echo "[INFO] No existing server configuration detected. Running setup..."
setup.sh
fi

p4 login <<EOF
$P4PASSWD
EOF
# Start the server
echo "[INFO] Starting Server..."
p4dctl start -t p4d "$P4NAME"

echo "Perforce Server starting..."
echo "[INFO] Server [RUNNING] with the following configuration"
until p4 info -s 2> /dev/null; do sleep 1; done
echo "Perforce Server [RUNNING]"

## Remove all triggers
echo "Triggers:" | p4 triggers -i
until p4 configure show 2> /dev/null; do sleep 1; done
16 changes: 0 additions & 16 deletions helix-p4d/files/latest_checkpoint.sh

This file was deleted.

29 changes: 11 additions & 18 deletions helix-p4d/files/restore.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#!/bin/bash

## Test for latest link
if [ ! -L "$P4CKP/latest" ]; then
echo "Link not found - looking for checkpoint"
/usr/local/bin/latest_checkpoint.sh
fi

## Test Checkpoint exists
if [ ! -L "$P4CKP/latest" ]; then
echo "Error: Checkpoint for link $P4CKP/latest not found."
echo "[ERROR] Checkpoint for link $P4CKP/latest not found."
exit 255
fi

## Stop Perforce
#p4 admin stop
#until ! p4 info -s 2> /dev/null; do sleep 1; done
## Check P4CASE environment variable
if [ -z "${P4CASE:-}" ]; then
echo "[ERROR] P4CASE environment variable is not set."
exit 255
fi
if [ "${P4CASE:-}" != "-C0" ] && [ "${P4CASE:-}" != "-C1" ]; then
echo "[ERROR] P4CASE must be set to -C0 (Unix-style) or -C1 (Windows-style)."
exit 255
fi

## Remove current data base
rm -rf $P4ROOT/*
Expand All @@ -23,13 +23,6 @@ rm -rf $P4ROOT/*
echo $P4NAME > $P4ROOT/server.id

## Restore and Upgrade Checkpoint
echo "[INFO] Restoring checkpoint with option $P4CASE"
p4d $P4CASE -r $P4ROOT -jr -z $P4CKP/latest
p4d $P4CASE -r $P4ROOT -xu

## Set key environment variables
p4d $P4CASE -r $P4ROOT "-cset security=2"
p4d $P4CASE -r $P4ROOT "-cset ${P4NAME}#server.depot.root=${P4DEPOTS}"
p4d $P4CASE -r $P4ROOT "-cset ${P4NAME}#journalPrefix=${P4CKP}/${JNL_PREFIX}"

## Start Perforce
p4d $P4CASE -r$P4ROOT -p$P4TCP -L$P4LOG -J$P4JOURNAL -d
81 changes: 72 additions & 9 deletions helix-p4d/files/setup.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,82 @@
#!/bin/bash

if [ ! -d "$P4ROOT/etc" ]; then
echo >&2 "First time installation, copying configuration from /etc/perforce to $P4ROOT/etc and relinking"
mkdir -p "$P4ROOT/etc"
cp -r /etc/perforce/* "$P4ROOT/etc/"
opts=()

# Check P4CHARSET environment variable
if [ -z "${P4CHARSET:-}" ]; then
echo "[ERROR] P4CHARSET environment variable is not set."
exit 255
fi
if [ "${P4CHARSET:-}" != "none" ] && [ "${P4CHARSET:-}" != "utf8" ]; then
echo "[ERROR] P4CHARSET value unknown, expected 'none' or 'utf8'."
exit 255
fi

mv /etc/perforce /etc/perforce.orig
ln -s "$P4ROOT/etc" /etc/perforce
# If P4CHARSET is set to "none", do not pass --unicode. Otherwise include it.
if [ "${P4CHARSET:-}" != "none" ]; then
opts+=(--unicode)
fi

if ! p4dctl list 2>/dev/null | grep -q "$NAME"; then
/opt/perforce/sbin/configure-helix-p4d.sh "$NAME" -n -p "$P4PORT" -r "$P4ROOT" -u "$P4USER" -P "${P4PASSWD}" --case "$P4CASE" --unicode
## Check P4CASE environment variable
if [ -z "${P4CASE:-}" ]; then
echo "[ERROR] P4CASE environment variable is not set."
exit 255
fi
if [ "${P4CASE:-}" != "-C0" ] && [ "${P4CASE:-}" != "-C1" ]; then
echo "[ERROR] P4CASE must be set to -C0 (Unix-style) or -C1 (Windows-style)."
exit 255
fi
if [ "${P4CASE:-}" == "-C1" ]; then
opts+=(--case=1)
else
opts+=(--case=0)
fi

# Script to configure the server with the given param so a p4dctl is created.
# Helper of the script available in it
#-------------------------------------------------------------------------------
# Configuration script for P4 Server
# Copyright 2025, Perforce Software Inc. All rights reserved.
#
# Synopsis:
#
# configure-p4d.sh [service-name] [options]
#
# Where options are:
#
# -n - Use the following flags in non-interactive mode
# -p <P4PORT> - Set P4 Server's address
# -r <P4ROOT> - Set P4 Server's root directory
# -u <username> - P4 super-user login name
# -P <password> - P4 super-user password
# --unicode - Enable unicode mode on server
# --case - Case-sensitivity (0=sensitive[default],1=insensitive)
#
# Password is only needed on initial configuration when the super-user
# account is created. If reconfiguring an existing Perforce Server, the
# super-user name and password are left alone.
#
# Unicode mode is disabled by default. Specify --unicode if you
# want it. This will change in a future release.
#
#-------------------------------------------------------------------------------
/opt/perforce/sbin/configure-helix-p4d.sh "$P4NAME" -n -p "$P4PORT" -r "$P4HOME" -u "$P4USER" -P "${P4PASSWD}" "${opts[@]}"

# Server configuration is set to default security 4, so we need to get a ticket with p4 login to change configuration settings.
p4 login <<EOF
$P4PASSWD
EOF

echo "[INFO] Configuring server settings..."
p4 configure set $P4NAME#security=2
p4 configure set $P4NAME#server.depot.root=$P4DEPOTS
p4 configure set $P4NAME#journalPrefix=$P4CKP/$JNL_PREFIX

p4dctl start -t p4d "$NAME"
# In the case where we restore a checkpoint, we must ensure that triggers are removed
echo "[INFO] Existing triggers :"
p4 triggers -o
echo "[INFO] Removing triggers ..."
echo "Triggers:" | p4 triggers -i

# Stopping the server so the new configuration is taken into account
p4dctl stop -t p4d "$P4NAME"