Skip to content

Instantly share code, notes, and snippets.

@mustafaturan
Last active September 2, 2024 19:34
Show Gist options
  • Save mustafaturan/289eb1b87844bb467ffa5ba0264d72e0 to your computer and use it in GitHub Desktop.
Save mustafaturan/289eb1b87844bb467ffa5ba0264d72e0 to your computer and use it in GitHub Desktop.
Set monoflake node id from ip address (digitalocean)
APP_ENV=production
MONOFLAKE_NODE=0
up:
MONOFLAKE_NODE=$(shell ip -4 addr show eth1 | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | head -n 1 | cut -d. -f4); \
echo "Monoflake node id: $$MONOFLAKE_NODE"; \
sed -i.bak "s/^MONOFLAKE_NODE=.*/MONOFLAKE_NODE=$$MONOFLAKE_NODE/" .env && \
echo "Updated MONOFLAKE_NODE to $$MONOFLAKE_NODE"; \
docker build . -t <app name>; \
docker compose down; \
docker compose --env-file=${PWD}/.env up -d; \
sleep 3; \
MONOFLAKE_NODE=0; \
sed -i.bak "s/^MONOFLAKE_NODE=.*/MONOFLAKE_NODE=$$MONOFLAKE_NODE/" .env && \
echo "Updated MONOFLAKE_NODE to $$MONOFLAKE_NODE";
down:
docker compose down
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment