Skip to content

Commit

Permalink
chore: clean up repo files
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards1230 committed Apr 20, 2024
1 parent f7f6406 commit a13388c
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 134 deletions.
5 changes: 1 addition & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/**/db/
/server/node_modules/
/client/node_modules/
/**/ios/
/client/ios/
/**/tests/
docker-service/*

/server/logs/
.gitignore
pg.sh
7 changes: 0 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
docker.sh

/docker-service/pg/
docker-service/mindsdb/
docker-service/ts/state

secrets/


.env
39 changes: 26 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,47 @@ ChatGPT clone. Definitely a WIP. This project was mostly to learn React Native a
### Server

- Fastify
- Serve static React files
- Serve client as a SPA React app
- Schema validation with `zod`
- Auto-generated OpenAPI docs with `@eropple/fastify-openapi3`
- Auto-generated OpenAPI docs served at `/docs`
- TypeORM & Postgres
- OpenAI API

### Client

- React Native and Expo
- State management with `zustand`
- Server state management with `@tanstack/react-query`
- Theming with `nativewind`
- Theming with `nativewind` and `tailwindcss`
- Reusable UI components with `@radix-ui`

### Deployment

- The Dockerfile compiles the main backend and the web client assets.
- Compiles `/server` for the main backend
- Compiles `/client` for the web client
- `/client/export.ts` is run to compile the static files into `/client/dist/`
- This is a hack since the expo cli `export` command does not end its process on successful export. It expects you to ctrl+c. This script reads the output and gracefully exits if it works out.
- This seems unreliable on Github Actions
There are two Compose files. They pull from `jewards1230/mychat` on Docker Hub. There is a Github Action that builds and pushes the image on every push to the `main` branch.

These can be modified for local build contexts, but I generally only use docker for the local Postgres DB.

#### Compose.yml

- Docker Compose will serve:
- Fastify server with static web client on port 3000
- Postgres DB
- Github Action (DISABLED):
- Connects to Tailscale network, builds docker image, deploys to private registry.
- Currently disabled because it does not reliably export the web client.
- This is mostly used for local development and testing

#### Production.yml

- Docker Compose will serve the same as above, plus:
- Tailscale Proxy that serves the Fastify server to the web with SSL
- This is nice because it gives the app its own machine on the Tailscale network.
- This exposes the Fastify server on port 443
- This requires copying the funnel.json file to the appropriate directory when configuring Docker Compose variables
- This can be reconfigured to use the Tailscale Serve service as well.

#### Development

- The Dockerfile compiles the main backend and serves a Postgres DB.
- Note: Generally best to just run the PG DB alone and run fastify form the CLI
- TODO: Add dev mode so docker watches for changes and restarts the server.
- Run `bun run export` from the `./client` directory to export the web client to the `./client/dist` directory. The Dockerfile has an ENV variable to point to this directory.

## Features

Expand Down
78 changes: 39 additions & 39 deletions client/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,48 @@ const OWNER = process.env.OWNER;
const PROJECT_ID = process.env.PROJECT_ID;

const IS_PROD =
process.env.APP_VARIANT === "production" || process.env.APP_VARIANT === "preview";
process.env.APP_VARIANT === "production" || process.env.APP_VARIANT === "preview";

const PACKAGE_NAME = IS_PROD ? "myChat" : "myChat-dev";
const PACKAGE_BUNDLE = IS_PROD ? "com.project.myChat" : "com.project.myChat.dev";

export default ({ config }: ConfigContext): ExpoConfig => ({
...config,
slug: "mychat",
version: "1.0.0",
name: PACKAGE_NAME,
scheme: PACKAGE_NAME,
orientation: "portrait",
userInterfaceStyle: "automatic",
assetBundlePatterns: ["assets/**/*"],
icon: "./assets/images/icon.png",
splash: {
image: "./assets/images/splash.png",
resizeMode: "contain",
backgroundColor: "#ffffff",
},
ios: {
supportsTablet: true,
bundleIdentifier: PACKAGE_BUNDLE,
},
android: {
package: PACKAGE_BUNDLE,
adaptiveIcon: {
foregroundImage: "./assets/images/adaptive-icon.png",
backgroundColor: "#ffffff",
},
},
web: {
bundler: "metro",
output: "single",
favicon: "./assets/images/favicon.png",
},
plugins: [
["expo-router", { asyncRoutes: false }],
["expo-document-picker", { iCloudContainerEnvironment: "Production" }],
["expo-updates", { username: "account-username" }],
],
experiments: { typedRoutes: true },
owner: OWNER,
extra: { eas: { projectId: PROJECT_ID } },
...config,
slug: PACKAGE_NAME,
version: "1.0.0",
name: PACKAGE_NAME,
scheme: PACKAGE_NAME,
orientation: "portrait",
userInterfaceStyle: "automatic",
assetBundlePatterns: ["assets/**/*"],
icon: "./assets/images/icon.png",
splash: {
image: "./assets/images/splash.png",
resizeMode: "contain",
backgroundColor: "#ffffff",
},
ios: {
supportsTablet: true,
bundleIdentifier: PACKAGE_BUNDLE,
},
android: {
package: PACKAGE_BUNDLE,
adaptiveIcon: {
foregroundImage: "./assets/images/adaptive-icon.png",
backgroundColor: "#ffffff",
},
},
web: {
bundler: "metro",
output: "single",
favicon: "./assets/images/favicon.png",
},
plugins: [
["expo-router", { asyncRoutes: false }],
["expo-document-picker", { iCloudContainerEnvironment: "Production" }],
["expo-updates", { username: "account-username" }],
],
experiments: { typedRoutes: true },
owner: OWNER,
extra: { eas: { projectId: PROJECT_ID } },
});
Binary file modified client/bun.lockb
Binary file not shown.
62 changes: 25 additions & 37 deletions client/eas.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,27 @@
{
"cli": {
"version": ">= 7.3.0",
"promptToConfigurePushNotifications": false
},
"build": {
"development": {
"extends": "preview",
"developmentClient": true,
"channel": "development",
"env": {
"APP_VARIANT": "development"
}
},
"preview": {
"extends": "production",
"channel": "preview",
"distribution": "internal",
"env": {
"APP_ENV": "preview"
}
},
"production": {
"android": {
"image": "latest"
},
"ios": {
"image": "latest"
},
"channel": "production",
"env": {
"APP_ENV": "production"
}
}
},
"submit": {
"production": {}
}
"cli": {
"version": ">= 7.3.0",
"promptToConfigurePushNotifications": false
},
"build": {
"development": {
"extends": "preview",
"developmentClient": true,
"channel": "development",
"env": { "APP_VARIANT": "development" }
},
"preview": {
"extends": "production",
"channel": "preview",
"distribution": "internal",
"env": { "APP_ENV": "preview" }
},
"production": {
"android": { "image": "latest" },
"ios": { "image": "latest" },
"channel": "production",
"env": { "APP_ENV": "production" }
}
},
"submit": { "production": {} }
}
7 changes: 3 additions & 4 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"export": "expo export -p web",
"build": "expo run:ios --no-build-cache",
"build:dev": "APP_VARIANT=development expo run:ios --device --no-build-cache",
"build:prev": "APP_VARIANT=preview expo run:ios --device",
"build:prev": "APP_VARIANT=preview expo run:ios --device --no-build-cache",
"build:sign": "APP_VARIANT=preview eas build -e preview -p ios",
"analyze:web": "source-map-explorer 'dist/_expo/static/js/web/*.js' 'dist/_expo/static/js/web/*.js.map'",
"analyze:ios": "source-map-explorer 'dist/_expo/static/js/ios/*.js' 'dist/_expo/static/js/ios/*.js.map'",
Expand Down Expand Up @@ -53,12 +53,11 @@
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"cmdk": "^1.0.0",
"expo": "next",
"expo-asset": "next",
"expo": "^50.0.17",
"expo-clipboard": "~5.0.1",
"expo-dev-client": "~3.3.11",
"expo-document-picker": "^11.10.1",
"expo-font": "next",
"expo-font": "^11.10.3",
"expo-haptics": "~12.8.1",
"expo-image": "~1.10.6",
"expo-linking": "~6.2.2",
Expand Down
5 changes: 4 additions & 1 deletion compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
ports:
- 5432:5432
volumes:
- ./docker-service/pg/:/var/lib/postgresql/data
- pg:/var/lib/postgresql/data
env_file:
- .env

Expand All @@ -32,3 +32,6 @@ services:
- .env
environment:
- DB_HOST=postgres

volumes:
pg:
19 changes: 0 additions & 19 deletions docker-service/ts/config/funnel.json

This file was deleted.

9 changes: 9 additions & 0 deletions funnel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"TCP": { "443": { "HTTPS": true } },
"Web": {
"${TS_CERT_DOMAIN}:443": {
"Handlers": { "/": { "Proxy": "http://127.0.0.1:3000" } }
}
},
"AllowFunnel": { "${TS_CERT_DOMAIN}:443": true }
}
10 changes: 7 additions & 3 deletions production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
depends_on:
- tailscale
volumes:
- ${PWD}/docker-service/pg/:/var/lib/postgresql/data
- pg:/var/lib/postgresql/data
env_file:
- .env
network_mode: service:tailscale
Expand Down Expand Up @@ -50,9 +50,13 @@ services:
env_file:
- .env
volumes:
- ${PWD}/docker-service/ts/state:/var/lib/tailscale
- ${PWD}/docker-service/ts/config:/config
- ts:/var/lib/tailscale
- ${PWD}/ts-config:/config
#- /dev/net/tun:/dev/net/tun
cap_add:
- net_admin
- sys_module

volumes:
pg:
ts:
7 changes: 0 additions & 7 deletions server/pg.sh

This file was deleted.

0 comments on commit a13388c

Please sign in to comment.