Skip to content

Commit ca7d675

Browse files
committed
feat: adding repo server docker file
1 parent 08e318a commit ca7d675

14 files changed

Lines changed: 352 additions & 266 deletions

File tree

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ jobs:
2525
artifact_suffix: ""
2626
runs-on: ${{ matrix.os }}
2727
steps:
28-
- uses: actions/checkout@master
28+
- uses: actions/checkout@v4
2929
- uses: actions/setup-go@v5
3030
with:
31-
go-version: 1.19
31+
go-version: 1.24
3232
- name: golang build
3333
env:
3434
GOARCH: ${{ matrix.arch }}

.github/workflows/golang-tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ jobs:
1919
- uses: actions/setup-go@v5
2020
with:
2121
go-version: 1.19
22+
- name: start soft-serve
23+
run: ./hack/soft-serve/start.sh
2224
- name: run golang tests
2325
env:
2426
SOPS_AGE_KEY_FILE: ${{ github.workspace }}/test_assets/keys.txt

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ main
2121
gitops
2222
# Actually... dont ignore gitops directory
2323
!cmd/gitops/
24+
!docker/gitops/
2425

2526
# Created by https://www.toptal.com/developers/gitignore/api/go,visualstudiocode,goland+all
2627
# Edit at https://www.toptal.com/developers/gitignore?templates=go,visualstudiocode,goland+all

cmd/gitops/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,12 @@ func main() {
259259
Usage: "SSH key passphrase for authenticating against the GitOps repository",
260260
EnvVars: []string{"GITOPS_REPOSITORY_SSH_KEY_PASSPHRASE"},
261261
},
262+
&cli.StringFlag{
263+
Name: "actor",
264+
Value: "",
265+
Usage: "Username of the actor to be used for the commit",
266+
EnvVars: []string{"GITOPS_ACTOR"},
267+
},
262268
},
263269
Action: func(c *cli.Context) error {
264270
initApplication(c)

cmd/repo-server/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"os"
5+
"time"
56

67
"github.com/rs/zerolog/log"
78

@@ -27,11 +28,14 @@ func main() {
2728
if err != nil {
2829
log.Panic().Err(err).Msg("error initializing git connection")
2930
}
31+
log.Info().Msg("Cloning git repository")
32+
startTime := time.Now()
3033

3134
err = gitConnection.Clone()
3235
if err != nil {
3336
log.Panic().Err(err).Msg("error cloning git repository")
3437
}
38+
log.Info().Msgf("Cloned git repository in %s", time.Since(startTime))
3539

3640
gitPatcher, err := patch.NewGitPatcher(&patch.GitPatcherOptions{
3741
GitConnection: gitConnection,
@@ -59,6 +63,7 @@ func main() {
5963
server.RegisterMiddlewares()
6064
server.RegisterRoutes()
6165

66+
log.Info().Msgf("Starting server on port %d", config.Get().Int("PORT"))
6267
err = server.Run()
6368
if err != nil {
6469
log.Panic().Err(err).Msg("error running server")

Dockerfile renamed to docker/gitops/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.20-alpine3.17 AS builder
1+
FROM golang:1.24-alpine3.20 AS builder
22
RUN apk add --no-cache git
33

44
WORKDIR /usr/src
@@ -12,7 +12,7 @@ COPY internal internal
1212
WORKDIR /usr/src/cmd/gitops
1313
RUN go build -o gitops -ldflags="-s -w" .
1414

15-
FROM alpine:3.17
15+
FROM alpine:3.20
1616
WORKDIR /usr/bin
1717
COPY --from=builder /usr/src/cmd/gitops/gitops .
1818
ENTRYPOINT ["/usr/bin/gitops"]

docker/repo-server/Dockerfile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
FROM golang:1.24-alpine AS builder
2+
3+
RUN apk add --no-cache \
4+
build-base \
5+
cmake \
6+
openssl-dev \
7+
libssh2-dev \
8+
zlib-dev \
9+
curl \
10+
git
11+
12+
WORKDIR /tmp
13+
RUN curl -L https://github.com/libgit2/libgit2/archive/refs/tags/v1.5.0.tar.gz | tar xz && \
14+
cd libgit2-1.5.0 && \
15+
cmake . -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=/usr && \
16+
cmake --build . --target install
17+
18+
WORKDIR /go/src/github.com/libgit2
19+
RUN git clone https://github.com/libgit2/git2go.git && \
20+
cd git2go && \
21+
git checkout v34.0.0 && \
22+
git submodule update --init
23+
24+
ENV CGO_CFLAGS="-I/usr/include"
25+
ENV CGO_LDFLAGS="-L/usr/lib -lz -lssl -lcrypto"
26+
ENV LD_LIBRARY_PATH="/usr/lib"
27+
28+
WORKDIR /usr/src
29+
COPY go.mod /usr/src/go.mod
30+
COPY go.sum /usr/src/go.sum
31+
RUN go mod download
32+
33+
COPY cmd cmd
34+
COPY internal internal
35+
36+
WORKDIR /usr/src/cmd/repo-server
37+
RUN go build -o repo-server -ldflags="-s -w" .
38+
39+
FROM alpine:3.21
40+
WORKDIR /usr/bin
41+
COPY --from=builder /usr/src/cmd/repo-server/repo-server .
42+
ENTRYPOINT ["/usr/bin/repo-server"]
43+
EXPOSE 8080

internal/git/git.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func NewGitConnection(options *ConnectionOptions) (*Connection, error) {
6767

6868
if options.Signature == nil {
6969
connection.Options.Signature = &Signature{
70-
Name: "GitOps CI User",
70+
Name: "GitOps CLI CI User",
7171
Email: "gitops@example.com",
7272
}
7373
} else {

0 commit comments

Comments
 (0)