Skip to content

Commit

Permalink
deploy latest
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtheman committed Sep 13, 2024
1 parent 8399acb commit fdf86dc
Show file tree
Hide file tree
Showing 18 changed files with 605 additions and 5,246 deletions.
89 changes: 89 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# flyctl launch added from .gitignore
# Dependency directories
**/node_modules
**/jspm_packages

# Optional npm cache directory
**/.npm

# database
**/*.db
**/*.sqlite
**/*.sqlite*

# Optional eslint cache
**/.eslintcache

# Optional REPL history
**/.node_repl_history

# Output of 'npm pack'
**/*.tgz

# Yarn Integrity file
**/.yarn-integrity

# dotenv environment variables file
**/.env
**/.env.test

# parcel-bundler cache (https://parceljs.org/)
**/.cache
**/.parcel-cache

# Next.js build output
**/.next
**/out

# Nuxt.js build / generate output
**/.nuxt
**/dist

# Gatsby files
**/.cache
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
**/.vuepress/dist

# Serverless directories
**/.serverless

# FuseBox cache
**/.fusebox

# DynamoDB Local files
**/.dynamodb

# TernJS port file
**/.tern-port

# Stores VSCode versions used for testing VSCode extensions
**/.vscode-test

# yarn v2
**/.yarn/cache
**/.yarn/unplugged
**/.yarn/build-state.yml
**/.yarn/install-state.gz
**/.pnp.*

# Logs
**/logs
**/*.log
**/npm-debug.log*
**/yarn-debug.log*
**/yarn-error.log*
**/lerna-debug.log*

# OS generated files
**/.DS_Store
**/.DS_Store?
**/._*
**/.Spotlight-V100
**/.Trashes
**/ehthumbs.db
**/Thumbs.db
fly.toml
18 changes: 18 additions & 0 deletions .github/workflows/fly-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/

name: Fly Deploy
on:
push:
branches:
- main
jobs:
deploy:
name: Deploy app
runs-on: ubuntu-latest
concurrency: deploy-group # optional: ensure only one action runs at a time
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
46 changes: 24 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
FROM node:20-bullseye
#!/bin/bash
set -e

RUN apt-get update && apt-get install -y sqlite3
# Set the migrations directory
MIGRATIONS_DIR="./db/migrations"

WORKDIR /app
# Create the data directory if it doesn't exist
mkdir -p /data

COPY package.json ./
RUN npm install
# rebuild sqlite3 for bullseye
RUN npm rebuild sqlite3
if [ ! -f /data/mydb.sqlite ]; then
echo "Database not found, creating and running migrations..."
touch /data/mydb.sqlite
chmod 644 /data/mydb.sqlite
dbmate --migrations-dir "$MIGRATIONS_DIR" up
echo "Database created and migrations applied."
else
echo "Database found, checking for unapplied migrations..."
if dbmate --migrations-dir "$MIGRATIONS_DIR" status | grep -q "Pending"; then
echo "Unapplied migrations found. Applying..."
dbmate --migrations-dir "$MIGRATIONS_DIR" up
echo "Migrations completed."
else
echo "No unapplied migrations found."
fi
fi

COPY ./src ./src
RUN mkdir -p ./db
COPY ./db/migrations ./db/migrations
COPY ./db/schema.sql ./db/

RUN mkdir -p /app/data && touch /app/data/mydb.sqlite
RUN chmod -R 777 /app/data
ENV DATABASE_URL=sqlite:./data/mydb.sqlite
RUN npm run db:migrate
# show tables
RUN sqlite3 /app/data/mydb.sqlite "select 1;"

EXPOSE 3000

CMD ["npm", "start"]
# Execute the command passed to the script
exec "$@"
Binary file added bun.lockb
Binary file not shown.
15 changes: 15 additions & 0 deletions db/migrations/20240913003421_todo_items.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- migrate:up
CREATE TABLE IF NOT EXISTS todo_items (
id INTEGER PRIMARY KEY AUTOINCREMENT,
list_id INTEGER NOT NULL,
title TEXT NOT NULL,
description TEXT,
is_completed BOOLEAN DEFAULT 0,
due_date DATE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- migrate:down
DROP TABLE IF EXISTS todo_items;


8 changes: 8 additions & 0 deletions db/migrations/20240913014845_add_user_ids.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- migrate:up
ALTER TABLE todo_items ADD COLUMN user_id TEXT;
CREATE INDEX idx_todo_items_user_id ON todo_items(user_id);


-- migrate:down
ALTER TABLE todo_items DROP COLUMN user_id;
DROP INDEX idx_todo_items_user_id;
9 changes: 6 additions & 3 deletions db/schema.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CREATE TABLE IF NOT EXISTS "schema_migrations" (version varchar(128) primary key);
CREATE TABLE todo_items (
id INTEGER PRIMARY KEY AUTOINCREMENT,
list_id INTEGER NOT NULL,
Expand All @@ -6,8 +7,10 @@ CREATE TABLE todo_items (
is_completed BOOLEAN DEFAULT 0,
due_date DATE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS "schema_migrations" (version varchar(128) primary key);
, user_id TEXT);
CREATE INDEX idx_todo_items_user_id ON todo_items(user_id);
-- Dbmate schema migrations
INSERT INTO "schema_migrations" (version) VALUES
('20240912204444');
('20240912204444'),
('20240913003421'),
('20240913014845');
27 changes: 27 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# fly.toml app configuration file generated for demo-htmx-nodejs on 2024-09-12T16:06:43-07:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'demo-htmx-nodejs'
primary_region = 'sjc'

[mounts]
source="data"
destination="/data"
initial_size="1gb"

[build]

[http_service]
internal_port = 3000
force_https = true
auto_stop_machines = 'stop'
auto_start_machines = true
min_machines_running = 0
processes = ['app']

[[vm]]
memory = '1gb'
cpu_kind = 'shared'
cpus = 1
Loading

0 comments on commit fdf86dc

Please sign in to comment.