Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ops-git): docker image for mirroring git repos #696

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions docker/ops-agent/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ FROM --platform=$TARGETPLATFORM jenkins/agent:latest-jdk17
ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG DOCKER_GID=996
ARG GIT_GID=1049

COPY --from=0 /usr/bin/yq /usr/bin/yq
COPY ./requirements.txt /home/jenkins/requirements.txt
Expand Down Expand Up @@ -59,6 +60,8 @@ RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then ARCHITECTURE="amd64"; elif [
&& curl -L https://github.com/regclient/regclient/releases/latest/download/regctl-linux-$ARCHITECTURE > /usr/bin/regctl \
&& chmod 755 /usr/bin/regctl

RUN groupadd -g $GIT_GID git && usermod -a -G git jenkins

USER jenkins
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
RUN mkdir -p /home/jenkins/.ansible/cp
Expand Down
25 changes: 25 additions & 0 deletions docker/ops-git/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM --platform=$TARGETPLATFORM jitsi/base:unstable
ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG GIT_UID=1046
ARG GIT_GID=1049

RUN apt-get update && apt-get -y install openssh-server openssh-client git cron sudo

RUN mkdir /run/sshd

RUN addgroup --gid $GIT_GID git && \
adduser --quiet --disabled-password --uid $GIT_UID --gid $GIT_GID git

RUN mkdir /home/git/.ssh && \
chmod 700 /home/git/.ssh

COPY rootfs /

USER root

VOLUME /home/git

EXPOSE 22

ENTRYPOINT [ "/init" ]
5 changes: 5 additions & 0 deletions docker/ops-git/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

# last tag 0.0.1
CACHE_FLAG="--no-cache"
docker buildx build $CACHE_FLAG --platform=linux/arm64,linux/amd64 --push --pull --progress=plain --tag aaronkvanmeerten/ops-git:$TAG --tag aaronkvanmeerten/ops-git:latest .
3 changes: 3 additions & 0 deletions docker/ops-git/rootfs/etc/cont-init.d/11-update-cron
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/with-contenv bash

echo '* * * * * /usr/bin/timeout 50 /opt/jitsi/update-repos.sh > /tmp/update.log 2>&1' | crontab -u git -
3 changes: 3 additions & 0 deletions docker/ops-git/rootfs/etc/services.d/20-ssh/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/with-contenv bash

exec /usr/sbin/sshd -D -e
3 changes: 3 additions & 0 deletions docker/ops-git/rootfs/etc/services.d/60-cron/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/with-contenv bash

exec cron -f
5 changes: 5 additions & 0 deletions docker/ops-git/rootfs/etc/services.d/70-tail/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/with-contenv bash

touch /tmp/update.log
chmod 777 /tmp/update.log
exec tail -f /tmp/update.log
45 changes: 45 additions & 0 deletions docker/ops-git/rootfs/opt/jitsi/update-repos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
export GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
eval "$(ssh-agent -s)"
trap "kill $SSH_AGENT_PID" exit

ssh-add ~/.ssh/id_rsa
set -x
UPDATE_DIR="/tmp/update"


cd /home/git/jitsi/infra-configuration.git
git pull

cd /home/git/jitsi/infra-provisioning.git
git pull

cd /home/git/jitsi/infra-customizations-private.git
git pull

mkdir -p $UPDATE_DIR
cd $UPDATE_DIR

/usr/bin/git clone --mirror [email protected]:jitsi/infra-configuration.git
cd infra-configuration.git
git remote set-url --push origin git@localhost:jitsi/infra-configuration.git
git fetch -p origin
git push --mirror
cd ..

/usr/bin/git clone --mirror [email protected]:jitsi/infra-provisioning.git
cd infra-provisioning.git
git remote set-url --push origin git@localhost:jitsi/infra-provisioning.git
git fetch -p origin
git push --mirror
cd ..

/usr/bin/git clone --mirror [email protected]:jitsi/infra-customizations-private.git
cd infra-customizations-private.git
git remote set-url --push origin git@localhost:jitsi/infra-customizations-private.git
git fetch -p origin
git push --mirror
cd ..

cd
rm -rf $UPDATE_DIR
3 changes: 3 additions & 0 deletions docker/ops-jenkins/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ ARG BUILDPLATFORM
FROM --platform=$TARGETPLATFORM jenkins/jenkins:lts-jdk17
ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG GIT_GID=1049
COPY --from=0 /usr/bin/yq /usr/bin/yq
COPY ./requirements.txt /home/jenkins/requirements.txt
COPY ./plugins.txt /home/jenkins/plugins.txt
Expand All @@ -27,5 +28,7 @@ RUN apt-get -y install docker-ce docker-ce-cli containerd.io docker-compose-plug
RUN usermod -a -G docker jenkins && usermod -a -G shadow jenkins
RUN adduser -q --disabled-password --gecos "" ubuntu && mkdir /home/ubuntu/.ssh && chown ubuntu /home/ubuntu/.ssh
RUN mkdir -p /home/jenkins/triggers && touch /home/jenkins/triggers/reconfigure-users-jenkins && chown -R jenkins:jenkins /home/jenkins/triggers
RUN groupadd -g $GIT_GID git && usermod -a -G git jenkins

USER jenkins
RUN jenkins-plugin-cli --plugin-file /home/jenkins/plugins.txt