Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
example: minecraft
Browse files Browse the repository at this point in the history
  • Loading branch information
thdxr committed Oct 4, 2024
1 parent c5dbefa commit 99868c4
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/hetzner-minecraft/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# sst
.sst
key_rsa
78 changes: 78 additions & 0 deletions examples/hetzner-minecraft/sst.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/// <reference path="./.sst/platform/config.d.ts" />

// Note this will error on the first deploy because the docker provider is not ready
// waiting a minute and running deploy again should work
import { writeFileSync } from "fs";
import { resolve } from "path";
export default $config({
app(input) {
return {
name: "hetzner-minecraft",
removal: input?.stage === "production" ? "retain" : "remove",
home: "local",
providers: {
docker: "4.5.6",
tls: "5.0.7",
hcloud: "1.20.4",
command: "1.0.1",
},
};
},
async run() {
const privateKey = new tls.PrivateKey("PrivateKey", {
algorithm: "RSA",
rsaBits: 4096,
});
const publicKey = new hcloud.SshKey("PublicKey", {
publicKey: privateKey.publicKeyOpenssh,
});
const server = new hcloud.Server("Server", {
image: "debian-12",
serverType: "cx11",
sshKeys: [publicKey.id],
userData: [
`#!/bin/bash`,
`apt-get update`,
`apt-get install -y docker.io apparmor`,
`systemctl enable --now docker`,
`usermod -aG docker debian`,
].join("\n"),
});
const keyPath = privateKey.privateKeyOpenssh.apply((key) => {
const path = "key_rsa";
writeFileSync(path, key, { mode: 0o600 });
return resolve(path);
});
const dockerProvider = new docker.Provider("DockerProvider", {
host: $interpolate`ssh://root@${server.ipv4Address}`,
sshOpts: ["-i", keyPath, "-o", "StrictHostKeyChecking=no"],
});
const minecraft = new docker.Container(
"Minecraft",
{
image: "itzg/minecraft-server",
ports: [
{
internal: 25565,
external: 25565,
},
],
envs: ["EULA=TRUE"],
volumes: [
{
hostPath: "/docker/minecraft/data",
containerPath: "/data",
},
],
restart: "always",
},
{
provider: dockerProvider,
dependsOn: [server],
},
);
return {
url: $interpolate`${server.ipv4Address}:25565`,
};
},
});

0 comments on commit 99868c4

Please sign in to comment.