diff --git a/.github/workflows/arena-argentina-testing-deploy.yaml b/.github/workflows/arena-argentina-testing-deploy.yaml new file mode 100644 index 000000000..8d2f0a5fd --- /dev/null +++ b/.github/workflows/arena-argentina-testing-deploy.yaml @@ -0,0 +1,81 @@ +name: "[MACMINI-TESTING-ARGENTINA] Deploy to Argentina Arena Testing" +on: + workflow_dispatch: + push: + branches: + - deploy-macos + +jobs: + build-deploy: + name: Build and deploy to Argentina Testing + runs-on: ubuntu-latest + environment: + name: testing-brazil + + 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.MACMINI_SSH_KEY }} + SSH_HOST: ${{ vars.TS_ARENA_MACMINI_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: lambdaclass + SSH_HOST: ${{ vars.TS_ARENA_MACMINI_HOST }} + run: | + set -ex + rsync -avz devops/deploy-macos.sh ${SSH_USERNAME}@${SSH_HOST}:/Users/${SSH_USERNAME}/deploy-script/ + + - name: Execute deploy script + env: + SSH_HOST: ${{ vars.TS_ARENA_MACMINI_HOST }} + SSH_USERNAME: lambdaclass + MIX_ENV: ${{ vars.MIX_ENV }} + RELEASE: arena + PHX_SERVER: ${{ vars.PHX_SERVER }} + PHX_HOST: ${{ vars.MACMINI_HOST }} + PORT: ${{ vars.ARENA_PORT }} + GATEWAY_URL: ${{ vars.GATEWAY_URL }} + 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 }} + DBUS_SESSION_BUS_ADDRESS: ${{ vars.DBUS_SESSION_BUS_ADDRESS }} + XDG_RUNTIME_DIR: ${{ vars.XDG_RUNTIME_DIR }} + BRANCH_NAME: "20240826_backend_tests" + 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} \ + BOT_MANAGER_HOST=${BOT_MANAGER_HOST} \ + PORT=${PORT} \ + GATEWAY_URL=${GATEWAY_URL} \ + BOT_MANAGER_PORT=${BOT_MANAGER_PORT} \ + DATABASE_URL=${DATABASE_URL} \ + SECRET_KEY_BASE=${SECRET_KEY_BASE} \ + NEWRELIC_APP_NAME=${NEWRELIC_APP_NAME} \ + NEWRELIC_KEY=${NEWRELIC_KEY} \ + DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS} \ + XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR} \ + /Users/${SSH_USERNAME}/deploy-script/deploy-macos.sh diff --git a/devops/deploy-macos.sh b/devops/deploy-macos.sh new file mode 100755 index 000000000..7cb4d8f94 --- /dev/null +++ b/devops/deploy-macos.sh @@ -0,0 +1,146 @@ +#!/usr/bin/env bash +. "${HOME}/.cargo/env" +set -ex + +if [ -d "/tmp/mirra_backend" ]; then + rm -rf /tmp/mirra_backend +fi + +cd /tmp +git clone git@github.com:lambdaclass/mirra_backend.git --branch ${BRANCH_NAME} mirra_backend +cd mirra_backend + +chmod +x devops/entrypoint.sh + +mix local.hex --force && mix local.rebar --force +mix deps.get --only $MIX_ENV +MIX_ENV=$MIX_ENV mix compile +MIX_ENV=$MIX_ENV mix tailwind configurator --minify +MIX_ENV=$MIX_ENV mix esbuild configurator --minify +MIX_ENV=$MIX_ENV mix phx.digest +mix release ${RELEASE} --overwrite +if [ ${RELEASE} == "central_backend" ]; then + mix ecto.migrate +fi + +rm -rf ${HOME}/arena/mirra_backend +mv /tmp/mirra_backend ${HOME}/ + +mkdir -p ${HOME}/.config/systemd/user/ + +cat <${HOME}/.config/systemd/user/${RELEASE}.plist + + + + + Label + com.lambdaclass.${RELEASE} + + ServiceDescription + Arena + + Program + ${HOME}/arena/devops/entrypoint-macos.sh + + WorkingDirectory + ${HOME}/arena/mirra_backend + + StandardOutputPath + ${HOME}/arena/arena.log + + StandardErrorPath + ${HOME}/arena/arena.log + + EnvironmentVariables + + PHX_HOST + + ${PHX_HOST} + + DATABASE_URL + + ${DATABASE_URL} + + PHX_SERVER + + ${PHX_SERVER} + + SECRET_KEY_BASE + + ${SECRET_KEY_BASE} + + JWT_PRIVATE_KEY_BASE_64 + + ${JWT_PRIVATE_KEY_BASE_64} + + PORT + + ${PORT} + + RELEASE_NODE + + ${RELEASE_NODE} + + GATEWAY_URL + + ${GATEWAY_URL} + + METRICS_ENDPOINT_PORT + + ${METRICS_ENDPOINT_PORT} + + OVERRIDE_JWT + + ${OVERRIDE_JWT} + + GOOGLE_CLIENT_ID + + ${GOOGLE_CLIENT_ID} + + BOT_MANAGER_PORT + + ${BOT_MANAGER_PORT} + + BOT_MANAGER_HOST + + ${BOT_MANAGER_HOST} + + CONFIGURATOR_HOST + + ${CONFIGURATOR_HOST} + + CONFIGURATOR_GOOGLE_CLIENT_ID + + ${CONFIGURATOR_GOOGLE_CLIENT_ID} + + CONFIGURATOR_GOOGLE_CLIENT_SECRET + + ${CONFIGURATOR_GOOGLE_CLIENT_SECRET} + + RELEASE + + ${RELEASE} + + TARGET_SERVER + + ${TARGET_SERVER} + + LOADTEST_EUROPE_HOST + + ${LOADTEST_EUROPE_HOST} + + LOADTEST_BRAZIL_HOST + + ${LOADTEST_BRAZIL_HOST} + + + + RunAtLoad + + + +EOF + +launchctl unload ${HOME}/Library/LaunchAgents/${RELEASE}.plist || true +launchctl load ${HOME}/Library/LaunchAgents/${RELEASE}.plist +launchctl start com.lambdaclass.${RELEASE} diff --git a/devops/entrypoint-macos.sh b/devops/entrypoint-macos.sh new file mode 100755 index 000000000..51989e40c --- /dev/null +++ b/devops/entrypoint-macos.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -ex + +$HOME/arena/mirra_backend/_build/prod/rel/$RELEASE/bin/$RELEASE start