-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'milo/spa-provider' of https://github.com/railwayapp/nix…
…packs into milo/spa-provider
- Loading branch information
Showing
21 changed files
with
259 additions
and
65 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
title: Stacktape | ||
--- | ||
|
||
# {% $markdoc.frontmatter.title %} | ||
|
||
[Stacktape](https://stacktape.com?ref=nixpacks) allows you to use Nixpacks as a builder for web applications, workers, and other container workloads. You can configure the Nixpacks build with nixpacks config (`nixpacks.json` or `nixpacks.toml`) or directly in [Stacktape config](https://docs.stacktape.com/configuration/packaging/#nixpacks) or console. | ||
|
||
![](/images/stacktape.png) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import os | ||
import psycopg2 | ||
from psycopg2 import Error | ||
import time | ||
|
||
def get_db_connection(): | ||
max_retries = 3 | ||
retry_delay = 2 # seconds | ||
|
||
for attempt in range(max_retries): | ||
try: | ||
connection = psycopg2.connect( | ||
host=os.getenv('PGHOST'), | ||
database=os.getenv('PGDATABASE'), | ||
user=os.getenv('PGUSER'), | ||
password=os.getenv('PGPASSWORD'), | ||
port=os.getenv('PGPORT') | ||
) | ||
return connection | ||
except Error as e: | ||
if "starting up" in str(e).lower(): | ||
if attempt < max_retries - 1: # Don't sleep on last attempt | ||
time.sleep(retry_delay) | ||
continue | ||
print(f"Error connecting to PostgreSQL: {e}") | ||
return None | ||
|
||
def close_connection(connection): | ||
if connection: | ||
connection.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
from database import get_db_connection, close_connection | ||
|
||
def create_table(): | ||
connection = get_db_connection() | ||
if connection: | ||
try: | ||
cursor = connection.cursor() | ||
|
||
# Create a sample table | ||
create_table_query = ''' | ||
CREATE TABLE IF NOT EXISTS users ( | ||
id SERIAL PRIMARY KEY, | ||
name VARCHAR(100) NOT NULL, | ||
email VARCHAR(100) UNIQUE NOT NULL | ||
) | ||
''' | ||
cursor.execute(create_table_query) | ||
|
||
# Commit the changes | ||
connection.commit() | ||
print("Table created successfully") | ||
|
||
except Exception as e: | ||
print(f"Error: {e}") | ||
finally: | ||
cursor.close() | ||
close_connection(connection) | ||
|
||
def insert_user(name, email): | ||
connection = get_db_connection() | ||
if connection: | ||
try: | ||
cursor = connection.cursor() | ||
|
||
# Insert a new user | ||
insert_query = ''' | ||
INSERT INTO users (name, email) | ||
VALUES (%s, %s) | ||
RETURNING id | ||
''' | ||
cursor.execute(insert_query, (name, email)) | ||
user_id = cursor.fetchone()[0] | ||
|
||
# Commit the changes | ||
connection.commit() | ||
print(f"User inserted successfully with ID: {user_id}") | ||
|
||
except Exception as e: | ||
print(f"Error: {e}") | ||
finally: | ||
cursor.close() | ||
close_connection(connection) | ||
|
||
def get_all_users(): | ||
connection = get_db_connection() | ||
if connection: | ||
try: | ||
cursor = connection.cursor() | ||
|
||
# Select all users | ||
select_query = "SELECT * FROM users" | ||
cursor.execute(select_query) | ||
users = cursor.fetchall() | ||
|
||
for user in users: | ||
print(f"ID: {user[0]}, Name: {user[1]}, Email: {user[2]}") | ||
|
||
except Exception as e: | ||
print(f"Error: {e}") | ||
finally: | ||
cursor.close() | ||
close_connection(connection) | ||
|
||
if __name__ == "__main__": | ||
# Create the table | ||
create_table() | ||
|
||
# Insert some sample users | ||
insert_user("John Doe", "john@example.com") | ||
insert_user("Jane Smith", "jane@example.com") | ||
|
||
# Retrieve and display all users | ||
get_all_users() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
psycopg2-binary>=2.9.10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.