diff --git a/.github/workflows/arena-brazil-testing-deploy.yml b/.github/workflows/arena-brazil-testing-deploy.yml index 2df6338a6..b4c8130ef 100644 --- a/.github/workflows/arena-brazil-testing-deploy.yml +++ b/.github/workflows/arena-brazil-testing-deploy.yml @@ -1,16 +1,6 @@ name: Deploy to Brazil Arena testing on: workflow_dispatch: - inputs: - release: - type: choice - description: What release to deploy - options: - - game_backend - - arena - - arena_load_test - - game_client - required: true jobs: build-deploy: @@ -33,28 +23,28 @@ jobs: - name: Create ssh private key file from env var env: SSH_KEY: ${{ secrets.SSH_KEY }} - TS_HOST: ${{ vars.TS_HOST }} + SSH_HOST: ${{ vars.TS_ARENA_HOST }} run: | set -ex mkdir -p ~/.ssh/ sed -E 's/(-+(BEGIN|END) OPENSSH PRIVATE KEY-+) *| +/\1\n/g' <<< "$SSH_KEY" > ~/.ssh/id_ed25519 chmod 400 ~/.ssh/id_ed25519 - retries=5; until ssh-keyscan $TS_HOST >> ~/.ssh/known_hosts || [ $retries -eq 0 ]; do ((retries--)); sleep 5; done + retries=5; until ssh-keyscan $SSH_HOST >> ~/.ssh/known_hosts || [ $retries -eq 0 ]; do ((retries--)); sleep 5; done - name: Copy deploy script env: SSH_USERNAME: ${{ vars.SSH_USERNAME }} - SSH_HOST: ${{ vars.TS_HOST }} + SSH_HOST: ${{ vars.TS_ARENA_HOST }} run: | set -ex rsync -avz --mkpath devops/deploy.sh ${SSH_USERNAME}@${SSH_HOST}:/home/${SSH_USERNAME}/deploy-script/ - name: Execute deploy script env: - SSH_HOST: ${{ vars.TS_HOST }} + SSH_HOST: ${{ vars.TS_ARENA_HOST }} SSH_USERNAME: ${{ vars.SSH_USERNAME }} MIX_ENV: ${{ vars.MIX_ENV }} - RELEASE: ${{ inputs.release }} + RELEASE: arena PHX_SERVER: ${{ vars.PHX_SERVER }} PHX_HOST: ${{ vars.HOST }} PORT: ${{ vars.ARENA_PORT }} diff --git a/.github/workflows/arena-europe-testing-deploy.yml b/.github/workflows/arena-europe-testing-deploy.yml index f76a1cc61..e9763fcfd 100644 --- a/.github/workflows/arena-europe-testing-deploy.yml +++ b/.github/workflows/arena-europe-testing-deploy.yml @@ -1,16 +1,6 @@ name: Deploy to Europe Arena testing on: workflow_dispatch: - inputs: - release: - type: choice - description: What release to deploy - options: - - game_backend - - arena - - arena_load_test - - game_client - required: true jobs: build-deploy: @@ -33,28 +23,28 @@ jobs: - name: Create ssh private key file from env var env: SSH_KEY: ${{ secrets.SSH_KEY }} - TS_HOST: ${{ vars.TS_HOST }} + SSH_HOST: ${{ vars.TS_ARENA_HOST }} run: | set -ex mkdir -p ~/.ssh/ sed -E 's/(-+(BEGIN|END) OPENSSH PRIVATE KEY-+) *| +/\1\n/g' <<< "$SSH_KEY" > ~/.ssh/id_ed25519 chmod 400 ~/.ssh/id_ed25519 - retries=5; until ssh-keyscan $TS_HOST >> ~/.ssh/known_hosts || [ $retries -eq 0 ]; do ((retries--)); sleep 5; done + retries=5; until ssh-keyscan $SSH_HOST >> ~/.ssh/known_hosts || [ $retries -eq 0 ]; do ((retries--)); sleep 5; done - name: Copy deploy script env: SSH_USERNAME: ${{ vars.SSH_USERNAME }} - SSH_HOST: ${{ vars.TS_HOST }} + SSH_HOST: ${{ vars.TS_ARENA_HOST }} run: | set -ex rsync -avz --mkpath devops/deploy.sh ${SSH_USERNAME}@${SSH_HOST}:/home/${SSH_USERNAME}/deploy-script/ - name: Execute deploy script env: - SSH_HOST: ${{ vars.TS_HOST }} + SSH_HOST: ${{ vars.TS_ARENA_HOST }} SSH_USERNAME: ${{ vars.SSH_USERNAME }} MIX_ENV: ${{ vars.MIX_ENV }} - RELEASE: ${{ inputs.release }} + RELEASE: arena PHX_SERVER: ${{ vars.PHX_SERVER }} PHX_HOST: ${{ vars.HOST }} PORT: ${{ vars.ARENA_PORT }} diff --git a/.github/workflows/central-brazil-testing-deploy.yml b/.github/workflows/central-brazil-testing-deploy.yml new file mode 100644 index 000000000..847966c9b --- /dev/null +++ b/.github/workflows/central-brazil-testing-deploy.yml @@ -0,0 +1,73 @@ +name: Deploy to Brazil Central testing +on: + workflow_dispatch: + +jobs: + build-deploy: + name: Build and deploy to Brazil testing + runs-on: ubuntu-latest + environment: + name: testing-brazil + url: https://central-europe-testing.curseofmirra.com/ + + steps: + - uses: actions/checkout@v4 + + - name: Tailscale + uses: tailscale/github-action@v2 + with: + oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }} + oauth-secret: ${{ secrets.TS_OAUTH_SECRET }} + tags: tag:ci + + - name: Create ssh private key file from env var + env: + SSH_KEY: ${{ secrets.SSH_KEY }} + SSH_HOST: ${{ vars.TS_CENTRAL_HOST }} + run: | + set -ex + mkdir -p ~/.ssh/ + sed -E 's/(-+(BEGIN|END) OPENSSH PRIVATE KEY-+) *| +/\1\n/g' <<< "$SSH_KEY" > ~/.ssh/id_ed25519 + chmod 400 ~/.ssh/id_ed25519 + retries=5; until ssh-keyscan $SSH_HOST >> ~/.ssh/known_hosts || [ $retries -eq 0 ]; do ((retries--)); sleep 5; done + + - name: Copy deploy script + env: + SSH_USERNAME: ${{ vars.SSH_USERNAME }} + SSH_HOST: ${{ vars.TS_CENTRAL_HOST }} + run: | + set -ex + rsync -avz --mkpath devops/deploy.sh ${SSH_USERNAME}@${SSH_HOST}:/home/${SSH_USERNAME}/deploy-script/ + + - name: Execute deploy script + env: + SSH_HOST: ${{ vars.TS_CENTRAL_HOST }} + SSH_USERNAME: ${{ vars.SSH_USERNAME }} + MIX_ENV: ${{ vars.MIX_ENV }} + RELEASE: central_backend + PHX_SERVER: ${{ vars.PHX_SERVER }} + PHX_HOST: ${{ vars.HOST }} + PORT: ${{ vars.ARENA_PORT }} + BOT_MANAGER_PORT: ${{ vars.BOT_MANAGER_PORT }} + BOT_MANAGER_HOST: ${{ vars.LOADTEST_CLIENT_HOST }} + DATABASE_URL: ${{ secrets.DATABASE_URL }} + SECRET_KEY_BASE: ${{ secrets.SECRET_KEY_BASE }} + NEWRELIC_APP_NAME: ${{ vars.NEWRELIC_APP_NAME }} + NEWRELIC_KEY: ${{ secrets.NEWRELIC_KEY }} + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} + run: | + set -ex + ssh ${SSH_USERNAME}@${SSH_HOST} \ + BRANCH_NAME=${BRANCH_NAME} \ + MIX_ENV=${MIX_ENV} \ + RELEASE=${RELEASE} \ + PHX_SERVER=${PHX_SERVER} \ + PHX_HOST=${PHX_HOST} \ + PORT=${PORT} \ + BOT_MANAGER_PORT=${BOT_MANAGER_PORT} \ + BOT_MANAGER_HOST=${BOT_MANAGER_HOST} \ + DATABASE_URL=${DATABASE_URL} \ + SECRET_KEY_BASE=${SECRET_KEY_BASE} \ + NEWRELIC_APP_NAME=${NEWRELIC_APP_NAME} \ + NEWRELIC_KEY=${NEWRELIC_KEY} \ + /home/${SSH_USERNAME}/deploy-script/deploy.sh diff --git a/.github/workflows/central-europe-testing-deploy.yml b/.github/workflows/central-europe-testing-deploy.yml new file mode 100644 index 000000000..b4876c094 --- /dev/null +++ b/.github/workflows/central-europe-testing-deploy.yml @@ -0,0 +1,73 @@ +name: Deploy to Europe Central testing +on: + workflow_dispatch: + +jobs: + build-deploy: + name: Build and deploy to Europe testing + runs-on: ubuntu-latest + environment: + name: testing-europe + url: https://central-europe-testing.curseofmirra.com/ + + steps: + - uses: actions/checkout@v4 + + - name: Tailscale + uses: tailscale/github-action@v2 + with: + oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }} + oauth-secret: ${{ secrets.TS_OAUTH_SECRET }} + tags: tag:ci + + - name: Create ssh private key file from env var + env: + SSH_KEY: ${{ secrets.SSH_KEY }} + SSH_HOST: ${{ vars.TS_CENTRAL_HOST }} + run: | + set -ex + mkdir -p ~/.ssh/ + sed -E 's/(-+(BEGIN|END) OPENSSH PRIVATE KEY-+) *| +/\1\n/g' <<< "$SSH_KEY" > ~/.ssh/id_ed25519 + chmod 400 ~/.ssh/id_ed25519 + retries=5; until ssh-keyscan $SSH_HOST >> ~/.ssh/known_hosts || [ $retries -eq 0 ]; do ((retries--)); sleep 5; done + + - name: Copy deploy script + env: + SSH_USERNAME: ${{ vars.SSH_USERNAME }} + SSH_HOST: ${{ vars.TS_CENTRAL_HOST }} + run: | + set -ex + rsync -avz --mkpath devops/deploy.sh ${SSH_USERNAME}@${SSH_HOST}:/home/${SSH_USERNAME}/deploy-script/ + + - name: Execute deploy script + env: + SSH_HOST: ${{ vars.TS_CENTRAL_HOST }} + SSH_USERNAME: ${{ vars.SSH_USERNAME }} + MIX_ENV: ${{ vars.MIX_ENV }} + RELEASE: central_backend + PHX_SERVER: ${{ vars.PHX_SERVER }} + PHX_HOST: ${{ vars.HOST }} + PORT: ${{ vars.ARENA_PORT }} + BOT_MANAGER_PORT: ${{ vars.BOT_MANAGER_PORT }} + BOT_MANAGER_HOST: ${{ vars.LOADTEST_CLIENT_HOST }} + DATABASE_URL: ${{ secrets.DATABASE_URL }} + SECRET_KEY_BASE: ${{ secrets.SECRET_KEY_BASE }} + NEWRELIC_APP_NAME: ${{ vars.NEWRELIC_APP_NAME }} + NEWRELIC_KEY: ${{ secrets.NEWRELIC_KEY }} + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} + run: | + set -ex + ssh ${SSH_USERNAME}@${SSH_HOST} \ + BRANCH_NAME=${BRANCH_NAME} \ + MIX_ENV=${MIX_ENV} \ + RELEASE=${RELEASE} \ + PHX_SERVER=${PHX_SERVER} \ + PHX_HOST=${PHX_HOST} \ + PORT=${PORT} \ + BOT_MANAGER_PORT=${BOT_MANAGER_PORT} \ + BOT_MANAGER_HOST=${BOT_MANAGER_HOST} \ + DATABASE_URL=${DATABASE_URL} \ + SECRET_KEY_BASE=${SECRET_KEY_BASE} \ + NEWRELIC_APP_NAME=${NEWRELIC_APP_NAME} \ + NEWRELIC_KEY=${NEWRELIC_KEY} \ + /home/${SSH_USERNAME}/deploy-script/deploy.sh diff --git a/.github/workflows/loadtest-brazil-client-deploy.yml b/.github/workflows/loadtest-brazil-client-deploy.yml index 7c369c227..859a505ef 100644 --- a/.github/workflows/loadtest-brazil-client-deploy.yml +++ b/.github/workflows/loadtest-brazil-client-deploy.yml @@ -6,10 +6,7 @@ on: type: choice description: What release to deploy options: - - game_backend - - arena - arena_load_test - - game_client - bot_manager required: true target_server: @@ -40,13 +37,13 @@ jobs: - name: Create ssh private key file from env var env: SSH_KEY: ${{ secrets.SSH_KEY }} - TS_HOST: ${{ vars.TS_LOADTEST_CLIENT_HOST }} + SSH_HOST: ${{ vars.TS_LOADTEST_CLIENT_HOST }} run: | set -ex mkdir -p ~/.ssh/ sed -E 's/(-+(BEGIN|END) OPENSSH PRIVATE KEY-+) *| +/\1\n/g' <<< "$SSH_KEY" > ~/.ssh/id_ed25519 chmod 400 ~/.ssh/id_ed25519 - retries=5; until ssh-keyscan $TS_HOST >> ~/.ssh/known_hosts || [ $retries -eq 0 ]; do ((retries--)); sleep 5; done + retries=5; until ssh-keyscan $SSH_HOST >> ~/.ssh/known_hosts || [ $retries -eq 0 ]; do ((retries--)); sleep 5; done - name: Copy deploy script env: diff --git a/.github/workflows/loadtest-brazil-server-deploy.yml b/.github/workflows/loadtest-brazil-server-deploy.yml index 1ddc68e92..bd16dd12a 100644 --- a/.github/workflows/loadtest-brazil-server-deploy.yml +++ b/.github/workflows/loadtest-brazil-server-deploy.yml @@ -1,16 +1,6 @@ name: Deploy to Brazil Loadtest Server on: workflow_dispatch: - inputs: - release: - type: choice - description: What release to deploy - options: - - game_backend - - arena - - arena_load_test - - game_client - required: true jobs: build-deploy: @@ -33,13 +23,13 @@ jobs: - name: Create ssh private key file from env var env: SSH_KEY: ${{ secrets.SSH_KEY }} - TS_HOST: ${{ vars.TS_LOADTEST_SERVER_HOST }} + SSH_HOST: ${{ vars.TS_LOADTEST_SERVER_HOST }} run: | set -ex mkdir -p ~/.ssh/ sed -E 's/(-+(BEGIN|END) OPENSSH PRIVATE KEY-+) *| +/\1\n/g' <<< "$SSH_KEY" > ~/.ssh/id_ed25519 chmod 400 ~/.ssh/id_ed25519 - retries=5; until ssh-keyscan $TS_HOST >> ~/.ssh/known_hosts || [ $retries -eq 0 ]; do ((retries--)); sleep 5; done + retries=5; until ssh-keyscan $SSH_HOST >> ~/.ssh/known_hosts || [ $retries -eq 0 ]; do ((retries--)); sleep 5; done - name: Copy deploy script env: @@ -51,10 +41,11 @@ jobs: - name: Execute deploy script env: + XDG_RUNTIME_DIR: /run/user/1001 # Temporary fix for systemd commands. SSH_HOST: ${{ vars.TS_LOADTEST_SERVER_HOST }} SSH_USERNAME: ${{ vars.SSH_USERNAME }} MIX_ENV: ${{ vars.MIX_ENV }} - RELEASE: ${{ inputs.release }} + RELEASE: arena PHX_SERVER: ${{ vars.PHX_SERVER }} PHX_HOST: ${{ vars.LOADTEST_SERVER_HOST }} PORT: ${{ vars.ARENA_PORT }} @@ -67,6 +58,7 @@ jobs: run: | set -ex ssh ${SSH_USERNAME}@${SSH_HOST} \ + XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR} \ BRANCH_NAME=${BRANCH_NAME} \ MIX_ENV=${MIX_ENV} \ RELEASE=${RELEASE} \ diff --git a/.github/workflows/loadtest-europe-client-deploy.yml b/.github/workflows/loadtest-europe-client-deploy.yml index 9d66a3062..e7e64dcf4 100644 --- a/.github/workflows/loadtest-europe-client-deploy.yml +++ b/.github/workflows/loadtest-europe-client-deploy.yml @@ -6,10 +6,7 @@ on: type: choice description: What release to deploy options: - - game_backend - - arena - arena_load_test - - game_client - bot_manager required: true target_server: @@ -40,13 +37,13 @@ jobs: - name: Create ssh private key file from env var env: SSH_KEY: ${{ secrets.SSH_KEY }} - TS_HOST: ${{ vars.TS_LOADTEST_CLIENT_HOST }} + SSH_HOST: ${{ vars.TS_LOADTEST_CLIENT_HOST }} run: | set -ex mkdir -p ~/.ssh/ sed -E 's/(-+(BEGIN|END) OPENSSH PRIVATE KEY-+) *| +/\1\n/g' <<< "$SSH_KEY" > ~/.ssh/id_ed25519 chmod 400 ~/.ssh/id_ed25519 - retries=5; until ssh-keyscan $TS_HOST >> ~/.ssh/known_hosts || [ $retries -eq 0 ]; do ((retries--)); sleep 5; done + retries=5; until ssh-keyscan $SSH_HOST >> ~/.ssh/known_hosts || [ $retries -eq 0 ]; do ((retries--)); sleep 5; done - name: Copy deploy script env: diff --git a/.github/workflows/loadtest-europe-server-deploy.yml b/.github/workflows/loadtest-europe-server-deploy.yml index 645a3ba94..808f3fc6f 100644 --- a/.github/workflows/loadtest-europe-server-deploy.yml +++ b/.github/workflows/loadtest-europe-server-deploy.yml @@ -1,16 +1,6 @@ name: Deploy to Europe Loadtest Server on: workflow_dispatch: - inputs: - release: - type: choice - description: What release to deploy - options: - - game_backend - - arena - - arena_load_test - - game_client - required: true jobs: build-deploy: @@ -33,13 +23,13 @@ jobs: - name: Create ssh private key file from env var env: SSH_KEY: ${{ secrets.SSH_KEY }} - TS_HOST: ${{ vars.TS_LOADTEST_SERVER_HOST }} + SSH_HOST: ${{ vars.TS_LOADTEST_SERVER_HOST }} run: | set -ex mkdir -p ~/.ssh/ sed -E 's/(-+(BEGIN|END) OPENSSH PRIVATE KEY-+) *| +/\1\n/g' <<< "$SSH_KEY" > ~/.ssh/id_ed25519 chmod 400 ~/.ssh/id_ed25519 - retries=5; until ssh-keyscan $TS_HOST >> ~/.ssh/known_hosts || [ $retries -eq 0 ]; do ((retries--)); sleep 5; done + retries=5; until ssh-keyscan $SSH_HOST >> ~/.ssh/known_hosts || [ $retries -eq 0 ]; do ((retries--)); sleep 5; done - name: Copy deploy script env: @@ -54,7 +44,7 @@ jobs: SSH_HOST: ${{ vars.TS_LOADTEST_SERVER_HOST }} SSH_USERNAME: ${{ vars.SSH_USERNAME }} MIX_ENV: ${{ vars.MIX_ENV }} - RELEASE: ${{ inputs.release }} + RELEASE: arena PHX_SERVER: ${{ vars.PHX_SERVER }} PHX_HOST: ${{ vars.LOADTEST_SERVER_HOST }} PORT: ${{ vars.ARENA_PORT }} diff --git a/devops/deploy.sh b/devops/deploy.sh index e1bda7cd7..70ff0cf65 100755 --- a/devops/deploy.sh +++ b/devops/deploy.sh @@ -17,7 +17,7 @@ mix deps.get --only $MIX_ENV mix deps.compile mix compile mix release ${RELEASE} --overwrite -if [ ${RELEASE} == "game_backend" ]; then +if [ ${RELEASE} == "central_backend" ]; then mix ecto.migrate fi @@ -26,13 +26,6 @@ mv /tmp/mirra_backend $HOME/ mkdir -p $HOME/.config/systemd/user/ -existing_service=$(ls $HOME/.config/systemd/user/*.service 2>/dev/null) - -if [[ $(wc -l <<<$existing_service) > 1 || "$(basename ${existing_service})" != "${RELEASE}.service" ]]; then - echo "The release you are trying to deploy is not the same as the installed" - exit 1 -fi - cat <$HOME/.config/systemd/user/${RELEASE}.service [Unit] Description=$RELEASE @@ -47,7 +40,7 @@ EnvironmentFile=$HOME/.env LimitNOFILE=4000 [Install] -WantedBy=multi-user.target +WantedBy=default.target EOF systemctl --user enable $RELEASE diff --git a/mix.exs b/mix.exs index 88856650e..02d174251 100644 --- a/mix.exs +++ b/mix.exs @@ -45,8 +45,9 @@ defmodule MirraBackend.MixProject do [ arena: [applications: [arena: :permanent]], arena_load_test: [applications: [arena_load_test: :permanent]], + bot_manager: [applications: [bot_manager: :permanent]], game_client: [applications: [game_client: :permanent]], - game_backend: [ + central_backend: [ applications: [ champions: :permanent, game_backend: :permanent,