Skip to content

Commit

Permalink
feature: change example to use non-root
Browse files Browse the repository at this point in the history
#### 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>
  • Loading branch information
cdrage committed May 29, 2024
1 parent 50e0408 commit 03c9670
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 4 additions & 4 deletions examples/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ services:

redis-leader:
container_name: redis-leader
image: redis:latest
image: redis
ports:
- "6379"

redis-replica:
container_name: redis-replica
image: redis:latest
image: redis
ports:
- "6379"
command: redis-server --replicaof redis-leader 6379
command: redis-server --replicaof redis-leader 6379 --dir /tmp

web:
container_name: web
image: quay.io/kompose/web
ports:
- "8080:8080"
- "8080:8080"
15 changes: 15 additions & 0 deletions examples/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
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

# Copy the entire project which includes the public directory, vendoring, etc.
Expand All @@ -7,5 +12,15 @@ COPY . .
# Build your application
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
CMD ["/frontend"]

0 comments on commit 03c9670

Please sign in to comment.