diff --git a/README.md b/README.md index f15d40a..12d02ea 100644 --- a/README.md +++ b/README.md @@ -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` @@ -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: @@ -48,12 +53,17 @@ 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 @@ -61,7 +71,7 @@ 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/). @@ -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 + +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 diff --git a/helix-p4d/Dockerfile b/helix-p4d/Dockerfile index ce6b520..36c57d2 100644 --- a/helix-p4d/Dockerfile +++ b/helix-p4d/Dockerfile @@ -1,46 +1,50 @@ # -------------------------------------------------------------------------------- # 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 @@ -48,8 +52,7 @@ ARG P4CASE=-C0 ARG P4CHARSET=utf8 # Dynamic Environment -ENV NAME=$NAME \ - P4NAME=$P4NAME \ +ENV P4NAME=$P4NAME \ P4TCP=$P4TCP \ P4PORT=$P4TCP \ P4USER=$P4USER \ @@ -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 \ diff --git a/helix-p4d/files/init.sh b/helix-p4d/files/init.sh index 405913c..b017036 100644 --- a/helix-p4d/files/init.sh +++ b/helix-p4d/files/init.sh @@ -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 < /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 diff --git a/helix-p4d/files/latest_checkpoint.sh b/helix-p4d/files/latest_checkpoint.sh deleted file mode 100644 index 5466195..0000000 --- a/helix-p4d/files/latest_checkpoint.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -## Find latest checkpoint -unset -v latest -for file in "$P4CKP"/"$JNL_PREFIX".ckp.*.gz; do - [[ $file -nt $latest ]] && latest=$file -done - -## If file exists update symlink -if [ "$latest" ]; then - echo "Updating latest symlink to: $latest" - ln -f -s "$latest" "$P4CKP/latest" -else - echo "Error: Unable to find a checkpoint" - exit 255 -fi diff --git a/helix-p4d/files/restore.sh b/helix-p4d/files/restore.sh index c132cff..3924535 100644 --- a/helix-p4d/files/restore.sh +++ b/helix-p4d/files/restore.sh @@ -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/* @@ -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 diff --git a/helix-p4d/files/setup.sh b/helix-p4d/files/setup.sh index 615b6d0..0b04101 100644 --- a/helix-p4d/files/setup.sh +++ b/helix-p4d/files/setup.sh @@ -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 - Set P4 Server's address +# -r - Set P4 Server's root directory +# -u - P4 super-user login name +# -P - 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 <