Skip to content

Commit c4f6c7e

Browse files
committed
05-rwslotmachine5: Add Makefile and Dockerfile
1 parent 2d21544 commit c4f6c7e

File tree

2 files changed

+46
-0
lines changed
  • chapters/mitigations-and-defensive-strategies/defense-mechanisms/activities/05-rwslotmachine5/sol

2 files changed

+46
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# --- Build ---
2+
FROM gcc:latest AS builder
3+
4+
# Set working directory
5+
WORKDIR /app
6+
7+
# Copy the source code
8+
COPY ./rwslotmachine5.c .
9+
10+
# Build the C program
11+
RUN gcc -o rwslotmachine5 rwslotmachine5.c
12+
13+
# --- Runtime ---
14+
FROM ubuntu:22.04
15+
16+
# Install minimal libraries needed for runtime
17+
RUN apt-get update && apt-get install -y libstdc++6 && rm -rf /var/lib/apt/lists/*
18+
19+
# Set working directory
20+
WORKDIR /app
21+
22+
# Copy compiled binary from builder stage
23+
COPY --from=builder /app/rwslotmachine5 .
24+
25+
# Expose port
26+
EXPOSE 31348
27+
28+
# Run the executable
29+
CMD ["/app/rwslotmachine5"]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
PORT ?= 31348
2+
IMG_NAME ?= rwslotmachine5
3+
CONT_NAME ?= $(IMG_NAME)-cnt
4+
5+
build:
6+
docker build -t $(IMG_NAME) -f Dockerfile .
7+
8+
run: build
9+
docker run -d -p $(PORT):31348 --name $(CONT_NAME) -t $(IMG_NAME)
10+
11+
stop:
12+
-docker stop $(CONT_NAME)
13+
14+
clean: stop
15+
docker rm $(CONT_NAME)
16+
17+
.PHONY: build run stop clean

0 commit comments

Comments
 (0)