Skip to content

Commit

Permalink
Add MacMini self hosted deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
klaus993 committed Aug 26, 2024
1 parent df42baa commit 4b62dda
Show file tree
Hide file tree
Showing 3 changed files with 228 additions and 0 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/arena-argentina-testing-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
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: Add host keys
env:
SSH_HOST: ${{ vars.TS_ARENA_MACMINI_HOST }}
run: |
set -ex
mkdir -p ~/.ssh/
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 --mkpath 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} \
/home/${SSH_USERNAME}/deploy-script/deploy-macos.sh
146 changes: 146 additions & 0 deletions devops/deploy-macos.sh
Original file line number Diff line number Diff line change
@@ -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 [email protected]: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 <<EOF >${HOME}/.config/systemd/user/${RELEASE}.plist
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.lambdaclass.${RELEASE}</string>
<key>ServiceDescription</key>
<string>Arena</string>
<key>Program</key>
<string>${HOME}/arena/devops/entrypoint-macos.sh</string>
<key>WorkingDirectory</key>
<string>${HOME}/arena/mirra_backend</string>
<key>StandardOutputPath</key>
<string>${HOME}/arena/arena.log</string>
<key>StandardErrorPath</key>
<string>${HOME}/arena/arena.log</string>
<key>EnvironmentVariables</key>
<dict>
<key>PHX_HOST</key>
<string>
${PHX_HOST}
</string>
<key>DATABASE_URL</key>
<string>
${DATABASE_URL}
</string>
<key>PHX_SERVER</key>
<string>
${PHX_SERVER}
</string>
<key>SECRET_KEY_BASE</key>
<string>
${SECRET_KEY_BASE}
</string>
<key>JWT_PRIVATE_KEY_BASE_64</key>
<string>
${JWT_PRIVATE_KEY_BASE_64}
</string>
<key>PORT</key>
<string>
${PORT}
</string>
<key>RELEASE_NODE</key>
<string>
${RELEASE_NODE}
</string>
<key>GATEWAY_URL</key>
<string>
${GATEWAY_URL}
</string>
<key>METRICS_ENDPOINT_PORT</key>
<string>
${METRICS_ENDPOINT_PORT}
</string>
<key>OVERRIDE_JWT</key>
<string>
${OVERRIDE_JWT}
</string>
<key>GOOGLE_CLIENT_ID</key>
<string>
${GOOGLE_CLIENT_ID}
</string>
<key>BOT_MANAGER_PORT</key>
<string>
${BOT_MANAGER_PORT}
</string>
<key>BOT_MANAGER_HOST</key>
<string>
${BOT_MANAGER_HOST}
</string>
<key>CONFIGURATOR_HOST</key>
<string>
${CONFIGURATOR_HOST}
</string>
<key>CONFIGURATOR_GOOGLE_CLIENT_ID</key>
<string>
${CONFIGURATOR_GOOGLE_CLIENT_ID}
</string>
<key>CONFIGURATOR_GOOGLE_CLIENT_SECRET</key>
<string>
${CONFIGURATOR_GOOGLE_CLIENT_SECRET}
</string>
<key>RELEASE</key>
<string>
${RELEASE}
</string>
<key>TARGET_SERVER</key>
<string>
${TARGET_SERVER}
</string>
<key>LOADTEST_EUROPE_HOST</key>
<string>
${LOADTEST_EUROPE_HOST}
</string>
<key>LOADTEST_BRAZIL_HOST</key>
<string>
${LOADTEST_BRAZIL_HOST}
</string>
</dict>
<key>RunAtLoad</key>
<false />
</dict>
</plist>
EOF

launchctl unload ${HOME}/Library/LaunchAgents/${RELEASE}.plist || true
launchctl load ${HOME}/Library/LaunchAgents/${RELEASE}.plist
launchctl start com.lambdaclass.${RELEASE}
4 changes: 4 additions & 0 deletions devops/entrypoint-macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
set -ex

$HOME/arena/mirra_backend/_build/prod/rel/$RELEASE/bin/$RELEASE start

0 comments on commit 4b62dda

Please sign in to comment.