M Jenkinsfile => Jenkinsfile +8 -2
@@ 4,6 4,7 @@ pipeline {
environment {
DOCKER_LOGIN_CREDS = credentials('gitlab-docker-key')
PATH = "/var/lib/jenkins/.cargo/bin:$PATH"
+ INFRA_KEY = credentials('infra_key')
}
stages {
@@ 20,8 21,13 @@ pipeline {
stage('Docker') {
steps {
sh 'docker login registry.gitlab.com -u ${DOCKER_LOGIN_CREDS_USR} -p ${DOCKER_LOGIN_CREDS_PSW}'
- sh 'STK_CHANNEL=bleeding STK_BUILD_NUM=${BUILD_NUMBER} ./spacetime build_docker_api'
- sh 'STK_CHANNEL=bleeding STK_BUILD_NUM=${BUILD_NUMBER} ./spacetime build_docker_server'
+ sh 'STK_CHANNEL=bleeding STK_BUILD_NUM=${BUILD_NUMBER} ./spacetime build_docker'
+ }
+ }
+ stage('Deploy') {
+ steps {
+ sh 'sshpass -p ${INFRA_KEY} ./spacetime infra update-bleeding'
+ sh 'sshpass -p ${INFRA_KEY} ./spacetime infra restart-bleeding'
}
}
}
A ansible/deploy-beta.yaml => ansible/deploy-beta.yaml +50 -0
@@ 0,0 1,50 @@
+- name: Deploy beta servers
+ hosts: starkingdoms_prod_servers_beta
+ vars:
+ # Randomly generated per-deployment secrets
+ api_key: "{{ lookup('community.general.random_string', base64=True, length=24) }}"
+ jwt_signing_secret: "{{ lookup('community.general.random_string', base64=True, length=24) }}"
+
+ # Database info
+ db_name: starkingdoms-bleeding
+
+ # What version of the docker container should be deployed?
+ version: beta
+
+ ws_port: 3204
+ api_port: 3205
+ web_port: 3206
+
+ api_config_dir: /home/stk-deploy/config
+ db_data_dir: /home/stk-deploy/data
+ compose_dir: /home/stk-deploy
+
+ api_url: https://api.beta.starkingdoms.tk
+ game_url: https://beta.starkingdoms.tk
+ tasks:
+ - name: Ensure host connectivity
+ ansible.builtin.ping:
+ - name: Create configuration directory
+ ansible.builtin.file:
+ path: "{{ api_config_dir }}"
+ state: directory
+ mode: 0755
+ - name: Create data directory
+ ansible.builtin.file:
+ path: "{{ db_data_dir }}"
+ state: directory
+ mode: 0755
+ - name: Create API config file
+ ansible.builtin.template:
+ src: ../docker/config.jinja.toml
+ dest: "{{ api_config_dir }}/config.toml"
+ force: no
+ - name: Create docker-compose config file
+ ansible.builtin.template:
+ src: ../docker/docker-compose.jinja.yml
+ dest: "{{ compose_dir }}/docker-compose.yml"
+ force: no
+ - name: Start the server
+ ansible.builtin.shell:
+ cmd: docker-compose up -d
+ chdir: "{{ compose_dir }}"
R ansible/deploy.yaml => ansible/deploy-bleeding.yaml +16 -21
@@ 1,20 1,26 @@
- name: Deploy bleeding servers
hosts: starkingdoms_prod_servers_bleeding
vars:
- api_key: "{{ lookup('community.general.random_string', length=24) }}"
- jwt_signing_secret: "{{ lookup('community.general.random_string', length=24) }}"
- db_user: starkingdoms-bleeding
- db_pass: "{{ lookup('community.general.random_string', length=24) }}"
+ # Randomly generated per-deployment secrets
+ api_key: "{{ lookup('community.general.random_string', base64=True, length=24) }}"
+ jwt_signing_secret: "{{ lookup('community.general.random_string', base64=True, length=24) }}"
+
+ # Database info
db_name: starkingdoms-bleeding
- ws_port: 3000
+
+ # What version of the docker container should be deployed?
version: bleeding
- api_port: 8080
+
+ ws_port: 3204
+ api_port: 3205
+ web_port: 3206
+
api_config_dir: /home/stk-deploy/config
db_data_dir: /home/stk-deploy/data
compose_dir: /home/stk-deploy
+
api_url: https://api.bleeding.starkingdoms.tk
game_url: https://bleeding.starkingdoms.tk
- web_port: 8000
tasks:
- name: Ensure host connectivity
ansible.builtin.ping:
@@ 32,24 38,13 @@
ansible.builtin.template:
src: ../docker/config.jinja.toml
dest: "{{ api_config_dir }}/config.toml"
+ force: no
- name: Create docker-compose config file
ansible.builtin.template:
src: ../docker/docker-compose.jinja.yml
dest: "{{ compose_dir }}/docker-compose.yml"
+ force: no
- name: Start the server
ansible.builtin.shell:
cmd: docker-compose up -d
- chdir: "{{ compose_dir }}"
-
-
-- name: Deploy beta servers
- hosts: starkingdoms_prod_servers_beta
- tasks:
- - name: Ensure host connectivity
- ansible.builtin.ping:
-
-- name: Deploy stable servers
- hosts: starkingdoms_prod_servers_stable
- tasks:
- - name: Ensure host connectivity
- ansible.builtin.ping:>
\ No newline at end of file
+ chdir: "{{ compose_dir }}"<
\ No newline at end of file
A ansible/deploy-stable.yaml => ansible/deploy-stable.yaml +51 -0
@@ 0,0 1,51 @@
+
+- name: Deploy stable servers
+ hosts: starkingdoms_prod_servers_stable
+ vars:
+ # Randomly generated per-deployment secrets
+ api_key: "{{ lookup('community.general.random_string', base64=True, length=24) }}"
+ jwt_signing_secret: "{{ lookup('community.general.random_string', base64=True, length=24) }}"
+
+ # Database info
+ db_name: starkingdoms-bleeding
+
+ # What version of the docker container should be deployed?
+ version: stable
+
+ ws_port: 3204
+ api_port: 3205
+ web_port: 3206
+
+ api_config_dir: /home/stk-deploy/config
+ db_data_dir: /home/stk-deploy/data
+ compose_dir: /home/stk-deploy
+
+ api_url: https://api.starkingdoms.tk
+ game_url: https://starkingdoms.tk
+ tasks:
+ - name: Ensure host connectivity
+ ansible.builtin.ping:
+ - name: Create configuration directory
+ ansible.builtin.file:
+ path: "{{ api_config_dir }}"
+ state: directory
+ mode: 0755
+ - name: Create data directory
+ ansible.builtin.file:
+ path: "{{ db_data_dir }}"
+ state: directory
+ mode: 0755
+ - name: Create API config file
+ ansible.builtin.template:
+ src: ../docker/config.jinja.toml
+ dest: "{{ api_config_dir }}/config.toml"
+ force: no
+ - name: Create docker-compose config file
+ ansible.builtin.template:
+ src: ../docker/docker-compose.jinja.yml
+ dest: "{{ compose_dir }}/docker-compose.yml"
+ force: no
+ - name: Start the server
+ ansible.builtin.shell:
+ cmd: docker-compose up -d
+ chdir: "{{ compose_dir }}"<
\ No newline at end of file
A ansible/restart-beta.yaml => ansible/restart-beta.yaml +15 -0
@@ 0,0 1,15 @@
+- name: Restart beta servers
+ hosts: starkingdoms_prod_servers_beta
+ vars:
+ compose_dir: /home/stk-deploy
+ tasks:
+ - name: Ensure host connectivity
+ ansible.builtin.ping:
+ - name: Stop the server
+ ansible.builtin.shell:
+ cmd: docker-compose down
+ chdir: "{{ compose_dir }}"
+ - name: Start the server
+ ansible.builtin.shell:
+ cmd: docker-compose up -d
+ chdir: "{{ compose_dir }}"<
\ No newline at end of file
A ansible/restart-bleeding.yaml => ansible/restart-bleeding.yaml +15 -0
@@ 0,0 1,15 @@
+- name: Restart bleeding servers
+ hosts: starkingdoms_prod_servers_bleeding
+ vars:
+ compose_dir: /home/stk-deploy
+ tasks:
+ - name: Ensure host connectivity
+ ansible.builtin.ping:
+ - name: Stop the server
+ ansible.builtin.shell:
+ cmd: docker-compose down
+ chdir: "{{ compose_dir }}"
+ - name: Start the server
+ ansible.builtin.shell:
+ cmd: docker-compose up -d
+ chdir: "{{ compose_dir }}"<
\ No newline at end of file
A ansible/restart-stable.yaml => ansible/restart-stable.yaml +15 -0
@@ 0,0 1,15 @@
+- name: Restart stable servers
+ hosts: starkingdoms_prod_servers_stable
+ vars:
+ compose_dir: /home/stk-deploy
+ tasks:
+ - name: Ensure host connectivity
+ ansible.builtin.ping:
+ - name: Stop the server
+ ansible.builtin.shell:
+ cmd: docker-compose down
+ chdir: "{{ compose_dir }}"
+ - name: Start the server
+ ansible.builtin.shell:
+ cmd: docker-compose up -d
+ chdir: "{{ compose_dir }}"<
\ No newline at end of file
A ansible/restart.yaml => ansible/restart.yaml +15 -0
@@ 0,0 1,15 @@
+- name: Restart all servers
+ hosts: starkingdoms_prod_servers
+ vars:
+ compose_dir: /home/stk-deploy
+ tasks:
+ - name: Ensure host connectivity
+ ansible.builtin.ping:
+ - name: Stop the server
+ ansible.builtin.shell:
+ cmd: docker-compose down
+ chdir: "{{ compose_dir }}"
+ - name: Start the server
+ ansible.builtin.shell:
+ cmd: docker-compose up -d
+ chdir: "{{ compose_dir }}"<
\ No newline at end of file
A ansible/start-beta.yaml => ansible/start-beta.yaml +11 -0
@@ 0,0 1,11 @@
+- name: Start beta servers
+ hosts: starkingdoms_prod_servers_beta
+ vars:
+ compose_dir: /home/stk-deploy
+ tasks:
+ - name: Ensure host connectivity
+ ansible.builtin.ping:
+ - name: Start the server
+ ansible.builtin.shell:
+ cmd: docker-compose up -d
+ chdir: "{{ compose_dir }}"<
\ No newline at end of file
A ansible/start-bleeding.yaml => ansible/start-bleeding.yaml +11 -0
@@ 0,0 1,11 @@
+- name: Start bleeding servers
+ hosts: starkingdoms_prod_servers_bleeding
+ vars:
+ compose_dir: /home/stk-deploy
+ tasks:
+ - name: Ensure host connectivity
+ ansible.builtin.ping:
+ - name: Start the server
+ ansible.builtin.shell:
+ cmd: docker-compose up -d
+ chdir: "{{ compose_dir }}"<
\ No newline at end of file
A ansible/start-stable.yaml => ansible/start-stable.yaml +11 -0
@@ 0,0 1,11 @@
+- name: Start stable servers
+ hosts: starkingdoms_prod_servers_beta
+ vars:
+ compose_dir: /home/stk-deploy
+ tasks:
+ - name: Ensure host connectivity
+ ansible.builtin.ping:
+ - name: Start the server
+ ansible.builtin.shell:
+ cmd: docker-compose up -d
+ chdir: "{{ compose_dir }}"<
\ No newline at end of file
A ansible/start.yaml => ansible/start.yaml +11 -0
@@ 0,0 1,11 @@
+- name: Start all servers
+ hosts: starkingdoms_prod_servers
+ vars:
+ compose_dir: /home/stk-deploy
+ tasks:
+ - name: Ensure host connectivity
+ ansible.builtin.ping:
+ - name: Start the server
+ ansible.builtin.shell:
+ cmd: docker-compose up -d
+ chdir: "{{ compose_dir }}"<
\ No newline at end of file
A ansible/stop-beta.yaml => ansible/stop-beta.yaml +11 -0
@@ 0,0 1,11 @@
+- name: Stop beta servers
+ hosts: starkingdoms_prod_servers_beta
+ vars:
+ compose_dir: /home/stk-deploy
+ tasks:
+ - name: Ensure host connectivity
+ ansible.builtin.ping:
+ - name: Stop the server
+ ansible.builtin.shell:
+ cmd: docker-compose down
+ chdir: "{{ compose_dir }}"<
\ No newline at end of file
A ansible/stop-bleeding.yaml => ansible/stop-bleeding.yaml +11 -0
@@ 0,0 1,11 @@
+- name: Stop bleeding servers
+ hosts: starkingdoms_prod_servers_beta
+ vars:
+ compose_dir: /home/stk-deploy
+ tasks:
+ - name: Ensure host connectivity
+ ansible.builtin.ping:
+ - name: Stop the server
+ ansible.builtin.shell:
+ cmd: docker-compose down
+ chdir: "{{ compose_dir }}"<
\ No newline at end of file
A ansible/stop-stable.yaml => ansible/stop-stable.yaml +11 -0
@@ 0,0 1,11 @@
+- name: Stop stable servers
+ hosts: starkingdoms_prod_servers_stable
+ vars:
+ compose_dir: /home/stk-deploy
+ tasks:
+ - name: Ensure host connectivity
+ ansible.builtin.ping:
+ - name: Stop the server
+ ansible.builtin.shell:
+ cmd: docker-compose down
+ chdir: "{{ compose_dir }}"<
\ No newline at end of file
A ansible/stop.yaml => ansible/stop.yaml +11 -0
@@ 0,0 1,11 @@
+- name: Stop all servers
+ hosts: starkingdoms_prod_servers
+ vars:
+ compose_dir: /home/stk-deploy
+ tasks:
+ - name: Ensure host connectivity
+ ansible.builtin.ping:
+ - name: Stop the server
+ ansible.builtin.shell:
+ cmd: docker-compose down
+ chdir: "{{ compose_dir }}"<
\ No newline at end of file
A ansible/update-beta.yaml => ansible/update-beta.yaml +11 -0
@@ 0,0 1,11 @@
+- name: Update beta servers
+ hosts: starkingdoms_prod_servers_beta
+ vars:
+ compose_dir: /home/stk-deploy
+ tasks:
+ - name: Ensure host connectivity
+ ansible.builtin.ping:
+ - name: Update the server
+ ansible.builtin.shell:
+ cmd: docker-compose pull
+ chdir: "{{ compose_dir }}"<
\ No newline at end of file
A ansible/update-bleeding.yaml => ansible/update-bleeding.yaml +11 -0
@@ 0,0 1,11 @@
+- name: Update bleeding servers
+ hosts: starkingdoms_prod_servers_bleeding
+ vars:
+ compose_dir: /home/stk-deploy
+ tasks:
+ - name: Ensure host connectivity
+ ansible.builtin.ping:
+ - name: Update the server
+ ansible.builtin.shell:
+ cmd: docker-compose pull
+ chdir: "{{ compose_dir }}"<
\ No newline at end of file
A ansible/update-stable.yaml => ansible/update-stable.yaml +11 -0
@@ 0,0 1,11 @@
+- name: Update stable servers
+ hosts: starkingdoms_prod_servers_stable
+ vars:
+ compose_dir: /home/stk-deploy
+ tasks:
+ - name: Ensure host connectivity
+ ansible.builtin.ping:
+ - name: Update the server
+ ansible.builtin.shell:
+ cmd: docker-compose pull
+ chdir: "{{ compose_dir }}"<
\ No newline at end of file
A ansible/update.yaml => ansible/update.yaml +11 -0
@@ 0,0 1,11 @@
+- name: Update all servers
+ hosts: starkingdoms_prod_servers
+ vars:
+ compose_dir: /home/stk-deploy
+ tasks:
+ - name: Ensure host connectivity
+ ansible.builtin.ping:
+ - name: Update the server
+ ansible.builtin.shell:
+ cmd: docker-compose pull
+ chdir: "{{ compose_dir }}"<
\ No newline at end of file
A beta.Jenkinsfile => beta.Jenkinsfile +27 -0
@@ 0,0 1,27 @@
+pipeline {
+ agent any
+
+ environment {
+ DOCKER_LOGIN_CREDS = credentials('gitlab-docker-key')
+ PATH = "/var/lib/jenkins/.cargo/bin:$PATH"
+ }
+
+ stages {
+ stage('Build') {
+ steps {
+ sh 'cargo build --locked'
+ }
+ }
+ stage('Clippy') {
+ steps {
+ sh 'cargo clippy --locked'
+ }
+ }
+ stage('Docker') {
+ steps {
+ sh 'docker login registry.gitlab.com -u ${DOCKER_LOGIN_CREDS_USR} -p ${DOCKER_LOGIN_CREDS_PSW}'
+ sh 'STK_CHANNEL=beta STK_BUILD_NUM=${BUILD_NUMBER} ./spacetime build_docker_beta'
+ }
+ }
+ }
+}<
\ No newline at end of file
M docker/config.jinja.toml => docker/config.jinja.toml +1 -1
@@ 13,7 13,7 @@ public_key = "-----BEGIN PUBLIC KEY-----\nMIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgH
issuer = "https://api.e3t.cc"
[database]
-url = "postgres://{{ db_user }}:{{ db_pass }}@postgres/{{ db_name }}"
+url = "postgres://postgres@postgres/{{ db_name }}"
[server]
listen = "0.0.0.0:8080"
M docker/docker-compose.jinja.yml => docker/docker-compose.jinja.yml +3 -4
@@ 9,8 9,8 @@ services:
ports:
- {{ ws_port }}:3000
environment:
- - STK_API_KEY={{ api_key }}
- - STK_API_URL=http://api:8080
+ - "STK_API_KEY={{ api_key }}"
+ - "STK_API_URL=http://api:8080"
api:
image: registry.gitlab.com/starkingdoms.tk/starkingdoms.tk:api-{{ version }}
depends_on:
@@ 27,9 27,8 @@ services:
# docker run --name basic-postgres --rm -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=4y7sV96vA9wv46VR -e PGDATA=/var/lib/postgresql/data/pgdata -v /tmp:/var/lib/postgresql/data -p 5432:5432 -it postgres:14.1-alpine
image: postgres:14.1-alpine
environment:
- - POSTGRES_USER={{ db_user }}
- - POSTGRES_PASSWORD={{ db_pass }}
- POSTGRES_DB={{ db_name }}
- PGDATA=/var/lib/postgresql/data/pgdata
+ - POSTGRES_HOST_AUTH_METHOD=trust
volumes:
- {{ db_data_dir }}:/var/lib/postgresql/data=
\ No newline at end of file
M spacetime => spacetime +48 -7
@@ 46,6 46,7 @@ sub_help() {
echo " build_docker_server_stable - Build the server container and push it as server-stable" # done
echo " build_docker_web_stable - Build the web dockerfile and push it as web-stable" # done
echo " build_docker_stable - Build the stable api, web and server containers" # done
+ echo " infra [action] - Run an infrastructure command. Requires an infrastructure key" # done
}
check_install_cargo() {
@@ 172,7 173,20 @@ build_docker() {
docker buildx build -f "$SCRIPT_DIR/$1".Dockerfile -t registry.gitlab.com/starkingdoms.tk/starkingdoms.tk:"$1"-"$2" "$SCRIPT_DIR"
docker push registry.gitlab.com/starkingdoms.tk/starkingdoms.tk:"$1"-$(git rev-parse --short HEAD)
docker push registry.gitlab.com/starkingdoms.tk/starkingdoms.tk:"$1"-"$2"
+}
+
+swap_out_server_for() {
+ echo "[*] Swapping out API server"
+ sed -i'orig' "s/let api_server = \"http:\\/\\/localhost:8080\";/let api_server = \"https:\\/\\/api.${1}.${2}\";/" "$SCRIPT_DIR/client/index.html"
+ echo "[*] Swapping out game server"
+ sed -i "s/let servers = \[\"localhost:3000\"\];/let servers = [\"${1}.${2}\"];/" "$SCRIPT_DIR/client/index.html"
+}
+sub_swap_server() {
+ swap_out_server_for "$1" "$2"
+}
+sub_reset_server() {
+ mv client/index.htmlorig client/index.html
}
sub_build_docker_api() {
@@ 185,19 199,18 @@ sub_build_docker_server() {
build_docker "server" "bleeding"
}
-swap_out_server_for() {
- echo "[*] Swapping out API server"
- sed -i'orig' "s/let api_server = \"http:\\/\\/localhost:8080\";/let api_server = \"https:\\/\\/api.$1.$2\";/" "$SCRIPT_DIR/client/index.html"
- echo "[*] Swapping out game server"
- sed -i "s/let servers = [\"localhost:3000\"];/let servers = [\"https:\\/\\/$1.$2\"];/" "$SCRIPT_DIR/client/index.html"
-}
-
sub_build_docker_web() {
swap_out_server_for "bleeding" "starkingdoms.io"
build_docker "web" "bleeding"
mv "$SCRIPT_DIR/client/index.htmlorig" "$SCRIPT_DIR/client/index.html"
}
+sub_build_docker_web_stable() {
+ swap_out_server_for "starkingdoms" "io"
+ build_docker "web" "stable"
+ mv "$SCRIPT_DIR/client/index.htmlorig" "$SCRIPT_DIR/client/index.html"
+}
+
sub_build_docker_api_stable() {
sub_build_api_prod
build_docker "api" "stable"
@@ 208,18 221,46 @@ sub_build_docker_server_stable() {
build_docker "server" "stable"
}
+
+sub_build_docker_api_beta() {
+ sub_build_api_prod
+ build_docker "api" "beta"
+}
+
+sub_build_docker_server_beta() {
+ sub_build_server_prod
+ build_docker "server" "beta"
+}
+
+sub_build_docker_web_beta() {
+ swap_out_server_for "beta" "starkingdoms.io"
+ build_docker "web" "beta"
+ mv "$SCRIPT_DIR/client/index.htmlorig" "$SCRIPT_DIR/client/index.html"
+}
+
sub_build_docker() {
sub_build_docker_api
sub_build_docker_server
sub_build_docker_web
}
+sub_build_docker_beta() {
+ sub_build_docker_api_beta
+ sub_build_docker_server_beta
+ sub_build_docker_web_beta
+}
+
sub_build_docker_stable() {
sub_build_docker_api_stable
sub_build_docker_server_stable
sub_build_docker_web_stable
}
+sub_infra() {
+ echo "[*] Connecting to infrastructure manager server. If you are prompted for a password, enter your infrastructure key. You may be prompted several times."
+ ssh team@10.16.1.3 /home/team/run_ansible.sh "$1"
+}
+
subcommand=$1
case $subcommand in
"" | "-h" | "--help" | "help")
A stable.Jenkinsfile => stable.Jenkinsfile +27 -0
@@ 0,0 1,27 @@
+pipeline {
+ agent any
+
+ environment {
+ DOCKER_LOGIN_CREDS = credentials('gitlab-docker-key')
+ PATH = "/var/lib/jenkins/.cargo/bin:$PATH"
+ }
+
+ stages {
+ stage('Build') {
+ steps {
+ sh 'cargo build --locked'
+ }
+ }
+ stage('Clippy') {
+ steps {
+ sh 'cargo clippy --locked'
+ }
+ }
+ stage('Docker') {
+ steps {
+ sh 'docker login registry.gitlab.com -u ${DOCKER_LOGIN_CREDS_USR} -p ${DOCKER_LOGIN_CREDS_PSW}'
+ sh 'STK_CHANNEL=stable STK_BUILD_NUM=${BUILD_NUMBER} ./spacetime build_docker_stable'
+ }
+ }
+ }
+}<
\ No newline at end of file