Skip to content

Commit 65b947b

Browse files
samrosesoedirgo
authored andcommitted
fix: gh actions oom try without overmind
1 parent 36ed328 commit 65b947b

File tree

1 file changed

+27
-62
lines changed

1 file changed

+27
-62
lines changed

nix/tools/dbmate-tool.sh.in

Lines changed: 27 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -15,52 +15,41 @@ CURRENT_SYSTEM="@CURRENT_SYSTEM@"
1515
ANSIBLE_VARS="@ANSIBLE_VARS@"
1616
PGBOUNCER_AUTH_SCHEMA_SQL=@PGBOUNCER_AUTH_SCHEMA_SQL@
1717
STAT_EXTENSION_SQL=@STAT_EXTENSION_SQL@
18+
19+
# Start PostgreSQL using nix
20+
start_postgres() {
21+
echo "Starting PostgreSQL..."
22+
nix run "$FLAKE_URL#start-server" -- "$PSQL_VERSION" --skip-migrations --daemonize &
23+
echo "PostgreSQL started."
24+
}
25+
1826
# Cleanup function
1927
cleanup() {
2028
echo "Cleaning up..."
2129

22-
# First, gracefully stop Overmind if it's running
23-
if [ -S "./.overmind.sock" ]; then
24-
echo "Stopping Overmind gracefully..."
25-
overmind quit || true
26-
sleep 5 # Give Overmind time to shut down
27-
fi
28-
2930
# Stop PostgreSQL processes gracefully
3031
if pgrep -f "postgres" >/dev/null; then
3132
echo "Stopping PostgreSQL gracefully..."
32-
pkill -TERM postgres || true
33+
pkill -f "postgres" || true # Adjust this if you have a specific way to stop the service
3334
sleep 5 # Wait for PostgreSQL to shut down
3435
fi
3536

36-
# Clean up any remaining tmux sessions
37-
if tmux ls 2>/dev/null | grep 'overmind'; then
38-
echo "Cleaning up tmux sessions..."
39-
tmux ls 2>/dev/null | grep 'overmind' | cut -d: -f1 | xargs -I{} tmux kill-session -t {} || true
40-
sleep 2
41-
fi
42-
43-
# Final cleanup: Force kill if necessary (as a last resort)
44-
if ps aux | grep -E "(postgres|overmind|tmux.*postgresql)" | grep -v grep >/dev/null; then
45-
echo "Force killing remaining processes..."
46-
pkill -9 -f "(postgres|overmind|tmux.*postgresql)" || true
47-
sleep 2
48-
fi
49-
50-
# Remove socket and Procfile
51-
rm -f .overmind.sock Procfile
52-
5337
# Verify cleanup
54-
if ps aux | grep -E "(postgres|overmind|tmux.*postgresql)" | grep -v grep >/dev/null; then
55-
echo "Warning: Some processes could not be cleaned up:"
56-
ps aux | grep -E "(postgres|overmind|tmux.*postgresql)" | grep -v grep
38+
if pgrep -f "postgres" >/dev/null; then
39+
echo "Warning: Some PostgreSQL processes could not be cleaned up:"
40+
pgrep -f "postgres"
5741
return 1
5842
else
5943
echo "Cleanup completed successfully"
6044
fi
6145
}
46+
6247
# Set up trap for cleanup on script exit
6348
trap cleanup EXIT INT TERM
49+
50+
# Start PostgreSQL
51+
start_postgres
52+
6453
# Function to display help
6554
print_help() {
6655
echo "Usage: nix run .#dbmate-tool -- [options]"
@@ -81,7 +70,6 @@ print_help() {
8170
echo " nix run .#dbmate-tool -- --version 16 --port 5433 --flake-url github:supabase/postgres/<commithash>"
8271
}
8372

84-
8573
# Parse arguments
8674
while [[ "$#" -gt 0 ]]; do
8775
case "$1" in
@@ -138,7 +126,7 @@ wait_for_postgres() {
138126
local max_attempts=30 # Increased significantly
139127
local attempt=1
140128

141-
# Give overmind a moment to actually start the process
129+
# Give PostgreSQL a moment to actually start the process
142130
sleep 2
143131

144132
while [ $attempt -le $max_attempts ]; do
@@ -155,7 +143,6 @@ wait_for_postgres() {
155143
done
156144

157145
echo "PostgreSQL failed to start after $max_attempts attempts"
158-
overmind echo postgres
159146
return 1
160147
}
161148

@@ -188,26 +175,7 @@ trim_schema() {
188175
;;
189176
esac
190177
}
191-
overmind_start() {
192-
cat > Procfile << EOF
193-
postgres_${PSQL_VERSION}: exec nix run "$FLAKE_URL#start-server" -- "$PSQL_VERSION" --skip-migrations
194-
EOF
195-
overmind start -D
196-
echo "Waiting for overmind socket..."
197-
max_wait=5
198-
count=0
199-
while [ $count -lt $max_wait ]; do
200-
if [ -S "./.overmind.sock" ]; then
201-
# Found the socket, give it a moment to be ready
202-
sleep 5
203-
echo "Socket file found and ready"
204-
break
205-
fi
206-
echo "Waiting for socket file (attempt $count/$max_wait)"
207-
sleep 1
208-
count=$((count + 1))
209-
done
210-
}
178+
211179
perform_dump() {
212180
local max_attempts=3
213181
local attempt=1
@@ -227,21 +195,18 @@ perform_dump() {
227195
echo "All dump attempts failed"
228196
return 1
229197
}
198+
230199
migrate_version() {
231200
echo "PSQL_VERSION: $PSQL_VERSION"
232-
overmind kill || true
233-
rm -f .overmind.sock Procfile || true
201+
pkill -f "postgres" || true # Ensure PostgreSQL is stopped before starting
234202
PSQLBIN=$(nix build --no-link "$FLAKE_URL#psql_$PSQL_VERSION/bin" --json | jq -r '.[].outputs.out + "/bin"')
235203
echo "Using PostgreSQL version $PSQL_VERSION from $PSQLBIN"
236204

237-
# Start overmind
238-
overmind_start
239-
echo "Waiting for overmind socket..."
240-
241-
205+
# Start PostgreSQL
206+
start_postgres
242207
echo "Waiting for PostgreSQL to be ready..."
243208

244-
#Wait for PostgreSQL to be ready to accept connections
209+
# Wait for PostgreSQL to be ready to accept connections
245210
if ! wait_for_postgres; then
246211
echo "Failed to connect to PostgreSQL server"
247212
exit 1
@@ -268,11 +233,11 @@ EOSQL
268233
"${PSQLBIN}/psql" -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -p "$PORTNO" -h localhost -d postgres -f "$PGBOUNCER_AUTH_SCHEMA_SQL"
269234
"${PSQLBIN}/psql" -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -p "$PORTNO" -h localhost -d postgres -f "$STAT_EXTENSION_SQL"
270235

271-
#set db url to run dbmate
236+
# Set db url to run dbmate
272237
export DATABASE_URL="postgres://$PGSQL_USER:$PGPASSWORD@localhost:$PORTNO/postgres?sslmode=disable"
273-
#export path so dbmate can find correct psql and pg_dump
238+
# Export path so dbmate can find correct psql and pg_dump
274239
export PATH="$PSQLBIN:$PATH"
275-
# run init scripts
240+
# Run init scripts
276241
if ! dbmate --migrations-dir "$MIGRATIONS_DIR/init-scripts" up; then
277242
echo "Error: Initial migration failed"
278243
exit 1

0 commit comments

Comments
 (0)