mirror of
https://github.com/tobiasehlert/teslamateapi.git
synced 2026-02-27 09:54:18 +08:00
Fix permission issues with Dockerfile nonroot implementation (#274)
This commit is contained in:
+15
-14
@@ -1,5 +1,5 @@
|
||||
# get golang container
|
||||
FROM golang:1.22.1
|
||||
FROM golang:1.22.1 AS builder
|
||||
|
||||
# get args
|
||||
ARG apiVersion=unknown
|
||||
@@ -21,23 +21,24 @@ RUN CGO_ENABLED=0 go build -ldflags="-w -s -X 'main.apiVersion=${apiVersion}'" -
|
||||
|
||||
|
||||
# get alpine container
|
||||
FROM 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
|
||||
FROM alpine:3.19.1 AS app
|
||||
|
||||
# create workdir
|
||||
WORKDIR /root/
|
||||
WORKDIR /opt/app
|
||||
|
||||
# copy binary from first container
|
||||
COPY --from=0 /go/src/app .
|
||||
# add ca-certificates and tzdata
|
||||
RUN apk --no-cache add ca-certificates tzdata
|
||||
|
||||
# set user
|
||||
USER nonroot
|
||||
# create nonroot user and group
|
||||
RUN addgroup -S nonroot && \
|
||||
adduser -S nonroot -G nonroot && \
|
||||
chown -R nonroot:nonroot .
|
||||
|
||||
# set user to nonroot
|
||||
USER nonroot:nonroot
|
||||
|
||||
# copy binary from builder
|
||||
COPY --from=builder --chown=nonroot:nonroot --chmod=544 /go/src/app .
|
||||
|
||||
# expose port 8080
|
||||
EXPOSE 8080
|
||||
|
||||
Reference in New Issue
Block a user