Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy on Alpine and add a non-root user #13

Merged
merged 2 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
jmtcsngr marked this conversation as resolved.
Show resolved Hide resolved

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=source=.git,target=.git,type=bind make build-linux
kjsanger marked this conversation as resolved.
Show resolved Hide resolved

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