Skip to content

Commit

Permalink
Merge pull request #133 from v00g100skr/beta_build_support
Browse files Browse the repository at this point in the history
Додано підтримку beta прошивок
  • Loading branch information
Foroxon authored Feb 7, 2024
2 parents 3752c82 + 9d6ffa9 commit 80a63f7
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 91 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/beta_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: 🅱️ Release BETA Firmware
on:
workflow_dispatch:
inputs:
release-version:
description: 'Beta version, ex. 3.6 or 3.6.1'
required: true
type: string
run-name: Release BETA ${{ inputs.release-version }}-b${{ github.run_number }}
env:
BETA_VERSION: ${{ inputs.release-version }}-b${{ github.run_number }}
RELEASE_TITLE: Beta ${{ inputs.release-version }}-b${{ github.run_number }}
jobs:
release_beta_firmware:
if: ${{ github.ref_name == 'develop' }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Replace version in firmware source
run: |
sed -i "s/String VERSION = \".*\";/String VERSION = \"${{ env.BETA_VERSION }}\";/" ${{ github.workspace }}/src/firmware/firmware.ino
- name: Compile firmware
uses: ./.github/workflows/firmware-compile
- name: Copy release files to bin folder
run: |
mkdir -p ${{ github.workspace }}/bin_beta/
cp -f ${{ github.workspace }}/src/firmware/build/esp32.esp32.esp32/firmware.ino.bin ${{ github.workspace }}/bin_beta/${{ env.BETA_VERSION }}.bin
cp -f ${{ github.workspace }}/src/firmware/build/esp32.esp32.esp32/firmware.ino.bin ${{ github.workspace }}/bin_beta/latest_beta.bin
- name: Leave only 3 recent BETA builds
run: |
cd ${{ github.workspace }}/bin_beta/
ls -tp | grep -v '/$' | tail -n +5 | xargs -I {} rm -- {}
cd ${{ github.workspace }}
- name: Commit changes
id: commit_changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Beta ${{ env.BETA_VERSION }}"
file_pattern: ${{ github.workspace }}/bin_beta/
- name: Create Beta Pre Release
uses: ncipollo/release-action@v1
with:
artifacts: ${{ github.workspace }}/bin_beta/${{ env.BETA_VERSION }}.bin
name: ${{ env.RELEASE_TITLE }}
commit: ${{ steps.commit_changes.outputs.commit_hash }}
tag: ${{ env.BETA_VERSION }}
generateReleaseNotes: true
allowUpdates: true
prerelease: true
makeLatest: false
- name: Update server test bin list
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SERVER_SSH_USER }}
password: ${{ secrets.SERVER_SSH_PASSWORD }}
script: |
cd /root/ukraine_alarm_map/deploy/
git fetch --all
git checkout ${{ github.ref_name }}
bash redeploy_update_server.sh -s '/root/ukraine_alarm_map/bin' -sb '/root/ukraine_alarm_map/bin_beta' -m ${{ secrets.MEMCACHED_HOST }}
2 changes: 1 addition & 1 deletion .github/workflows/deploy_server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
cd /root/ukraine_alarm_map/deploy/
git fetch --all
git checkout ${{ github.ref_name }}
bash redeploy_update_server.sh -s '/root/ukraine_alarm_map/bin' -m ${{ secrets.MEMCACHED_HOST }}
bash redeploy_update_server.sh -s '/root/ukraine_alarm_map/bin' -sb '/root/ukraine_alarm_map/bin_beta' -m ${{ secrets.MEMCACHED_HOST }}
- name: Redeploy Web Server
if: ${{ inputs.redeploy_web_server || inputs.redeploy_all }}
uses: appleboy/[email protected]
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ jobs:
uses: ./.github/workflows/firmware-compile
- name: Copy release files to bin folder
run: |
mkdir -p ${{ github.workspace }}/bin/
cp -f ${{ github.workspace }}/src/firmware/build/esp32.esp32.esp32/firmware.ino.bin ${{ github.workspace }}/bin/${{ inputs.release-version }}.bin
cp -f ${{ github.workspace }}/src/firmware/build/esp32.esp32.esp32/firmware.ino.bin ${{ github.workspace }}/bin/latest.bin
- name: Leave only 3 recent releases
run: |
cd ${{ github.workspace }}/bin/
ls -tp | grep -v '/$' | tail -n +5 | xargs -I {} rm -- {}
cd ${{ github.workspace }}
- name: Commit changes
id: commit_changes
uses: stefanzweifel/git-auto-commit-action@v5
Expand All @@ -44,6 +50,7 @@ jobs:
tag: ${{ inputs.release-version }}
generateReleaseNotes: true
allowUpdates: true
makeLatest: true
- name: Merge master -> develop
uses: devmasx/merge-branch@master
with:
Expand All @@ -62,5 +69,5 @@ jobs:
cd /root/ukraine_alarm_map/deploy/
git fetch --all
git checkout master
bash redeploy_update_server.sh -s '/root/ukraine_alarm_map/bin' -m ${{ secrets.MEMCACHED_HOST }}
bash redeploy_update_server.sh -s '/root/ukraine_alarm_map/bin' -sb '/root/ukraine_alarm_map/bin_beta' -m ${{ secrets.MEMCACHED_HOST }}
8 changes: 7 additions & 1 deletion deploy/redeploy_update_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Default values
SHARED_PATH=""
SHARED_BETA_PATH=""
MEMCACHED_HOST=""
PORT=8090

Expand All @@ -20,6 +21,10 @@ while [[ $# -gt 0 ]]; do
SHARED_PATH="$2"
shift 2
;;
-sb|--shared-beta-path)
SHARED_BETA_PATH="$2"
shift 2
;;
*)
echo "Unknown argument: $1"
exit 1
Expand All @@ -30,6 +35,7 @@ done
echo "UPDATE_SERVER"

echo "SHARED_PATH: $SHARED_PATH"
echo "SHARED_BETA_PATH: $SHARED_BETA_PATH"
echo "MEMCACHED_HOST: $MEMCACHED_HOST"
echo "PORT: $PORT"

Expand Down Expand Up @@ -58,7 +64,7 @@ docker rm map_update_server || true

# Deploying the new container
echo "Deploying new container..."
docker run --name map_update_server --restart unless-stopped -d -p "$PORT":8080 -v "$SHARED_PATH":/shared_data --env MEMCACHED_HOST="$MEMCACHED_HOST" map_update_server
docker run --name map_update_server --restart unless-stopped -d -p "$PORT":8080 -v "$SHARED_PATH":/shared_data -v "$SHARED_BETA_PATH":/shared_beta_data --env MEMCACHED_HOST="$MEMCACHED_HOST" map_update_server

echo "Container deployed successfully!"

11 changes: 11 additions & 0 deletions deploy/update_server/update_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
memcached_port = int(os.environ.get('MEMCACHED_PORT', 11211))

shared_path = os.environ.get('SHARED_PATH') or '/shared_data'
shared_beta_path = os.environ.get('SHARED_BETA_PATH') or '/shared_beta_data'

HTML_404_PAGE = '''page not found'''
HTML_500_PAGE = '''request error'''
Expand Down Expand Up @@ -56,21 +57,31 @@ async def list(request):
filenames = sorted([file for file in os.listdir(shared_path) if os.path.isfile(os.path.join(shared_path, file))])
return JSONResponse(filenames)

async def list_beta(request):
filenames = sorted([file for file in os.listdir(shared_beta_path) if os.path.isfile(os.path.join(shared_beta_path, file))])
return JSONResponse(filenames)

async def update(request):
return FileResponse(f'{shared_path}/{request.path_params["filename"]}.bin')

async def update_beta(request):
return FileResponse(f'{shared_beta_path}/{request.path_params["filename"]}.bin')


async def update_cache():
mc = Client(memcached_host, 11211)
filenames = sorted([file for file in os.listdir(shared_path) if os.path.isfile(os.path.join(shared_path, file))])
beta_filenames = sorted([file for file in os.listdir(shared_beta_path) if os.path.isfile(os.path.join(shared_beta_path, file))])
await mc.set(b"bins", json.dumps(filenames).encode('utf-8'))
await mc.set(b"test_bins", json.dumps(beta_filenames).encode('utf-8'))


app = Starlette(debug=debug, exception_handlers=exception_handlers, routes=[
Route('/', main),
Route('/list', list),
Route('/betalist', list_beta),
Route('/{filename}.bin', update),
Route('/beta/{filename}.bin', update_beta),
])


Expand Down
24 changes: 22 additions & 2 deletions deploy/websocket_server/websocket_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self):
self.weather = '[]'
self.weather_full = {}
self.bins = '[]'
self.test_bins = '[]'
self.clients = {}
self.blocked_ips = []

Expand Down Expand Up @@ -94,6 +95,11 @@ async def alerts_data(websocket, client, shared_data):
await websocket.send(payload)
logger.info(f"{client_ip}:{client_id} <<< new bins")
client['bins'] = shared_data.bins
if client['test_bins'] != shared_data.test_bins:
payload = '{"payload": "test_bins", "test_bins": %s}' % shared_data.test_bins
await websocket.send(payload)
logger.info(f"{client_ip}:{client_id} <<< new test_bins")
client['test_bins'] = shared_data.test_bins
await asyncio.sleep(0.1)
except websockets.exceptions.ConnectionClosedError:
logger.warning(f"{client_ip}:{client_id} !!! data stopped")
Expand Down Expand Up @@ -127,6 +133,7 @@ async def echo(websocket, path):
'alerts': '[]',
'weather': '[]',
'bins': '[]',
'test_bins': '[]',
'firmware': 'unknown',
'chip_id': 'unknown',
'city': city,
Expand Down Expand Up @@ -205,7 +212,7 @@ async def district_data_v1(district_id):
async def update_shared_data(shared_data, mc):
while True:
logger.debug("memcache check")
alerts, weather, bins, alerts_full, weather_full = await get_data_from_memcached(mc)
alerts, weather, bins, test_bins, alerts_full, weather_full = await get_data_from_memcached(mc)
try:
if alerts != shared_data.alerts:
shared_data.alerts = alerts
Expand All @@ -225,6 +232,13 @@ async def update_shared_data(shared_data, mc):
logger.info(f"bins updated: {bins}")
except Exception as e:
logger.error(f"error in bins: {e}")

try:
if test_bins != shared_data.test_bins:
shared_data.test_bins = test_bins
logger.info(f"test bins updated: {test_bins}")
except Exception as e:
logger.error(f"error in test_bins: {e}")

try:
if alerts_full != shared_data.alerts_full:
Expand Down Expand Up @@ -258,6 +272,7 @@ async def get_data_from_memcached(mc):
alerts_cached = await mc.get(b"alerts_websocket_v1")
weather_cached = await mc.get(b"weather_websocket_v1")
bins_cached = await mc.get(b"bins")
test_bins_cached = await mc.get(b"test_bins")
alerts_full_cached = await mc.get(b"alerts")
weather_full_cached = await mc.get(b"weather")

Expand All @@ -281,6 +296,11 @@ async def get_data_from_memcached(mc):
bins_cached_data = bins_cached.decode('utf-8')
else:
bins_cached_data = '[]'

if test_bins_cached:
test_bins_cached_data = test_bins_cached.decode('utf-8')
else:
test_bins_cached_data = '[]'

if alerts_full_cached:
alerts_full_cached_data = json.loads(alerts_full_cached.decode('utf-8'))['states']
Expand All @@ -292,7 +312,7 @@ async def get_data_from_memcached(mc):
else:
weather_full_cached_data = {}

return alerts_cached_data, weather_cached_data, bins_cached_data, alerts_full_cached_data, weather_full_cached_data
return alerts_cached_data, weather_cached_data, bins_cached_data, test_bins_cached_data, alerts_full_cached_data, weather_full_cached_data


start_server = websockets.serve(echo, "0.0.0.0", websocket_port, ping_interval=ping_interval)
Expand Down
Loading

0 comments on commit 80a63f7

Please sign in to comment.