Skip to content

Commit

Permalink
Add private repo hack script
Browse files Browse the repository at this point in the history
  • Loading branch information
Blair Drummond authored and blair drummond committed Oct 10, 2021
1 parent 7830702 commit be7bd9b
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
1 change: 1 addition & 0 deletions hack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This directory contains several scripts useful in the development process of Shi
- `install-kubectl.sh` Install the kubectl command line.
- `install-registry.sh` Install the local container registry in the KinD cluster.
- `install-tekton.sh` Install the latest verified Tekton Pipeline release.
- `install-private-repo.sh` Install a "private repo" (sample-nodejs) as a ssh-gitserver inside kind.
- `release.sh` Creates a new release of Shipwright Build.
- `update-codegen.sh` Updates auto-generated client libraries.
- `verify-codegen.sh` Verifies that auto-generated client libraries are up-to-date.
101 changes: 101 additions & 0 deletions hack/install-private-repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/bin/bash

# Copyright The Shipwright Contributors
#
# SPDX-License-Identifier: Apache-2.0

#
# Installs a private git repo into the cluster (for testing private repo builds)
#

set -eu

DOCKER_PRIVATE_REPO_IMAGE=private-git-repo-test
KIND_CLUSTER_NAME="${KIND_CLUSTER_NAME:-kind}"

tmp_dir=$(mktemp -d -t ssh-XXXXXXXXXX)
trap "rm -rf $tmp_dir" EXIT

ssh-keygen -b 2048 -t rsa -f $tmp_dir/sshkey -q -N ""

echo "# Building a private repo docker image..."

# The Dockerhub repo
# https://hub.docker.com/r/jkarlos/git-server-docker/
cat <<EOF | docker build -t $DOCKER_PRIVATE_REPO_IMAGE -
FROM docker.io/jkarlos/git-server-docker
RUN echo "$(cat ${tmp_dir}/sshkey.pub)" > /git-server/keys/sshkey.pub \
&& chmod 600 /git-server/keys/sshkey.pub
RUN git clone https://github.com/shipwright-io/sample-nodejs \
/git-server/repos/sample-nodejs.git
WORKDIR /git-server/
EOF

echo "# Loading into kind..."
kind load docker-image $DOCKER_PRIVATE_REPO_IMAGE --name $KIND_CLUSTER_NAME

echo "# Deploying Git Server..."
cat <<EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
name: gitserver
labels:
app: gitserver
spec:
selector:
matchLabels:
app: gitserver
replicas: 1
template:
metadata:
labels:
app: gitserver
spec:
containers:
- name: gitserver
image: $DOCKER_PRIVATE_REPO_IMAGE
imagePullPolicy: IfNotPresent
ports:
- name: ssh
containerPort: 22
---
apiVersion: v1
kind: Service
metadata:
name: gitserver
spec:
ports:
- name: ssh
port: 22
targetPort: 22
selector:
app: gitserver
---
apiVersion: v1
kind: Secret
metadata:
name: ${DOCKER_PRIVATE_REPO_IMAGE}-secret
type: kubernetes.io/ssh-auth
data:
ssh-privatekey: "$(cat ${tmp_dir}/sshkey | base64 | sed 's/$/\\n/' | tr -d '\n')"
EOF

kubectl rollout restart deployment gitserver

# The GIT_SSH_COMMAND magic
# https://stackoverflow.com/a/29754018

cat <<EOF
# To clone from this repo, run
#
# > kubectl get secrets private-git-repo-test-secret -o json | jq -r '.data[]' | base64 -d > sshkey
# > chmod 600 sshkey
# > kubectl port-forward svc/gitserver 2222:22
# > GIT_SSH_COMMAND='ssh -i sshkey -o IdentitiesOnly=yes -o StrictHostKeyChecking=no' \
# git clone ssh://git@localhost:2222/git-server/repos/sample-private-repo.git
#
EOF

0 comments on commit be7bd9b

Please sign in to comment.