Adding Makefile and minor tweaks.
This commit is contained in:
parent
849530158a
commit
bf552562bb
3 changed files with 114 additions and 10 deletions
|
|
@ -16,9 +16,9 @@ RUN mkdir -p ${INSTALL_DIR} ${SERVER_DIR} ${CONFIG_DIR}
|
||||||
RUN apt-get update && \
|
RUN apt-get update && \
|
||||||
apt-get install -y libicu-dev
|
apt-get install -y libicu-dev
|
||||||
|
|
||||||
# Create a new group and user
|
# Create a new group and user using groupadd/useradd instead of addgroup/adduser
|
||||||
RUN addgroup --gid $GID steam && \
|
RUN groupadd --gid $GID steam && \
|
||||||
adduser --disabled-password --gecos '' --uid $UID --gid $GID steam
|
useradd --disabled-password --gecos '' --uid $UID --gid $GID steam
|
||||||
|
|
||||||
COPY start.sh $INSTALL_DIR/start.sh
|
COPY start.sh $INSTALL_DIR/start.sh
|
||||||
# COPY config_gameplay.txt $CONFIGS/config_gameplay.txt
|
# 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
|
# COPY localadmin_internal_data.json $CONFIGS/../localadmin_internal_data.json
|
||||||
|
|
||||||
# Change ownership of directories and set the start script as executable
|
# 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
|
ENTRYPOINT /bin/sh ${INSTALL_DIR}/start.sh
|
||||||
96
Makefile
Normal file
96
Makefile
Normal file
|
|
@ -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)
|
||||||
19
start.sh
19
start.sh
|
|
@ -1,10 +1,17 @@
|
||||||
|
#!/bin/sh
|
||||||
echo "Current user is: $(whoami)"
|
echo "Current user is: $(whoami)"
|
||||||
|
|
||||||
|
# Install/update SCP:SL server
|
||||||
steamcmd +force_install_dir $SERVER_DIR +login anonymous +app_update 996560 validate +quit
|
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
|
# Define config directory path
|
||||||
echo "Current user is: $(whoami)"
|
CONFIGS="$INSTALL_DIR/.config/SCP Secret Laboratory/config/$PORT"
|
||||||
cd $SERVER_DIR
|
|
||||||
export HOME=$SERVER_DIR
|
# Ensure config directory exists
|
||||||
./LocalAdmin $PORT --config $CONFIGS
|
mkdir -p "$CONFIGS"
|
||||||
|
|
||||||
|
# Switch to steam user and run server
|
||||||
|
su - steam -c "cd $SERVER_DIR && HOME=$INSTALL_DIR ./LocalAdmin $PORT --config \"$CONFIGS\""
|
||||||
Loading…
Reference in a new issue