From 572937ae81531125624b2782e0c124cdbcb79321 Mon Sep 17 00:00:00 2001 From: Aljaz Ceru Date: Thu, 1 Feb 2024 10:11:59 +0000 Subject: [PATCH 1/4] adding -s to display shared repos --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index c84c4f7..03e8c68 100644 --- a/Readme.md +++ b/Readme.md @@ -80,7 +80,7 @@ Collaboration is possible with the following flow between Alice and Bob in a pee ``` cd Repo git pear init -s -git pear list +git pear list -s # outputs: # Repo pear:///Repo ``` From 4ddc50f3667e4611f2c8be0cc1913a9434a8648f Mon Sep 17 00:00:00 2001 From: Aljaz Ceru Date: Fri, 9 Feb 2024 14:23:08 +0000 Subject: [PATCH 2/4] docker and http --- Dockerfile | 35 +++++++++++++++++++++++++++++++++++ default | 18 ++++++++++++++++++ entrypoint.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 Dockerfile create mode 100644 default create mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..da9e48a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,35 @@ +# Use the official Node.js image as the base image +FROM node:latest + +# install nginx +RUN apt-get update && apt-get install -y nginx git fcgiwrap spawn-fcgi +ENV GIT_PEAR=/srv/repos/pear +EXPOSE 80 +STOPSIGNAL SIGTERM +# Set the working directory inside the container +WORKDIR /app + +# Clone the gitpear repository from GitHub +RUN git clone https://github.com/dzdidi/gitpear.git + +# Change the working directory to the gitpear directory +WORKDIR /app/gitpear + +# Install the dependencies using npm +RUN npm install + +# Link the gitpear package globally +RUN npm link + +RUN mkdir -p /srv/repos/pear + + +COPY default /etc/nginx/sites-enabled/default + +WORKDIR /app +COPY entrypoint.sh . +RUN chmod +x entrypoint.sh + +ENTRYPOINT ["/bin/bash", "-c", "/app/entrypoint.sh"] + + diff --git a/default b/default new file mode 100644 index 0000000..a9a71d1 --- /dev/null +++ b/default @@ -0,0 +1,18 @@ +server { + listen 80; + server_name _; + + # This is where the repositories live on the server + root /srv/repos/pear; + + + location ~ (/.*) { + fastcgi_pass unix:/var/run/fcgiwrap.socket; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend; + # export all repositories under GIT_PROJECT_ROOT + fastcgi_param GIT_HTTP_EXPORT_ALL ""; + fastcgi_param GIT_PROJECT_ROOT /srv/repos/pear; + fastcgi_param PATH_INFO $1; + } +} diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..560b1af --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# if $1 includes an url +exec > >(tee -a "/tmp/deployment.log") 2>&1 + +export GIT_PEAR=/srv/repos/pear +git pear daemon -s +# if $1 exists +if [ -n "$1" ]; then + REPO_NAME=$1 +fi + + + +if [[ $REPO_NAME =~ ^https.* ]]; then + ORIGINAL_NAME=$(basename $REPO_NAME .git) + mkdir -p /srv/repos/"$ORIGINAL_NAME" + git clone $REPO_NAME /srv/repos/"$ORIGINAL_NAME" + cd /srv/repos/"$ORIGINAL_NAME" + git pear init -s +# enter pear repo and expose http + cd /srv/repos/pear/"$ORIGINAL_NAME"/ + echo "[http]" >> config + echo " receivepack = true" >> config +fi + + +if [[ ! $REPO_NAME =~ ^https.* ]]; then + mkdir -p /srv/repos/"$REPO_NAME" + cd /srv/repos/"$REPO_NAME" + git init + git pear init -s + # enter pear repo and expose http + cd /srv/repos/pear/"$REPO_NAME"/ + echo "[http]" >> config + echo " receivepack = true" >> config +# git config --bool core.bare true +fi +echo "REPO_NAME: $REPO_NAME" >> /tmp/debug.log +echo "ORIGINAL_NAME: $ORIGINAL_NAME" >> /tmp/debug.log +echo "GIT_PEAR: $GIT_PEAR" >> /tmp/debug.log +echo "PEAR_KEY: $PEAR_KEY" >> /tmp/debug.log +echo "PEAR_REPO: $PEAR_REPO" >> /tmp/debug.log + +/etc/init.d/fcgiwrap start +chmod 766 /var/run/fcgiwrap.socket +nginx -g "daemon off;" \ No newline at end of file From 5905c024598e9cd834b1f8eb2585aaccdcaeccc3 Mon Sep 17 00:00:00 2001 From: Aljaz Ceru Date: Fri, 9 Feb 2024 15:19:07 +0000 Subject: [PATCH 3/4] debug --- entrypoint.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 560b1af..38f14a6 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -35,6 +35,8 @@ if [[ ! $REPO_NAME =~ ^https.* ]]; then echo " receivepack = true" >> config # git config --bool core.bare true fi +PEAR_KEY=$(git pear key) +PEAR_REPO=$(git pear list -s) echo "REPO_NAME: $REPO_NAME" >> /tmp/debug.log echo "ORIGINAL_NAME: $ORIGINAL_NAME" >> /tmp/debug.log echo "GIT_PEAR: $GIT_PEAR" >> /tmp/debug.log @@ -43,4 +45,4 @@ echo "PEAR_REPO: $PEAR_REPO" >> /tmp/debug.log /etc/init.d/fcgiwrap start chmod 766 /var/run/fcgiwrap.socket -nginx -g "daemon off;" \ No newline at end of file +nginx -g "daemon off;" From f76db09acf908b2b1f1e07fd2c9e206dedc13b1f Mon Sep 17 00:00:00 2001 From: Aljaz Ceru Date: Fri, 9 Feb 2024 15:25:40 +0000 Subject: [PATCH 4/4] documentation update for docker --- Readme.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Readme.md b/Readme.md index b774027..a88e2b2 100644 --- a/Readme.md +++ b/Readme.md @@ -165,3 +165,15 @@ Supported authentication methods are `native` and `nip98`. The `nip98` authentic * `git fetch pear` 2. From there she can do * `git diff pear/feat/david` or `git pull pear feat/david` ... merge to master and push to `pear` + + +## Migrate existing public repository to gitpear +Docker image automatically clones the repository and exposes it over http and pear. + +Example: +``` +git clone https://github.com/dzdidi/gitpear.git +cd gitpear +docker build -t gitpear . +docker run -it -p 80:80 -e REPO_URL=https://github.com/dzdidi/repo.git gitpear +``` \ No newline at end of file