Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance local development ex #52

Merged
merged 6 commits into from
Sep 30, 2023
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/*/logs/*
**/*/.cache/*
**/*/world/**/*.json
**/*/world/**/*.dat*
**/*/usercache.json
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"[terraform]": {
"editor.defaultFormatter": "hashicorp.terraform",
"editor.formatOnSave": true,
"editor.tabSize": 2,
"editor.insertSpaces": true
}
}
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,11 @@ chmod +x load-memory.sh
./load-memory.sh
```

### Restart ECS Cluster
```bash
cl=$(aws ecs list-clusters | jq -r '.clusterArns[0]' )
svc=$(aws ecs list-services --cluster ${cl} | jq -r '.serviceArns[0]' | sed -E 's/.+cluster\///g')

aws ecs update-service --force-new-deployment --cluster ${cl} --service ${svc}

```
8 changes: 6 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ version: "3.8"
services:
mc:
container_name: minecraft
image: itzg/minecraft-server
build:
context: ./docker/minecraft
dockerfile: Dockerfile
tty: true
stdin_open: true
ports:
- "25565:25565"
environment:
EULA: "TRUE"
volumes:
- ~/.aws/credentials:/root/.aws/credentials:ro
- ~/.aws/config:/root/.aws/config:ro
# attach the relative directory 'data' to the container's /data path
- ./app:/data
- ./docker/minecraft:/data
fluent-bit:
container_name: fluentbit
depends_on:
Expand Down
1 change: 1 addition & 0 deletions docker/minecraft/.rcon-cli.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
password=a20114382cbc7ac18cd6fdcf
24 changes: 24 additions & 0 deletions docker/minecraft/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM itzg/minecraft-server

ENV S3_BUCKET_NAME="minecraft-backend"
ENV S3_PREFIX_NAME="backups"

# install aws cli
RUN apt-get update && apt-get install -y \
ca-certificates \
curl \
unzip \
tini \
&& curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" \
&& unzip awscliv2.zip \
&& ./aws/install -i /usr/local/aws-cli -b /usr/bin


RUN aws --version

WORKDIR /data

COPY scripts/entrypoint.sh scripts/
RUN chmod +x scripts/entrypoint.sh
ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["./scripts/entrypoint.sh"]
1 change: 1 addition & 0 deletions docker/minecraft/banned-ips.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
1 change: 1 addition & 0 deletions docker/minecraft/banned-players.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
4 changes: 4 additions & 0 deletions docker/minecraft/eula.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Generated via Docker
# Sat 30 Sep 2023 11:15:10 AM UTC
eula=true

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added docker/minecraft/minecraft_server.1.20.2.jar
Binary file not shown.
1 change: 1 addition & 0 deletions docker/minecraft/ops.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
42 changes: 42 additions & 0 deletions docker/minecraft/scripts/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

set -ex

export S3_BUCKET=$S3_BUCKET_NAME # minecraft-backend
S3_PREFIX=$S3_PREFIX_NAME # backups

BACKUP_DATE_TIME=$(date +"%Y%m%d%H%M%S")
PARTITION_DATE=$(date +"%Y")-$(date +"%m")-$(date +"%d")

# function executed when container is shutdown
cleanup() {
echo "Container is terminating. Uploading data from EFS to S3..."
if [ ! -d backup/${PARTITION_DATE} ]; then
mkdir -p backup/${PARTITION_DATE}
fi
aws s3 rm s3://${S3_BUCKET}/${S3_PREFIX}/${PARTITION_DATE} --recursive
FILE_NAME='minecraft-'${BACKUP_DATE_TIME}'.tar.gz'
tar -zcvf backup/${PARTITION_DATE}/${FILE_NAME} -C /data/ world/
aws s3 cp backup/${PARTITION_DATE}/${FILE_NAME} s3://${S3_BUCKET}/${S3_PREFIX}/${PARTITION_DATE}/

kill -TERM "$child" 2>/dev/null
}

# function executed when container is started
start() {
echo "Container is starting. Downloading data from S3..."
LATEST_BACKUP=$(aws s3 ls --recursive s3://${S3_BUCKET}/${S3_PREFIX}/ | sort | tail -n 1 | awk '{print $4}' )
# donwload s3 and unzip it to /data/world/
aws s3 cp s3://${S3_BUCKET}/${LATEST_BACKUP} /data/world/
find /data/world/ -name "*.tar.gz" -exec tar -xvf {} \;
rm -rf /data/world/*.tar.gz
}

# trap SIGTERM signal and call cleanup
trap cleanup TERM

# execute default command in container definition
/start "$@" &
child=$!

wait "$child"
59 changes: 59 additions & 0 deletions docker/minecraft/server.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#Minecraft server properties
#Sat Sep 30 11:30:39 UTC 2023
enable-jmx-monitoring=false
rcon.port=25575
level-seed=
gamemode=survival
enable-command-block=false
enable-query=false
generator-settings={}
enforce-secure-profile=true
level-name=world
motd=A Vanilla Minecraft Server powered by Docker
query.port=25565
pvp=true
generate-structures=true
max-chained-neighbor-updates=1000000
difficulty=easy
network-compression-threshold=256
max-tick-time=60000
require-resource-pack=false
use-native-transport=true
max-players=20
online-mode=true
enable-status=true
allow-flight=false
initial-disabled-packs=
broadcast-rcon-to-ops=true
view-distance=10
server-ip=
resource-pack-prompt=
allow-nether=true
server-port=25565
enable-rcon=true
sync-chunk-writes=true
op-permission-level=4
prevent-proxy-connections=false
hide-online-players=false
resource-pack=
entity-broadcast-range-percentage=100
simulation-distance=10
rcon.password=a20114382cbc7ac18cd6fdcf
player-idle-timeout=0
force-gamemode=false
rate-limit=0
hardcore=false
white-list=false
broadcast-console-to-ops=true
spawn-npcs=true
spawn-animals=true
log-ips=true
function-permission-level=2
initial-enabled-packs=vanilla
level-type=minecraft\:normal
text-filtering-config=
spawn-monsters=true
enforce-whitelist=false
spawn-protection=16
resource-pack-sha1=
max-world-size=29999984
Binary file not shown.
1 change: 1 addition & 0 deletions docker/minecraft/whitelist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Binary file added docker/minecraft/world/entities/r.-1.-1.mca
Binary file not shown.
Binary file added docker/minecraft/world/entities/r.-1.0.mca
Binary file not shown.
Binary file added docker/minecraft/world/entities/r.0.-1.mca
Binary file not shown.
Binary file added docker/minecraft/world/entities/r.0.0.mca
Binary file not shown.
Empty file.
Binary file added docker/minecraft/world/poi/r.-1.0.mca
Binary file not shown.
Empty file.
Empty file.
Binary file added docker/minecraft/world/poi/r.0.0.mca
Binary file not shown.
Empty file.
Binary file added docker/minecraft/world/region/r.-1.-1.mca
Binary file not shown.
Binary file added docker/minecraft/world/region/r.-1.0.mca
Binary file not shown.
Binary file added docker/minecraft/world/region/r.-1.1.mca
Binary file not shown.
Binary file added docker/minecraft/world/region/r.0.-1.mca
Binary file not shown.
Binary file added docker/minecraft/world/region/r.0.0.mca
Binary file not shown.
Binary file added docker/minecraft/world/region/r.0.1.mca
Binary file not shown.
1 change: 1 addition & 0 deletions docker/minecraft/world/session.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2 changes: 1 addition & 1 deletion terraform/scheduling/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module "custom_ecs" {
}
fargate_cpu = 1024
fargate_memory = 2048
mc_image_uri = "itzg/minecraft-server"
mc_image_uri = "${var.aws_account_id}.dkr.ecr.${var.aws_region}.amazonaws.com/minecraft/server"
fluentbit_image_uri = "${var.aws_account_id}.dkr.ecr.${var.aws_region}.amazonaws.com/minecraft/fluentbit"
mc_container_name = "minecraft"
mc_container_port = 25565
Expand Down
Loading