Skip to content

Commit 253ffaf

Browse files
committed
Lets commit entire git history into an image and update incrementally - create git-cache-updater service & git-cache/update-git-cache.cmd updating dcr.devsh.eu/nabla/source/git-cache:latest with entire Nabla history locally (currently full master only, but I'm going to track all branches there)
1 parent 9f25ce5 commit 253ffaf

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

docker/git-cache/Dockerfile

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# escape=`
2+
3+
ARG BASE_IMAGE=mcr.microsoft.com/windows/servercore:ltsc2022-amd64
4+
5+
FROM ${BASE_IMAGE}
6+
7+
SHELL ["cmd", "/S", "/C"]
8+
9+
RUN `
10+
# Install Chocolatey
11+
`
12+
powershell -Command "Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))"
13+
14+
RUN `
15+
# Install Git
16+
`
17+
choco install -y git --version 2.43.0
18+
19+
RUN `
20+
# Install CMake
21+
`
22+
curl -SL --output cmake.zip https://github.com/Kitware/CMake/releases/download/v3.31.0/cmake-3.31.0-windows-x86_64.zip `
23+
`
24+
&& mkdir "./cmake" `
25+
`
26+
&& tar -xf cmake.zip -C "./cmake" `
27+
`
28+
&& del /q cmake.zip
29+
30+
WORKDIR C:\gitcache
31+
32+
RUN `
33+
# Post environment setup
34+
`
35+
git config --system protocol.*.allow always `
36+
`
37+
&& git config --system url."https://github.com/".insteadOf "git@github.com:" `
38+
`
39+
&& git config --system --add safe.directory * `
40+
`
41+
&& setx THIS_PROJECT_GIT_CACHE "C:\gitcache" `
42+
`
43+
&& git init `
44+
`
45+
&& git remote add origin https://github.com/Devsh-Graphics-Programming/Nabla.git
46+
47+
ENTRYPOINT ["cmd.exe", "/K"]

docker/git-cache/compose.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
services:
2+
git-cache-updater:
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
6+
image: dcr.devsh.eu/nabla/source/git-cache:latest
7+
container_name: git.cache.update

docker/git-cache/update-git-cache.cmd

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
@echo off
2+
REM Set cache image reference
3+
set IMAGE_NAME=dcr.devsh.eu/nabla/source/git-cache:latest
4+
5+
REM Start the git-cache-updater container in detached mode and capture the container ID
6+
set CONTAINER_ID=
7+
for /f "delims=" %%i in ('docker-compose run --remove-orphans -d git-cache-updater') do set CONTAINER_ID=%%i
8+
9+
REM Check if the container started successfully
10+
if "%CONTAINER_ID%"=="" (
11+
echo Failed to start the git-cache-updater container.
12+
exit /b 1
13+
)
14+
15+
echo Started container with ID %CONTAINER_ID%
16+
17+
REM Fetch master commits
18+
docker exec -i -t %CONTAINER_ID% git fetch origin master
19+
if %errorlevel% neq 0 (
20+
echo "Error: git fetch failed"
21+
docker stop %CONTAINER_ID%
22+
exit /b %errorlevel%
23+
)
24+
25+
REM Checkout master. TODO: since it happens at runtime I could loop over /remotes' CURRENT branches and track all history
26+
docker exec -i -t %CONTAINER_ID% git checkout master -f
27+
if %errorlevel% neq 0 (
28+
echo "Error: git checkout failed"
29+
docker stop %CONTAINER_ID%
30+
exit /b %errorlevel%
31+
)
32+
33+
REM Update & checkout submodules with CMake
34+
docker exec -i -t %CONTAINER_ID% "C:\cmake\cmake-3.31.0-windows-x86_64\bin\cmake" -P cmake\submodules\update.cmake
35+
if %errorlevel% neq 0 (
36+
echo "Error: CMake submodule update failed"
37+
docker stop %CONTAINER_ID%
38+
exit /b %errorlevel%
39+
)
40+
41+
REM Stop the container before committing
42+
docker stop %CONTAINER_ID%
43+
if %errorlevel% neq 0 (
44+
echo "Error: failed to stop container"
45+
exit /b %errorlevel%
46+
)
47+
48+
REM Commit the updated container as a new image
49+
docker commit %CONTAINER_ID% %IMAGE_NAME%
50+
if %errorlevel% neq 0 (
51+
echo "Error: failed to commit the container"
52+
exit /b %errorlevel%
53+
)
54+
55+
echo Git cache updated and committed as %IMAGE_NAME%.
56+
57+
REM Remove the update container
58+
docker rm %CONTAINER_ID%
59+
if %errorlevel% neq 0 (
60+
echo "Error: failed to remove the update container"
61+
exit /b %errorlevel%
62+
)
63+
64+
echo Removed %CONTAINER_ID% update container.

0 commit comments

Comments
 (0)