mlops-club / awscdk-minecraft

An AWS CDK package written in Python for deploying an entire Minecraft Server Platform-as-a-Service
Other
13 stars 4 forks source link

refactor user_data.sh docker-compose file #29

Open mathematicalmichael opened 1 year ago

mathematicalmichael commented 1 year ago

In awscdk-minecraft/awscdk-minecraft-server-deployer/resources/user-data.sh we define the contents of a docker-compose file, but awscdk-minecraft/awscdk-minecraft-server-deployer/src/minecraft_server_deployer/server_stack.py could (and should) instead load up a docker-compose.yml file with these contents and template it there.

We're currently "templating" with what looks like bash variables but is actually used by server_stack.py to fill in those values in the shell script.

Instead of

cat << EOF > /home/ec2-user/docker-compose.yml
version: '3.7'
services:
    minecraft:
        # image docs: https://github.com/itzg/docker-minecraft-server
        image: itzg/minecraft-server
        restart: always
        ports:
            - "25565:25565"
        environment:
            EULA: "TRUE"
            TYPE: "PAPER"
            VERSION: "$MINECRAFT_SERVER_SEMANTIC_VERSION"
        networks:
        - minecraft-server
        deploy:
            replicas: 1

networks:
    minecraft-server:
        driver: overlay
        name: minecraft-server
EOF

Would become

cat << EOF > /home/ec2-user/docker-compose.yml
$DOCKER_COMPOSE_TEMPLATE_FILE
EOF

and the DOCKER_COMPOSE_TEMPLATE_FILE variable will instead be filled in with server_stack.py by using Python's built-in template library that reads in the docker-compose file from disk.

This would allow for syntax highlighting in your IDEs when editing this compose file, and make it something easier to find in the repo.

So to summarize, this feature would include