Skip to content

Commit

Permalink
Fine tuning
Browse files Browse the repository at this point in the history
  • Loading branch information
nickschuetz committed Mar 28, 2023
1 parent c3d4c2d commit 959bc1c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
20 changes: 12 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ RUN dnf install golang -y && dnf clean all
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o ocpdoom .

FROM fedora:37 AS build-essentials
ARG NAMESPACE=monsters
ARG TARGETARCH=amd64
ARG KUBECTL_VERSION=1.25.4
RUN dnf update -y && dnf install wget ca-certificates -y
RUN wget http://distro.ibiblio.org/pub/linux/distributions/slitaz/sources/packages/d/doom1.wad
RUN echo "TARGETARCH is $TARGETARCH"
RUN echo "KUBECTL_VERSION is $KUBECTL_VERSION"
RUN echo "NAMESPACE is $NAMESPACE"
RUN wget -O /usr/bin/kubectl "https://storage.googleapis.com/kubernetes-release/release/v$KUBECTL_VERSION/bin/linux/$TARGETARCH/kubectl" \
&& chmod +x /usr/bin/kubectl

Expand All @@ -23,24 +21,26 @@ RUN dnf update -y && dnf groupinstall 'Development Tools' -y \
sdl12-compat \
SDL_mixer-devel \
SDL_net-devel \
gcc
gcc \
&& dnf clean all
ADD /dockerdoom /dockerdoom
WORKDIR /dockerdoom/trunk
RUN ./configure && make && make install

FROM fedora:37 as build-converge
WORKDIR /build
RUN mkdir -p \
/build/root \
/build/app \
/build/usr/bin \
/build/usr/local/games
COPY --from=build-essentials /doom1.wad /build/root
COPY --from=build-essentials /doom1.wad /build/app
COPY --from=build-essentials /usr/bin/kubectl /build/usr/bin
COPY --from=build-ocpdoom /go/src/ocpdoom/ocpdoom /build/usr/bin
COPY --from=build-doom /usr/local/games/psdoom /build/usr/local/games

FROM fedora:37
ARG VNCPASSWORD=openshift
ENV NAMESAPCE=monsters
RUN dnf update -y \
&& dnf install -y \
sdl12-compat \
Expand All @@ -49,8 +49,12 @@ RUN dnf update -y \
xorg-x11-server-Xvfb \
nmap \
x11vnc \
&& dnf clean all -y
RUN mkdir /root/.vnc && x11vnc -storepasswd "${VNCPASSWORD}" /root/.vnc/passwd
&& dnf clean all
RUN mkdir -p /app/.vnc && x11vnc -storepasswd "${VNCPASSWORD}" /app/.vnc/passwd \
&& mkdir -p /app/socket
COPY --from=build-converge /build /
WORKDIR /root
WORKDIR /app
RUN chgrp -R 0 /app && \
chmod -R g=u /app

ENTRYPOINT ["/usr/bin/ocpdoom"]
4 changes: 2 additions & 2 deletions dockerdoom/trunk/src/pr_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void pr_check(void) {
return;
}

f = popen("echo list | nc -U /dockerdoom.socket", "r");
f = popen("echo list | nc -U /app/socket/dockerdoom.socket", "r");

if (!f) {
fprintf(stderr, "ERROR: pr_check could not open ps\n");
Expand Down Expand Up @@ -668,7 +668,7 @@ void pr_kill(int pid) {
if ( nopsact ){
return;
}
sprintf(buf, "echo \"kill %d\" | nc -U /dockerdoom.socket", pid);
sprintf(buf, "echo \"kill %d\" | nc -U /app/socket/dockerdoom.socket", pid);
system(buf);
}

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module kubedoom
module ocpdoom

go 1.20
go 1.18
11 changes: 8 additions & 3 deletions ocpdoom.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func socketLoop(listener net.Listener, mode Mode) {
padding := strings.Repeat("\n", 255-len(entity))
_, err = conn.Write([]byte(entity + padding))
if err != nil {
log.Fatal("Could not write to socker file")
log.Fatal("Could not write to socket file")
}
}
conn.Close()
Expand Down Expand Up @@ -162,15 +162,20 @@ func main() {
log.Fatalf("Mode should be pods or namespaces")
}

listener, err := net.Listen("unix", "/dockerdoom.socket")
c := os.Remove("/app/socket/dockerdoom.socket")
if c != nil {
log.Println(c)
}

listener, err := net.Listen("unix", "/app/socket/dockerdoom.socket")
if err != nil {
log.Fatalf("Could not create socket file")
}

log.Print("Create virtual display")
startCmd("/usr/bin/Xvfb :99 -ac -screen 0 640x480x24")
time.Sleep(time.Duration(2) * time.Second)
startCmd("x11vnc -geometry 640x480 -forever -usepw -display :99")
startCmd("x11vnc -geometry 640x480 -forever -rfbauth /app/.vnc/passwd -usepw -display :99")
log.Print("You can now connect to it with a VNC viewer at port 5900")

log.Print("Trying to start DOOM ...")
Expand Down

0 comments on commit 959bc1c

Please sign in to comment.