Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Stage 1: Build
FROM ubuntu:22.04 AS builder

WORKDIR /app

RUN set -xe; \
apt-get -yqq update; \
apt-get -yqq install build-essential \
;

COPY ./rwslotmachine4.c .
COPY ./Makefile.sol ./Makefile

RUN make

# Stage 2: Runtime
FROM ubuntu:22.04

RUN set -xe; \
apt-get -yqq update;\
apt-get -yqq install libstdc++6; \
rm -rf /var/lib/apt/lists/* \
;

WORKDIR /app

# Copy compiled binary from builder stage
COPY --from=builder /app/rwslotmachine4 .

# Expose port
EXPOSE 31347

# Run the executable
CMD ["/app/rwslotmachine4"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
PORT ?= 31347
IMG_NAME ?= rwslotmachine4
CONT_NAME ?= $(IMG_NAME)-cnt

build:
docker build -t $(IMG_NAME) -f Dockerfile .

run: build
docker run -d --rm -p $(PORT):31337 --name $(CONT_NAME) -t $(IMG_NAME)

stop:
-docker stop $(CONT_NAME)

clean: stop
docker rm $(CONT_NAME)

.PHONY: build run stop clean
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
TARGET = rwslotmachine4

all: $(TARGET)

$(TARGET): rwslotmachine4.c
$(CC) -o $(TARGET) rwslotmachine4.c

clean:
-rm -f $(TARGET)

.PHONY: all clean
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Building and Running

The included Makefile automates building and running the Docker container.

- Build the Docker image:

```bash
make build
```

- Run the container:

```bash
make run
```

- Stop the running container:

```bash
make stop
```

- Clean up container state:

```bash
make clean
```
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@

#define MAX_SLOTS 32

long read_int(int base);
long read_int(int base)
{
char buf[64];
char *endptr;

if (fgets(buf, sizeof(buf), stdin) == NULL) {
puts("Failed to read input!");
exit(1);
}

return strtol(buf, &endptr, base);
}

long slots[MAX_SLOTS];

Expand Down