summaryrefslogtreecommitdiffstatshomepage
path: root/test/integration/docker/git_server
diff options
context:
space:
mode:
authorEgor Tensin <egor@tensin.name>2026-10-14 15:59:48 +0500
committerEgor Tensin <egor@tensin.name>2026-10-14 15:59:48 +0500
commit36dabd454bf137f74ab7c3e372b060a4ded7f284 (patch)
tree8afec689f3e3d2bdfeb5f90bdc859fa4fb1e5840 /test/integration/docker/git_server
parentadd CHANGELOG.md (diff)
downloadcgitize-36dabd454bf137f74ab7c3e372b060a4ded7f284.tar.gz
cgitize-36dabd454bf137f74ab7c3e372b060a4ded7f284.zip
t/i/docker: move SSH setup to git_server
Diffstat (limited to 'test/integration/docker/git_server')
-rw-r--r--test/integration/docker/git_server/Dockerfile20
-rwxr-xr-xtest/integration/docker/git_server/entrypoint.sh64
-rwxr-xr-xtest/integration/docker/git_server/setup.sh68
-rwxr-xr-xtest/integration/docker/git_server/setup_repo.sh30
4 files changed, 138 insertions, 44 deletions
diff --git a/test/integration/docker/git_server/Dockerfile b/test/integration/docker/git_server/Dockerfile
index 97306f9..2d0fbe4 100644
--- a/test/integration/docker/git_server/Dockerfile
+++ b/test/integration/docker/git_server/Dockerfile
@@ -1,24 +1,16 @@
FROM alpine:3.24
-RUN apk add -q --no-cache bash git openssh-server tini && \
+RUN apk add -q --no-cache bash git openssh-client-common openssh-server tini && \
echo 'root:root' | chpasswd && \
- git config --global user.name 'John Doe' && \
- git config --global user.email 'John.Doe@example.com' && \
- git config --global init.defaultBranch main && \
sed -ri 's/^#?PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config
+USER root
WORKDIR /root
-COPY ["ssh_keys/server_key", "/etc/ssh/ssh_host_ed25519_key"]
-COPY ["ssh_keys/server_key.pub", "/etc/ssh/ssh_host_ed25519_key.pub"]
-COPY ["ssh_keys/client_key.pub", "./.ssh/authorized_keys"]
+COPY ["git_server/setup.sh", "./"]
+RUN ./setup.sh
-RUN chmod 0600 -- /etc/ssh/ssh_host_ed25519_key && \
- chmod 0700 -- ./.ssh/ && \
- chmod 0600 -- ./.ssh/authorized_keys
+COPY ["git_server/entrypoint.sh", "/"]
+ENTRYPOINT ["/sbin/tini", "--", "/entrypoint.sh"]
-COPY ["git_server/setup_repo.sh", "./"]
-RUN ./setup_repo.sh
-
-ENTRYPOINT ["/sbin/tini", "--"]
CMD ["/usr/sbin/sshd", "-D"]
diff --git a/test/integration/docker/git_server/entrypoint.sh b/test/integration/docker/git_server/entrypoint.sh
new file mode 100755
index 0000000..03f79e4
--- /dev/null
+++ b/test/integration/docker/git_server/entrypoint.sh
@@ -0,0 +1,64 @@
+#!/usr/bin/env bash
+
+set -o errexit -o nounset -o pipefail
+shopt -s inherit_errexit lastpipe
+
+script_name="$( basename -- "${BASH_SOURCE[0]}" )"
+readonly script_name
+
+dump() {
+ local prefix="${FUNCNAME[0]}"
+ [ "${#FUNCNAME[@]}" -gt 1 ] && prefix="${FUNCNAME[1]}"
+
+ local msg
+ for msg; do
+ echo "$script_name: $prefix: $msg"
+ done
+}
+
+readonly ssh_dir=/ssh
+readonly ssh_client_key="$ssh_dir/client_key"
+readonly ssh_client_password='password'
+
+spawn_ssh_agent() {
+ if ! command -v ssh-agent > /dev/null 2>&1; then
+ dump "could not find ssh-agent" >&2
+ return 1
+ fi
+
+ local output
+ output="$( ssh-agent -s -a "$ssh_dir/agent.sock" )"
+
+ echo "$output"
+ eval "$output"
+
+ if [ -z "${SSH_AGENT_PID:+x}" ]; then
+ dump "could not start ssh-agent" >&2
+ return 1
+ fi
+}
+
+setup_ssh_agent() {
+ echo
+ echo ----------------------------------------------------------------------
+ echo Setting up ssh-agent
+ echo ----------------------------------------------------------------------
+
+ spawn_ssh_agent
+
+ local askpass_path
+ askpass_path="$( mktemp )"
+ chmod 0700 -- "$askpass_path"
+
+ echo "#!/usr/bin/env sh" >> "$askpass_path"
+ printf -- 'echo %q' "$ssh_client_password" >> "$askpass_path"
+
+ SSH_ASKPASS="$askpass_path" SSH_ASKPASS_REQUIRE=force DISPLAY= ssh-add "$ssh_client_key" < /dev/null
+}
+
+main() {
+ setup_ssh_agent
+ exec "$@"
+}
+
+main "$@"
diff --git a/test/integration/docker/git_server/setup.sh b/test/integration/docker/git_server/setup.sh
new file mode 100755
index 0000000..f2572ff
--- /dev/null
+++ b/test/integration/docker/git_server/setup.sh
@@ -0,0 +1,68 @@
+#!/usr/bin/env bash
+
+set -o errexit -o nounset -o pipefail
+shopt -s inherit_errexit lastpipe
+
+readonly ssh_dir=/ssh
+readonly ssh_client_password='password'
+
+configure_git() {
+ echo
+ echo ----------------------------------------------------------------------
+ echo Configuring git
+ echo ----------------------------------------------------------------------
+
+ git config --global user.name 'John Doe'
+ git config --global user.email 'John.Doe@example.com'
+ git config --global init.defaultBranch main
+}
+
+generate_ssh_keys() {
+ echo
+ echo ----------------------------------------------------------------------
+ echo Generating SSH keys
+ echo ----------------------------------------------------------------------
+
+ mkdir -p -- "$ssh_dir"
+
+ ssh-keygen -t rsa -b 4096 -f "$ssh_dir/client_key" -N "$ssh_client_password"
+ ssh-keygen -t rsa -b 4096 -f "$ssh_dir/server_key" -N ''
+
+ mkdir ~/.ssh
+
+ cp "$ssh_dir/server_key" /etc/ssh/ssh_host_ed25519_key
+ cp "$ssh_dir/server_key.pub" /etc/ssh/ssh_host_ed25519_key.pub
+ cp "$ssh_dir/client_key.pub" ~/.ssh/authorized_keys
+
+ chmod 0600 -- /etc/ssh/ssh_host_ed25519_key
+ chmod 0700 -- ~/.ssh/
+ chmod 0600 -- ~/.ssh/authorized_keys
+}
+
+readonly repo_path="$HOME/test_repo"
+
+create_repo() {
+ echo
+ echo ----------------------------------------------------------------------
+ echo Setting up upstream repository
+ echo ----------------------------------------------------------------------
+
+ mkdir -p -- "$repo_path"
+ pushd -- "$repo_path" > /dev/null
+ git init
+ echo '1' > 1.txt
+ git add .
+ git commit -m 'first commit'
+ echo '2' > 2.txt
+ git add .
+ git commit -m 'second commit'
+ popd > /dev/null
+}
+
+main() {
+ configure_git
+ generate_ssh_keys
+ create_repo
+}
+
+main
diff --git a/test/integration/docker/git_server/setup_repo.sh b/test/integration/docker/git_server/setup_repo.sh
deleted file mode 100755
index c5bb32c..0000000
--- a/test/integration/docker/git_server/setup_repo.sh
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/usr/bin/env bash
-
-set -o errexit -o nounset -o pipefail
-shopt -s inherit_errexit lastpipe
-
-readonly local_repo_path="$HOME/test_repo"
-
-setup_local_repo() {
- echo
- echo ----------------------------------------------------------------------
- echo Setting up upstream repository
- echo ----------------------------------------------------------------------
-
- mkdir -p -- "$local_repo_path"
- pushd -- "$local_repo_path" > /dev/null
- git init
- echo '1' > 1.txt
- git add .
- git commit -m 'first commit'
- echo '2' > 2.txt
- git add .
- git commit -m 'second commit'
- popd > /dev/null
-}
-
-main() {
- setup_local_repo
-}
-
-main