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

Feature/cicd hetzner deploy #89

Draft
wants to merge 149 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
149 commits
Select commit Hold shift + click to select a range
8595e47
create terraform deployment on hetzner
NexusNull Oct 28, 2023
3a726f3
insert backlink
NexusNull Oct 28, 2023
e977d2b
Merge remote-tracking branch 'upstream/main'
NexusNull Oct 28, 2023
072d16e
remove admin urls
NexusNull Oct 28, 2023
831fd74
fix secret
NexusNull Oct 28, 2023
e124c36
enable signup
NexusNull Oct 28, 2023
43222d8
mount storage
NexusNull Oct 28, 2023
0dc95ad
update game url
NexusNull Oct 28, 2023
89a922f
pass server name
NexusNull Oct 28, 2023
95f1c02
fix storage mounting
NexusNull Oct 28, 2023
861bad6
remove overwrite od db
NexusNull Oct 28, 2023
6a89878
fix storage mounting
NexusNull Oct 29, 2023
d1dbed2
refactor
NexusNull Oct 29, 2023
0aab4c3
add github action
NexusNull Oct 29, 2023
77a4d7b
fix http backend
NexusNull Oct 29, 2023
f827327
fix variables
NexusNull Oct 29, 2023
ca5753b
kill server when create_server fails
NexusNull Oct 29, 2023
c8d4fab
enable unstuck
NexusNull Oct 29, 2023
e5eb671
fix unstuck
NexusNull Oct 29, 2023
8fd65e0
Merge pull request #2 from NexusNull/main
FreezePhoenix Oct 29, 2023
7ed2448
remove notverified and authfail
NexusNull Oct 29, 2023
68bd798
Merge pull request #3 from NexusNull/main
FreezePhoenix Oct 29, 2023
fcb926b
Update server.js (name_to_id Object -> Map)
FreezePhoenix Oct 29, 2023
18b9c99
Update server_functions.js (name_to_id Object -> Map)
FreezePhoenix Oct 30, 2023
a643ad1
Update functions.py (name_to_id Object -> Map)
FreezePhoenix Oct 30, 2023
ace3dcb
Merge pull request #7 from FreezePhoenix/Nexus
NexusNull Oct 30, 2023
2313f47
remove install and run from terraform
NexusNull Oct 31, 2023
acffa34
Merge branch 'main' of github.com:NexusNull/adventureland
NexusNull Oct 31, 2023
096d53e
fix locals
NexusNull Oct 31, 2023
70e1af0
ansible init
NexusNull Oct 31, 2023
f53fa24
fix setup
NexusNull Oct 31, 2023
8dfcb74
fix version
NexusNull Oct 31, 2023
ac79fba
switch action
NexusNull Oct 31, 2023
54c52f6
run on ansible-test
NexusNull Oct 31, 2023
df218d7
fix not checking out repo
NexusNull Oct 31, 2023
ec7208a
refactor
NexusNull Oct 31, 2023
a5d0cb3
use custom inventory
NexusNull Oct 31, 2023
b37bd2a
fix file name
NexusNull Oct 31, 2023
6e34193
setup needs deploy
NexusNull Oct 31, 2023
449544f
set connect user
NexusNull Oct 31, 2023
4ffcf83
change source dir for rsync
NexusNull Oct 31, 2023
b4382bc
refactor
NexusNull Oct 31, 2023
3751dac
debugging
NexusNull Oct 31, 2023
8a12aa9
debugging
NexusNull Oct 31, 2023
db51f9d
fix path
NexusNull Nov 1, 2023
08089f8
fix path
NexusNull Nov 1, 2023
7fc9317
remove debug
NexusNull Nov 1, 2023
2831d4a
add concurency
NexusNull Nov 1, 2023
6dffae0
try stoping a none existing service
NexusNull Nov 1, 2023
f70f79a
ignore errors
NexusNull Nov 1, 2023
29ff694
Update server.js (fix memory leak in name_to_id and id_to_id)
FreezePhoenix Nov 2, 2023
dc6f53b
Merge pull request #4 from FreezePhoenix/patch-2
FreezePhoenix Nov 2, 2023
00a223f
Merge pull request #8 from FreezePhoenix/Nexus
NexusNull Nov 3, 2023
7262e3e
Update server.js (improve calculate_stats)
FreezePhoenix Nov 3, 2023
21bb258
Merge pull request #9 from FreezePhoenix/patch-3
NexusNull Nov 5, 2023
6999704
wip
NexusNull Nov 5, 2023
075ae8c
add some more
NexusNull Nov 5, 2023
37f212f
fix services
NexusNull Nov 5, 2023
8a7ef81
fix storage
NexusNull Nov 5, 2023
1820dd5
I'm lazy, jsut testing
NexusNull Nov 5, 2023
2c297b9
Message me on discord if you actually read these.
NexusNull Nov 5, 2023
80f704a
remove meta
NexusNull Nov 5, 2023
e2adafb
remove handlers
NexusNull Nov 5, 2023
75a0d37
man chatgpt sucks ass
NexusNull Nov 5, 2023
e6f74b7
fix variable
NexusNull Nov 5, 2023
eb656c1
my mistake
NexusNull Nov 5, 2023
7fbdcf8
this commit makes me sad
NexusNull Nov 5, 2023
68811b7
this commit makes me sad
NexusNull Nov 5, 2023
0a2e695
add account
NexusNull Nov 5, 2023
9ab8387
ugh command sucks
NexusNull Nov 5, 2023
27d7fea
define variables for node server
NexusNull Nov 5, 2023
7b4247c
define variables for master server
NexusNull Nov 5, 2023
2072a64
asd
NexusNull Nov 5, 2023
6d099e5
Microwave goes MMMMMMMMMMMMMMMMMMMMMMMMh
NexusNull Nov 5, 2023
cd4d21d
Microwave goes MMMMMMMMMMMMMMMMMMMMMMMMh
NexusNull Nov 5, 2023
75ceb48
Microwave goes Bing!
NexusNull Nov 5, 2023
8d8d325
syncronize sucks
NexusNull Nov 5, 2023
0c63cd1
Incorporate prettier
FreezePhoenix Nov 5, 2023
39d5f28
Fix one small bug lul
FreezePhoenix Nov 5, 2023
369979a
Fix one small bug lul
FreezePhoenix Nov 5, 2023
9e628c4
some cleanup
NexusNull Nov 7, 2023
967ac67
start service
NexusNull Nov 7, 2023
009fc22
update service file
NexusNull Nov 7, 2023
5581066
create secrets
NexusNull Nov 7, 2023
9e2f436
asd
NexusNull Nov 7, 2023
869abac
Burgh
NexusNull Nov 7, 2023
ffb09dd
npm install
NexusNull Nov 8, 2023
1b49935
Merge pull request #10 from FreezePhoenix/Nexus
NexusNull Nov 11, 2023
3918cfc
allow to bind on port 80
NexusNull Nov 11, 2023
2acd3a3
Merge branch 'ansible-test'
NexusNull Nov 12, 2023
0788014
set service to restarted
NexusNull Nov 12, 2023
ccd28ee
provide base_url as variable from cicd
NexusNull Nov 12, 2023
72b1c15
use variable base_url
NexusNull Nov 12, 2023
572d195
take settings from inventory
NexusNull Nov 12, 2023
e2d20c7
Implement equip_batch on the server
FreezePhoenix Nov 13, 2023
770753f
Fix prettier error
FreezePhoenix Nov 19, 2023
9545f95
Update runner_functions.js to implement equip_batch
FreezePhoenix Nov 19, 2023
0f2cfa5
Create equip_batch.html
FreezePhoenix Nov 19, 2023
556284a
Update directory.py to include equip_batch
FreezePhoenix Nov 19, 2023
f2052bc
Fix equip_batch to send an object response, so that success_response …
FreezePhoenix Nov 19, 2023
5632fde
wip template
NexusNull Nov 23, 2023
7609b8f
more wip
NexusNull Nov 23, 2023
5a99208
use password instead of string
NexusNull Nov 23, 2023
3fc6bfc
fix password usage
NexusNull Nov 23, 2023
345b636
well, here goes
NexusNull Nov 23, 2023
cfdb52f
test
NexusNull Nov 23, 2023
8de0958
test1
NexusNull Nov 23, 2023
a02db3c
artifact management
NexusNull Nov 23, 2023
0a74119
merge stages
NexusNull Nov 23, 2023
f8e029b
recreate secrets
NexusNull Nov 23, 2023
8e3c9c3
Merge branch 'main' into patch-1
NexusNull Nov 23, 2023
791bfba
refactor
NexusNull Nov 30, 2023
58b7a3c
don not npm install on master
NexusNull Nov 30, 2023
fee3e4a
remove notify
NexusNull Nov 30, 2023
20ecb96
fix local source path
NexusNull Nov 30, 2023
c5e472b
add terraform provider cache
NexusNull Nov 30, 2023
cbfc44c
own recursively
NexusNull Nov 30, 2023
ba25732
add variables.js
NexusNull Nov 30, 2023
adbc901
Merge pull request #11 from FreezePhoenix/patch-1
NexusNull Nov 30, 2023
8a0dc5e
Revert "Implement batch_equip on server."
NexusNull Nov 30, 2023
d9dff4a
Merge pull request #12 from NexusNull/revert-11-patch-1
NexusNull Nov 30, 2023
e0dd845
merge
NexusNull Dec 1, 2023
2660476
fix secrets
NexusNull Dec 1, 2023
04543fc
add to template
NexusNull Dec 1, 2023
7013f4b
test more servers
NexusNull Dec 1, 2023
2d4229d
test less servers
NexusNull Dec 1, 2023
b02a567
module refactor
NexusNull Dec 1, 2023
3547c68
maybe this works?
NexusNull Dec 1, 2023
98fdc77
remove tests
NexusNull Dec 1, 2023
7d54d73
add one server
NexusNull Dec 1, 2023
4735347
fix threat detected
NexusNull Dec 1, 2023
f9d0e5d
hetzner test
NexusNull Dec 1, 2023
c298391
remove ipv6
NexusNull Dec 2, 2023
72f75de
remove editor configs
NexusNull Dec 2, 2023
d149e3c
remove some servers
NexusNull Dec 2, 2023
8b003a9
remove some servers
NexusNull Dec 2, 2023
f1879fd
remove test servers
NexusNull Dec 2, 2023
b763380
update gitignore
NexusNull Dec 2, 2023
1da36e8
merge main
NexusNull Dec 26, 2023
dfc3461
remove .vscode
NexusNull Dec 28, 2023
d5b9226
add extensions.json
NexusNull Dec 28, 2023
d2cac01
re add whitespace
NexusNull Dec 28, 2023
b320088
add admin endpoint
NexusNull Dec 28, 2023
0bb864f
adjust config.py to match base
NexusNull Dec 28, 2023
53f97ae
revert changes to cron.py
NexusNull Dec 28, 2023
7753f60
remove halloween drops
NexusNull Dec 28, 2023
ba84f72
revert several imports
NexusNull Dec 28, 2023
98e6587
re add functions.js
NexusNull Dec 28, 2023
0c2c2e9
missed import change
NexusNull Dec 28, 2023
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
47 changes: 47 additions & 0 deletions .github/workflows/setup_servers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Deploy Infrastructure and Run Ansible

on:
push:
branches:
- main

jobs:
deploy:
concurrency: staging_environment
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Terraform
uses: hashicorp/[email protected]
with:
terraform_version: 1.1.0 # You can specify the version you want to use

- uses: terraform-cache/terraform-cache@v1

- name: Initialize Terraform
working-directory: ./cicd/infra
run: terraform init
env:
TF_HTTP_ADDRESS: ${{ secrets.TF_HTTP_ADDRESS }}
TF_HTTP_USERNAME: ${{ secrets.TF_HTTP_USERNAME }}
TF_HTTP_PASSWORD: ${{ secrets.TF_HTTP_PASSWORD }}

- name: Terraform Apply
working-directory: ./cicd/infra
run: terraform apply -auto-approve -input=false
env:
TF_VAR_hcloud_token: ${{ secrets.hcloud_token }}
TF_VAR_base_url: ${{ secrets.TF_VAR_base_url }}
TF_HTTP_ADDRESS: ${{ secrets.TF_HTTP_ADDRESS }}
TF_HTTP_USERNAME: ${{ secrets.TF_HTTP_USERNAME }}
TF_HTTP_PASSWORD: ${{ secrets.TF_HTTP_PASSWORD }}

- name: Run Ansible Playbook
uses: dawidd6/action-ansible-playbook@v2
with:
playbook: ./cicd/setup/playbook.yml
key: ${{ secrets.HETZNER_PRIVATE_KEY }}
options: |
--inventory ./cicd/setup/inventory.yml
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,12 @@
# System Files
.DS_Store
Thumbs.db
# Terraform secrets
*.tfvars
.terraform
.terraform.lock.hcl
*.tfstate
*.tfstate.backup
**/.terraform
# Editor files
.idea
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"]
}
}
28 changes: 14 additions & 14 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def signup_or_login_api(**args):
#time.sleep(10)
self,domain,email,password,only_login,only_signup,mobile=gdmuld(args,"self","domain","email","password","only_login","only_signup","mobile")
logging.info("Signup or Login")

try: email=purify_email(email)
except: return jhtmle(self,"Invalid Email")

Expand All @@ -20,7 +20,7 @@ def signup_or_login_api(**args):
if msince(existing.last_online)>15 and msince(gf(existing,"last_auth",really_old))>15: pass # [15/05/22]
else: jhtmle(self,"Can't login while inside the bank"); return
if not domain.electron and not only_login and not domain.is_sdk: jhtmle(self,"Can't signup on web"); return

if existing and not only_signup:
if existing.password==hash_password(password,gf(existing,"salt","5")):
def login_transaction():
Expand Down Expand Up @@ -48,7 +48,7 @@ def login_transaction():
if not email: return jhtmle(self,"No Email Entered")

if only_login: return jhtmle(self,"Email Not Found In Records")

signupth=get_signupth()
ip=get_ip_info(self)
referrer=get_referrer(self,ip)
Expand Down Expand Up @@ -79,7 +79,7 @@ def signup_transaction():
user=ndb.transaction(signup_transaction,xg=True,retries=12)

if not user: return jhtmle(self,"Signup Failed")

user,auth=user
set_cookie(self,"auth","%s-%s"%(user.k(),auth))
send_verification_email(domain,user)
Expand Down Expand Up @@ -227,12 +227,12 @@ def servers_and_characters_api(**args):

characters_data=get_characters(user)
characters=characters_to_client(characters_data)

servers_data=get_servers()
servers=servers_to_client(domain,servers_data)

mail=gf(user_data,"mail",0)

logging.info("servers_and_characters")
jhtml(self,[{"type":"servers_and_characters","servers":servers,"characters":characters,"tutorial":data_to_tutorial(user_data),"code_list":gf(user_data,"code_list",{}),"mail":mail,"rewards":gf(user,"rewards",[])}])

Expand Down Expand Up @@ -379,7 +379,7 @@ def load_map_api(**args):
def load_article_api(**args):
#logging.info(col)
self,domain,user,name,func,tutorial,guide,url=gdmuld(args,"self","domain","user","name","func","tutorial","guide","url")
if tutorial: jjson(self,{"type":"article","html":shtml("docs/tutorial/%s.html"%name),"tutorial":tutorial,"url":url})
if tutorial: jjson(self,{"type":"article","html":shtml("docs/tutorial/%s.html"%name),"tutorial":tutorial,"url":url})
elif guide:
from docs.directory import docs
col=[]; prev=None; next=None; found=False
Expand All @@ -401,9 +401,9 @@ def traverse(entry):
break
prev=col[i]
#logging.info([prev,next])
try: jjson(self,{"type":"article","html":shtml("docs/guide/%s.html"%name),"guide":guide,"url":url,"prev":found and prev,"next":found and next})
try: jjson(self,{"type":"article","html":shtml("docs/guide/%s.html"%name),"guide":guide,"url":url,"prev":found and prev,"next":found and next})
except: jjson(self,{"type":"article","html":shtml("docs/articles/%s.html"%name),"url":url,"prev":found and prev,"next":found and next})
elif func: jjson(self,{"type":"article","html":shtml("docs/functions/%s.html"%name),"func":name,"url":url})
elif func: jjson(self,{"type":"article","html":shtml("docs/functions/%s.html"%name),"func":name,"url":url})
else: jjson(self,{"type":"article","html":shtml("docs/articles/%s.html"%name),"url":url})
jhtml(self)

Expand Down Expand Up @@ -577,7 +577,7 @@ def rename_character_api(**args):
if character.owner!=user.k(): return jhtmle(self,"You don't own that character.")
if is_in_game(character): return jhtmle(self,"Character is in game.")
if hsince(gf(character,"last_rename",really_old))<32: return jhtmle(self,"You can rename once every 32 hours!")

if not nname or not is_name_xallowed(nname): return jhtmle(self,"Invalid name")
if get_character(nname,phrase_check=True): return jhtmle(self,"%s is used"%nname)

Expand All @@ -591,7 +591,7 @@ def rename_character_api(**args):
else:
if not gf(character,"last_rename",None) and (character.level<60 or hsince(character.created)<72): price=0
price=640

if user.cash<price: return jhtmle(self,"Not enough shells")

def rename_character_transaction():
Expand Down Expand Up @@ -800,7 +800,7 @@ def is_first_api(**args):
self,domain,user,server,auth_id=gdmuld(args,"self","domain","user","server","auth_id")
if not server: jhtml(self,{"failed":1,"reason":"noserver"}); return
if not user: jhtml(self,{"failed":1,"reason":"nouser"}); return

def first_transaction():
markedphrase=get_by_iid("markedphrase|%s"%dgt("auth",auth_id))
if markedphrase: return False
Expand Down Expand Up @@ -1083,7 +1083,7 @@ def pull_messages_api(**args):
def log_chat_api(**args):
self,domain,server,fro,to,type,message,author=gdmuld(args,"self","domain","server","fro","to","type","message","author")
if not server: return jhtml(self,{"failed":1,"reason":"noserver"})

if type=="server":
Message(owner="~%s"%server.k(),author=author,fro=fro,type="server",info=cGG(message=message),server=server.k()).put()
Message(owner="~global",author=author,fro=fro,type="server",info=cGG(message=message),server=server.k()).put()
Expand Down Expand Up @@ -1735,4 +1735,4 @@ def post(self):

application = webapp.WSGIApplication([
('/api.*',APICall),
],debug=is_sdk)
],debug=is_sdk)
65 changes: 65 additions & 0 deletions cicd/infra/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
module "master" {
name = "master"
source = "./modules/al_server"
datacenter = "nbg1-dc3"
hcloud_token = var.hcloud_token
ssh_keys = data.hcloud_ssh_keys.admin.ssh_keys.*.name
master = {
enabled = true
}
}

module "eu_1_server" {
name = "EU-I"
source = "./modules/al_server"
datacenter = "nbg1-dc3"
hcloud_token = var.hcloud_token
ssh_keys = data.hcloud_ssh_keys.admin.ssh_keys.*.name
server = {
enabled = true
region = "EU"
name = "I"
}
}

module "us_1_server" {
name = "US-I"
source = "./modules/al_server"
datacenter = "hil-dc1"
hcloud_token = var.hcloud_token
ssh_keys = data.hcloud_ssh_keys.admin.ssh_keys.*.name
server = {
enabled = true
region = "US"
name = "I"
}
}

data "hcloud_ssh_keys" "admin" {
with_selector = "role=admin"
}

resource "local_file" "inventory" {
content = templatefile("./templates/inventory.tpl", {
base_url = local.secrets.base_url
keyword = local.secrets.keyword
master = local.secrets.master
bot_key = local.secrets.bot_key
master_server = module.master
game_servers = local.servers
})
filename = "../setup/inventory.yml"
}

locals {
secrets = {
base_url = var.base_url
keyword = random_password.keyword.result
master = random_password.master.result
bot_key = random_password.bot_key.result
}
servers = [
module.us_1_server.details,
module.eu_1_server.details,
]
}
44 changes: 44 additions & 0 deletions cicd/infra/modules/al_server/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
resource "hcloud_server" "server" {
name = var.name
image = "debian-11"
server_type = "cpx21"
datacenter = var.datacenter
ssh_keys = var.ssh_keys
public_net {
ipv4 = hcloud_primary_ip.ip.id
ipv6_enabled = false
}
}

resource "hcloud_primary_ip" "ip" {
name = "${var.name}-ip"
type = "ipv4"
datacenter = var.datacenter
assignee_type = "server"
auto_delete = false
delete_protection = true
}

resource "hcloud_volume_attachment" "main" {
count = var.master.enabled ? 1 : 0
volume_id = hcloud_volume.storage[0].id
server_id = hcloud_server.server.id
automount = true
}


resource "hcloud_volume" "storage" {
count = var.master.enabled ? 1 : 0
name = "${var.name}-storage"
size = 40
format = "ext4"
delete_protection = true
}

output "details" {
value = {
ip: hcloud_primary_ip.ip.ip_address
name: var.server.name
region: var.server.region
}
}
28 changes: 28 additions & 0 deletions cicd/infra/modules/al_server/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
terraform {
required_providers {
tls = {
source = "hashicorp/tls"
version = "4.0.4"
}
ssh = {
source = "loafoe/ssh"
version = "2.3.0"
}
hcloud = {
source = "hetznercloud/hcloud"
version = "1.38.2"
}
cloudinit = {
source = "hashicorp/cloudinit"
version = "2.2.0"
}
template = {
source = "hashicorp/template"
version = "2.2.0"
}
random = {
source = "hashicorp/random"
version = "3.5.1"
}
}
}
38 changes: 38 additions & 0 deletions cicd/infra/modules/al_server/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
variable "hcloud_token" {
sensitive = true
}

variable "datacenter" {
type = string
default = "nbg1-dc3"
}

variable "ssh_keys" {
type = list(string)
}

variable "name" {
type = string
}

variable "master" {
type = object({
enabled = bool
})
default = {
enabled = false
}
}

variable "server" {
type = object({
enabled = bool
region = string
name = string
})
default = {
enabled = false
region = "Undefined"
name = "Undefined"
}
}
Loading