Skip to content

Commit 9d47365

Browse files
Merge pull request #38 from hyperledger/fix/dockerfile
Create a non-root user for a docker container
2 parents a12b480 + d6b625b commit 9d47365

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

.dockerignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
# IDE configs
22
.vscode
3-
.idea
3+
.idea
4+
5+
# Compiled output
6+
firefly-tezosconnect

Dockerfile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ FROM golang:1.21-alpine3.19 AS builder
22
RUN apk add make
33
ARG BUILD_VERSION
44
ENV BUILD_VERSION=${BUILD_VERSION}
5-
ADD . /tezosconnect
5+
ADD --chown=1001:0 . /tezosconnect
66
WORKDIR /tezosconnect
7+
RUN mkdir /.cache \
8+
&& chgrp -R 0 /.cache \
9+
&& chmod -R g+rwX /.cache
10+
USER 1001
711
RUN make
812

913
# Copy the migrations from FFTM down into our local migrations directory
@@ -12,13 +16,16 @@ RUN DB_MIGRATIONS_DIR=$(go list -f '{{.Dir}}' github.com/hyperledger/firefly-tra
1216

1317
FROM debian:buster-slim
1418
WORKDIR /tezosconnect
19+
RUN chgrp -R 0 /tezosconnect \
20+
&& chmod -R g+rwX /tezosconnect
1521
RUN apt update -y \
1622
&& apt install -y curl jq \
1723
&& rm -rf /var/lib/apt/lists/* \
1824
&& curl -sL "https://github.com/golang-migrate/migrate/releases/download/$(curl -sL https://api.github.com/repos/golang-migrate/migrate/releases/latest | jq -r '.name')/migrate.linux-amd64.tar.gz" | tar xz \
1925
&& chmod +x ./migrate \
2026
&& mv ./migrate /usr/bin/migrate
21-
COPY --from=builder /tezosconnect/firefly-tezosconnect /usr/bin/tezosconnect
22-
COPY --from=builder /tezosconnect/db/ /tezosconnect/db/
27+
COPY --from=builder --chown=1001:0 /tezosconnect/firefly-tezosconnect /usr/bin/tezosconnect
28+
COPY --from=builder --chown=1001:0 /tezosconnect/db/ /tezosconnect/db/
29+
USER 1001
2330

2431
ENTRYPOINT [ "/usr/bin/tezosconnect" ]

0 commit comments

Comments
 (0)