Files
archived-teslamateapi/Dockerfile
T
Tobias Lindberg fc5fb63f03 update Dockerfile to specific version and use of nonroot user (#266)
* using alpine specific version instead of latest
* running container with nonroot user
2024-02-05 11:23:14 +01:00

47 lines
750 B
Docker

# get golang container
FROM golang:1.21.6
# get args
ARG apiVersion=unknown
# create and set workingfolder
WORKDIR /go/src/
# copy go mod files
COPY go.mod go.sum ./
# download go mods
RUN go mod download
# copy all sourcecode
COPY src/ .
# compile the program
RUN CGO_ENABLED=0 go build -ldflags="-w -s -X 'main.apiVersion=${apiVersion}'" -o app ./...
# get alpine container
FROM alpine:alpine:3.19.1
# create nonroot user
RUN addgroup -S nonroot \
&& adduser -S nonroot -G nonroot
# add ca-certificates
RUN apk --no-cache add ca-certificates tzdata
# create workdir
WORKDIR /root/
# copy binary from first container
COPY --from=0 /go/src/app .
# set user
USER nonroot
# expose port 8080
EXPOSE 8080
# run application
CMD ["./app"]