Skip to content

Commit

Permalink
Add Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Mar 2, 2024
1 parent 3a3e4e0 commit 773fd11
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Dockerfile
@@ -0,0 +1,37 @@
FROM golang:1.22-bookworm AS builder

WORKDIR /build

RUN apt update && apt install -y pkg-config cmake

# Cache modules and git2go build
COPY go.mod go.sum ./
RUN go mod download

# Build git2go
RUN git clone https://github.com/libgit2/git2go vendor/github.com/libgit2/git2go/v34
RUN cd vendor/github.com/libgit2/git2go/v34 && git checkout v34.0.0 && git submodule update --init && make install-static
RUN mv vendor/github.com/libgit2/git2go/v34 git2go

# Copy the code
COPY .git main.go ./
COPY splitter splitter/
RUN go mod vendor
RUN rm -rf vendor/github.com/libgit2/git2go/v34
RUN mv git2go vendor/github.com/libgit2/git2go/v34

# Build
RUN go build -tags static -ldflags="-s -w -X 'main.version=$(git describe --tags)'" -o splitsh-lite ./main.go

# Prepare files for the final image
WORKDIR /dist
RUN cp /build/splitsh-lite ./splitsh-lite

# Add dependent libraries
RUN ldd splitsh-lite | tr -s '[:blank:]' '\n' | grep '^/' | xargs -I % sh -c 'mkdir -p $(dirname ./%); cp % ./%;'

# Create the runtime image
FROM scratch

COPY --from=builder /dist /
ENTRYPOINT ["./splitsh-lite"]

0 comments on commit 773fd11

Please sign in to comment.