Skip to content

Commit

Permalink
Merge pull request #13 from kjsanger/feature/improve-dockerfile
Browse files Browse the repository at this point in the history
Deploy on Alpine and add a non-root user
  • Loading branch information
jmtcsngr authored Apr 2, 2024
2 parents 3a1f66b + 32ff12f commit 404291a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
2 changes: 0 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.idea/**
.git/**
tests/**

.DS_Store
.dockerignore
Expand Down
25 changes: 17 additions & 8 deletions Dockerfile
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"]
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
VERSION := $(shell git describe --always --tags --dirty)
ldflags := "-X sqyrrl/internal.Version=${VERSION}"
ldflags := "-X sqyrrl/server.Version=${VERSION}"
build_args := -a -v -ldflags ${ldflags}


.PHONY: build build-linux build-darwin build-windows check clean coverage install lint test

all: build

build: build-linux
build: build-linux build-darwin build-windows

build-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ${build_args} -o sqyrrl-linux-amd64 ./cmd/sqyrrl.go
Expand Down

0 comments on commit 404291a

Please sign in to comment.