This repository has been archived by the owner on Oct 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# sst | ||
.sst | ||
key_rsa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`, | ||
}; | ||
}, | ||
}); |