Skip to content

Commit 6dd2f3f

Browse files
authored
Merge pull request #2 from espressif/fix/docker_git
Fix git server in docker image
2 parents 2345e54 + 99a4e2c commit 6dd2f3f

File tree

5 files changed

+142
-17
lines changed

5 files changed

+142
-17
lines changed

.github/workflows/test.yml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: Test and Build
2+
3+
on:
4+
push:
5+
branches: [ master, main ]
6+
pull_request:
7+
branches: [ master, main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Set up Go
16+
uses: actions/setup-go@v4
17+
with:
18+
go-version: '1.21'
19+
20+
- name: Cache Go modules
21+
uses: actions/cache@v3
22+
with:
23+
path: ~/go/pkg/mod
24+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
25+
restore-keys: |
26+
${{ runner.os }}-go-
27+
28+
- name: Download dependencies
29+
run: go mod download
30+
31+
- name: Verify dependencies
32+
run: go mod verify
33+
34+
- name: Build
35+
run: go build -v ./...
36+
37+
- name: Run tests
38+
run: go test -race -coverprofile=coverage.out -covermode=atomic ./...
39+
40+
- name: Run go vet
41+
run: go vet ./...
42+
43+
- name: Run go fmt
44+
run: |
45+
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
46+
echo "Code is not formatted properly:"
47+
gofmt -s -l .
48+
exit 1
49+
fi
50+
51+
docker_and_integration_tests:
52+
runs-on: ubuntu-latest
53+
needs: test
54+
steps:
55+
- uses: actions/checkout@v4
56+
57+
- name: Set up Docker Buildx
58+
uses: docker/setup-buildx-action@v3
59+
60+
- name: Build Docker image
61+
uses: docker/build-push-action@v5
62+
with:
63+
context: .
64+
load: true
65+
tags: git-mirror-server:dev
66+
cache-from: type=gha
67+
cache-to: type=gha,mode=max
68+
69+
- name: Test Docker image
70+
run: |
71+
# Start the container in background
72+
docker run -d --name git-mirror-test \
73+
-v ${{ github.workspace }}/example-config.toml:/config.toml \
74+
git-mirror-server:dev /config.toml
75+
76+
# Wait a bit for the server to start
77+
sleep 5
78+
79+
# Check if container is still running
80+
if ! docker ps | grep git-mirror-test; then
81+
echo "Container failed to start"
82+
docker logs git-mirror-test
83+
exit 1
84+
fi
85+
86+
# Stop the container
87+
docker stop git-mirror-test
88+
docker rm git-mirror-test
89+
90+
- name: Create test config for integration
91+
run: |
92+
cat > test-config.toml << EOF
93+
ListenAddr = ":8080"
94+
BasePath = "/srv/git"
95+
Interval = "10s" # Default update interval for repos
96+
97+
[[repo]]
98+
Name = "github.com/espressif/git-mirror-server.git" # Explicitly set name
99+
Origin = "https://github.com/espressif/git-mirror-server.git"
100+
# Interval = "10s" # Specific interval for this repo (optional)
101+
EOF
102+
103+
- name: Run integration test
104+
run: |
105+
# Start git-mirror-server
106+
docker run -d --name git-mirror-integration \
107+
-p 8080:8080 \
108+
-v ${{ github.workspace }}/test-config.toml:/config.toml \
109+
-v ${{ github.workspace }}/test-git-repos:/srv/git \
110+
git-mirror-server:dev /config.toml
111+
112+
# Wait for server to start and first sync
113+
echo "Waiting for server to start and initial sync..."
114+
sleep 30 # Increased sleep to allow for cloning and initial setup
115+
116+
# Check container logs for any immediate errors
117+
echo "Git mirror server logs:"
118+
docker logs git-mirror-integration
119+
120+
# Test git clone
121+
echo "Testing git clone..."
122+
GIT_TRACE_PACKET=1 GIT_TRACE=1 GIT_CURL_VERBOSE=1 git clone --depth 1 http://localhost:8080/github.com/espressif/git-mirror-server.git test-clone
123+
cd test-clone
124+
git log -1 --oneline

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.21 as builder
1+
FROM golang:1.23 AS builder
22
WORKDIR /app
33

44
COPY go.mod ./
@@ -8,8 +8,8 @@ RUN go mod download
88
COPY *.go ./
99
RUN go build -o /git-mirror
1010

11-
FROM alpine/git
12-
RUN apk add --no-cache libc6-compat
11+
FROM alpine:latest
12+
RUN apk add --no-cache git git-daemon libc6-compat
1313
WORKDIR /
1414
COPY --from=builder /git-mirror git-mirror
1515
ENTRYPOINT [ "/git-mirror" ]

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
# git-mirror - simple Git mirrors
1+
# git-mirror-server - simple Git mirrors
22

3-
`git-mirror` is designed to create and serve read-only mirrors of your Git repositories locally or wherever you choose. A recent GitHub outage reinforces the fact that developers shouldn't be relying on a single remote for hosting code.
3+
`git-mirror` is designed to create and serve read-only mirrors of your Git repositories locally or wherever you choose.
4+
The server uses Git's smart HTTP protocol via `git http-backend` to provide efficient repository access.
45

56
A major design goal of `git-mirror` is that it should just work with as little configuration as possible.
67

78
## Get started
89

9-
Download and extract the latest release from the [releases page](https://github.com/beefsack/git-mirror/releases).
10+
Download and extract the latest release from the [releases page](https://github.com/espressif/git-mirror-server/releases).
1011

1112
Create `config.toml` similar to:
1213

1314
```toml
1415
[[repo]]
15-
Origin = "https://github.com/beefsack/git-mirror.git"
16+
Origin = "https://github.com/espressif/git-mirror-server.git"
1617
```
1718

1819
By default it will update the mirror every **1 minute** and will serve the mirror over HTTP using port **8080**. You can specify as many repos as you want by having multiple `[[repo]]` sections.
@@ -22,15 +23,15 @@ Run `git-mirror` with the path to the config file:
2223
```bash
2324
$ ./git-mirror config.toml
2425
2015/05/07 11:08:06 starting web server on :8080
25-
2015/05/07 11:08:06 updating github.com/beefsack/git-mirror.git
26-
2015/05/07 11:08:08 updated github.com/beefsack/git-mirror.git
26+
2015/05/07 11:08:06 updating github.com/espressif/git-mirror-server.git
27+
2015/05/07 11:08:08 updated github.com/espressif/git-mirror-server.git
2728
```
2829

2930
Now you can clone from your mirror on the default port of `8080`:
3031

3132
```bash
32-
$ git clone http://localhost:8080/github.com/beefsack/git-mirror.git
33-
Cloning into 'git-mirror'...
33+
$ git clone http://localhost:8080/github.com/espressif/git-mirror-server.git
34+
Cloning into 'git-mirror-server'...
3435
Checking connectivity... done.
3536
```
3637

@@ -39,15 +40,15 @@ Checking connectivity... done.
3940
You can run it with docker:
4041

4142
```
42-
docker run --rm -ti -v /your_config/path:/config kumekay/git-mirror /config/config.toml
43+
docker run --rm -ti -v /your_config/path:/config espressif/git-mirror-server /config/config.toml
4344
```
4445

4546
Or with docker compose, for example:
4647

4748
```
4849
services:
4950
git-mirror:
50-
image: kumekay/git-mirror
51+
image: espressif/git-mirror-server
5152
ports:
5253
- "8080:8080"
5354
command: ["/etc/git-mirror/config.toml"]
@@ -61,6 +62,6 @@ services:
6162

6263
See [the example config](example-config.toml) for more advanced configurations.
6364

64-
## Authentication and authorisation
65+
## Authentication and authorization
6566

6667
If you wish to control access to the mirror or specific repositories, consider proxying to `git-mirror` using a web server such as Nginx.

example-config.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ BasePath = "/opt/git-mirror/data"
1010
# An example of a public mirror taking defaults from above. The Name is
1111
# generated from the URL by just taking the host and path.
1212
#
13-
# Will be mirrored at at http://localhost:8080/github.com/beefsack/git-mirror.git
13+
# Will be mirrored at at http://localhost:8080/github.com/espressif/git-mirror-server.git
1414
[[Repo]]
15-
Origin = "https://github.com/beefsack/git-mirror.git"
15+
Origin = "https://github.com/espressif/git-mirror-server.git"
1616

1717
# It is also possible to set custom names for accessing the repos.
1818
#

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
func main() {
1414
// Parse config.
1515
if len(os.Args) != 2 {
16-
log.Fatal("please specify the path to a config file, an example config is available at https://github.com/beefsack/git-mirror/blob/master/example-config.toml")
16+
log.Fatal("please specify the path to a config file, an example config is available at https://github.com/espressif/git-mirror-server/blob/master/example-config.toml")
1717
}
1818
cfg, repos, err := parseConfig(os.Args[1])
1919
if err != nil {

0 commit comments

Comments
 (0)