feature: change example to use non-root (#1879)

#### What type of PR is this?

<!--
Add one of the following kinds:
/kind bug
/kind cleanup
/kind documentation
-->

/kind feature

#### What this PR does / why we need it:

This changes our example to use non-root so it runs well on non-root
clusters (ex. openshift).

We also add debugging tools so we can safely explore the container.

/tmp is also added as the directory for the replica or else it fails.

#### Which issue(s) this PR fixes:
<!--
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->

N/A

#### Special notes for your reviewer:

Signed-off-by: Charlie Drage <charlie@charliedrage.com>
This commit is contained in:
Charlie Drage 2024-05-29 12:51:37 -04:00 committed by GitHub
parent 50e0408f6f
commit 29f6765fc6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 4 deletions

View File

@ -2,16 +2,16 @@ services:
redis-leader: redis-leader:
container_name: redis-leader container_name: redis-leader
image: redis:latest image: redis
ports: ports:
- "6379" - "6379"
redis-replica: redis-replica:
container_name: redis-replica container_name: redis-replica
image: redis:latest image: redis
ports: ports:
- "6379" - "6379"
command: redis-server --replicaof redis-leader 6379 command: redis-server --replicaof redis-leader 6379 --dir /tmp
web: web:
container_name: web container_name: web

View File

@ -1,4 +1,9 @@
FROM golang:1.21.2 FROM golang:1.21.2
# Debugging within the container
RUN apt-get update && apt-get install dnsutils redis-tools -y
# Set the working directory in the container
WORKDIR /app WORKDIR /app
# Copy the entire project which includes the public directory, vendoring, etc. # Copy the entire project which includes the public directory, vendoring, etc.
@ -7,5 +12,15 @@ COPY . .
# Build your application # Build your application
RUN CGO_ENABLED=0 GOOS=linux go build -o /frontend RUN CGO_ENABLED=0 GOOS=linux go build -o /frontend
# Change the permissions so that all users can execute it
RUN chmod +x /frontend
# Although setting permissions on /frontend should suffice, set wider permissions if needed
RUN chown -R 1001:0 /app && \
chmod -R g=u /app
# This directive ensures the container does not run as root
USER 1001
EXPOSE 8080 EXPOSE 8080
CMD ["/frontend"] CMD ["/frontend"]