diff --git a/Dockerfile b/Dockerfile index 80c74f7..14d7de9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,9 +16,9 @@ RUN mkdir -p ${INSTALL_DIR} ${SERVER_DIR} ${CONFIG_DIR} RUN apt-get update && \ apt-get install -y libicu-dev -# Create a new group and user -RUN addgroup --gid $GID steam && \ - adduser --disabled-password --gecos '' --uid $UID --gid $GID steam +# Create a new group and user using groupadd/useradd instead of addgroup/adduser +RUN groupadd --gid $GID steam && \ + useradd --disabled-password --gecos '' --uid $UID --gid $GID steam COPY start.sh $INSTALL_DIR/start.sh # COPY config_gameplay.txt $CONFIGS/config_gameplay.txt @@ -27,6 +27,7 @@ COPY start.sh $INSTALL_DIR/start.sh # COPY localadmin_internal_data.json $CONFIGS/../localadmin_internal_data.json # Change ownership of directories and set the start script as executable -RUN chown $UID:$GID -R ${STEAM_DIR} ${INSTALL_DIR} ${SERVER_DIR} ${CONFIG_DIR} +RUN chown $UID:$GID -R ${STEAM_DIR} ${INSTALL_DIR} ${SERVER_DIR} ${CONFIG_DIR} && \ + chmod +x ${INSTALL_DIR}/start.sh ENTRYPOINT /bin/sh ${INSTALL_DIR}/start.sh \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..01f8a1d --- /dev/null +++ b/Makefile @@ -0,0 +1,96 @@ +# Configuration +IMAGE_NAME := greenmatthew/scp-secret-laboratory-server +VERSION := 1.0.0 +CONTAINER_NAME := scp-sl-server +PORT := 7777 + +# Set this to your Docker Hub username before pushing +DOCKER_USERNAME ?= greenmatthew + +# Default goal +.PHONY: all +all: build + +# Build the Docker image +.PHONY: build +build: + @echo "Building Docker image: $(IMAGE_NAME):$(VERSION)" + docker build -t $(IMAGE_NAME):$(VERSION) . + docker tag $(IMAGE_NAME):$(VERSION) $(IMAGE_NAME):latest + +# Run the container +.PHONY: run +run: + @echo "Running container: $(CONTAINER_NAME)" + docker run -d --name $(CONTAINER_NAME) \ + -p $(PORT):$(PORT)/udp \ + -v $(PWD)/config:/home/steam/.config/SCP\ Secret\ Laboratory/config/$(PORT) \ + --restart unless-stopped \ + $(IMAGE_NAME):latest + +# Stop the container +.PHONY: stop +stop: + @echo "Stopping container: $(CONTAINER_NAME)" + -docker stop $(CONTAINER_NAME) + -docker rm $(CONTAINER_NAME) + +# Restart the container +.PHONY: restart +restart: stop run + +# Push to Docker Hub +.PHONY: push +push: + @echo "Pushing to Docker Hub: $(IMAGE_NAME):$(VERSION) and $(IMAGE_NAME):latest" + docker push $(IMAGE_NAME):$(VERSION) + docker push $(IMAGE_NAME):latest + +# Tag and push with current date +.PHONY: tag-date +tag-date: + $(eval DATE := $(shell date +%Y%m%d)) + @echo "Tagging with date: $(IMAGE_NAME):$(DATE)" + docker tag $(IMAGE_NAME):latest $(IMAGE_NAME):$(DATE) + docker push $(IMAGE_NAME):$(DATE) + +# Login to Docker Hub +.PHONY: login +login: + @echo "Logging into Docker Hub..." + docker login -u $(DOCKER_USERNAME) + +# Remove Docker image +.PHONY: clean +clean: stop + @echo "Removing Docker image: $(IMAGE_NAME)" + -docker rmi $(IMAGE_NAME):$(VERSION) + -docker rmi $(IMAGE_NAME):latest + +# Show help +.PHONY: help +help: + @echo "Available targets:" + @echo " all (default) - Build the Docker image" + @echo " build - Build the Docker image" + @echo " run - Run the container" + @echo " stop - Stop and remove the container" + @echo " restart - Restart the container" + @echo " push - Push the image to Docker Hub" + @echo " tag-date - Tag and push image with current date" + @echo " login - Login to Docker Hub" + @echo " clean - Stop container and remove images" + @echo " logs - View container logs" + @echo " help - Show this help message" + @echo "" + @echo "Configuration:" + @echo " IMAGE_NAME = $(IMAGE_NAME)" + @echo " VERSION = $(VERSION)" + @echo " CONTAINER_NAME = $(CONTAINER_NAME)" + @echo " PORT = $(PORT)" + @echo " DOCKER_USERNAME = $(DOCKER_USERNAME)" + +# View container logs +.PHONY: logs +logs: + docker logs -f $(CONTAINER_NAME) \ No newline at end of file diff --git a/start.sh b/start.sh index ce1df76..9e934cb 100644 --- a/start.sh +++ b/start.sh @@ -1,10 +1,17 @@ +#!/bin/sh echo "Current user is: $(whoami)" + +# Install/update SCP:SL server steamcmd +force_install_dir $SERVER_DIR +login anonymous +app_update 996560 validate +quit -chown steam:steam -R $INSTALL_DIR +# Ensure proper ownership +chown -R steam:steam $INSTALL_DIR -su - steam -echo "Current user is: $(whoami)" -cd $SERVER_DIR -export HOME=$SERVER_DIR -./LocalAdmin $PORT --config $CONFIGS +# Define config directory path +CONFIGS="$INSTALL_DIR/.config/SCP Secret Laboratory/config/$PORT" + +# Ensure config directory exists +mkdir -p "$CONFIGS" + +# Switch to steam user and run server +su - steam -c "cd $SERVER_DIR && HOME=$INSTALL_DIR ./LocalAdmin $PORT --config \"$CONFIGS\"" \ No newline at end of file