-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from kjsanger/feature/improve-dockerfile
Deploy on Alpine and add a non-root user
- Loading branch information
Showing
3 changed files
with
19 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
.idea/** | ||
.git/** | ||
tests/** | ||
|
||
.DS_Store | ||
.dockerignore | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,34 @@ | ||
FROM golang:1.22 | ||
# syntax = docker/dockerfile:1.2 | ||
|
||
FROM golang:1.22 as builder | ||
|
||
ARG VERSION=dev | ||
|
||
WORKDIR /app | ||
|
||
COPY go.mod go.sum ./ | ||
COPY ./Makefile . | ||
COPY ./go.* . | ||
COPY ./cmd ./cmd | ||
COPY ./internal ./internal | ||
COPY ./server ./server | ||
COPY ./templates ./templates | ||
|
||
RUN go mod download | ||
RUN ls -la /app/templates | ||
|
||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \ | ||
go build -a -v -ldflags "-X sqyrrl/internal.Version=${VERSION}" -o sqyrrl ./cmd/sqyrrl.go | ||
# Mount the .git directory to allow the build to get the version from git | ||
RUN --mount=type=bind,source=.git,target=.git make build-linux | ||
|
||
FROM alpine:latest | ||
|
||
FROM scratch | ||
COPY --from=0 /app /app | ||
COPY --from=builder /app/sqyrrl-linux-amd64 /app/sqyrrl | ||
|
||
WORKDIR /app | ||
|
||
RUN adduser -D sqyrrl | ||
|
||
EXPOSE 3333 | ||
|
||
USER sqyrrl | ||
|
||
ENTRYPOINT ["/app/sqyrrl"] | ||
|
||
CMD ["--version"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters