Skip to content

Commit 9160ee2

Browse files
authored
feat: new development workflow setup (#42)
1 parent aa97ece commit 9160ee2

File tree

10 files changed

+809
-587
lines changed

10 files changed

+809
-587
lines changed

.env.development

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# DATABASE
2-
DATABASE_URL=postgresql://postgres:postgres@db:5432/postgres
2+
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# DATABASE
2+
# if localhost:
3+
# DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres
4+
# if docker:
5+
# DATABASE_URL=postgresql://postgres:postgres@db:5432/postgres
26
DATABASE_URL=
37

48
# SECRET

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ yarn-debug.log*
2626
yarn-error.log*
2727

2828
# local env files
29+
.env
2930
.env*.local
3031

3132
# vercel

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"files.associations": {
3+
"Dockerfile*": "dockerfile",
4+
".env*": "shellscript"
5+
},
6+
"editor.tabSize": 4
7+
}

.zed/settings.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Folder-specific settings
2+
//
3+
// For a full list of overridable settings, and general information on folder-specific settings,
4+
// see the documentation: https://zed.dev/docs/configuring-zed#settings-files
5+
{
6+
"file_types": {
7+
"Dockerfile": ["Dockerfile*"],
8+
"Shell Script": [".env*"]
9+
},
10+
"tab_size": 2
11+
}

README.md

Lines changed: 56 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,78 @@
1-
```ts
2-
// WHOAMI
3-
export const metadata: Metadata = {
4-
title: 'Moonlitgrace',
5-
description:
6-
'Step into Moonlitgrace, where a passionate web developer and
7-
open-source contributor shares insights, projects, and
8-
creativity—all under the alias Moonlitgrace.',
9-
};
10-
```
1+
# moonlitgrace.space
112

12-
## Development
3+
Step into Moonlitgrace, where a passionate web developer and open-source contributor shares insights, projects, and creativity—all under the alias Moonlitgrace.
134

14-
This is a containerized next.js app, so I recommend you to run it with docker or podman.
5+
### Table of Contents
156

16-
> [!IMPORTANT]
17-
> You can use [docker](https://www.docker.com/) or [podman](https://podman.io/)\
18-
> Here I will show you with podman.
7+
- [Development](#development)
8+
- [Basic Steps](#basic-steps)
9+
- [Configure environment variables](#configure-environment-variables)
10+
- [Run app on local](#run-app-on-local-traditional-workflow)
11+
- [Run app on container](#run-app-on-container)
1912

13+
## Development
2014
### Basic Steps
2115

22-
- `git clone https://github.com/moonlitgrace/space moonlitspace`
23-
- `cd moonlitspace`
16+
- `git clone https://github.com/moonlitgrace/moonlitgrace.space moonlitgrace.space`
17+
- `cd moonlitgrace.space`
2418
- `npm i`
2519

2620
### Configure environment variables
2721

2822
From repo you will get 3 `.env` files such as:
2923

30-
- `.env.development`
3124
- `.env.example`
25+
- `.env.development`
3226
- `.env.local.example`
3327

34-
For development you only have to change `.env.local.example` like:
28+
Check [Environment Variable Load Order](https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#environment-variable-load-order) for more information regarding this structure.
3529

36-
- First create `.env.local` with:
37-
`cp .env.local.example .env.local`
38-
39-
For `SECRET_KEY` you can use anything since it is for development. You can use this `openssl rand -base64 32` to create for production.
30+
For `SECRET_KEY` you can use anything since it is for development. (You can use this `openssl rand -base64 32` to create for production.)
4031

4132
As for `ADMIN_USERNAME` and `ADMIN_PASSWORD` add something to authenticate only you.
4233

43-
### Run containers
34+
`DATABASE_URL`: uncomment value according to your selected workflow (see next heading).
35+
36+
## Run app on local (traditional workflow)
37+
38+
Before running `app`, we need a postgres `db` running.\
39+
You can either run `db` on your system or use docker/podman.
4440

45-
After setting required env variables, let's start containers with one command:\
46-
`podman-compose -f docker-compose.dev.yml up -d --build`
41+
eg postgresql connection string format: `postgresql://[db_user[:db_password]@][db_host][:db_port]/[db_name]`
42+
43+
If you've docker/podman installed, you can run `db` on a container with command:
44+
```bash
45+
# docker compose -f docker-compose.db.yml up
46+
podman compose -f docker-compose.db.yml up
47+
```
48+
49+
Now `db` is up!\
50+
Next run database migrations with commands:
51+
```bash
52+
# can use any package manager
53+
npm run db:generate
54+
npm run db:migrate
55+
```
56+
57+
If you want some mock data for development: run: `npm run db:seed`
58+
59+
To get `next.js` app running, run this command:
60+
```bash
61+
npm run dev
62+
```
63+
64+
And that's for now! check [localhost:3000](https://localhost:3000) to see app running!
65+
66+
## Run app on container
67+
68+
(un)fortunately this app is containerized, so you can easily run it with docker/podman/any(idk).\
69+
Just run this command:
70+
```bash
71+
# docker compose -f docker-compose.dev.yml up --build
72+
podman compose -f docker-compose.dev.yml up --build
73+
```
4774

48-
And that's it, docker will setup everything for you, and once its done, visit: `http://localhost:3000`\
75+
This will run app on [localhost:3000](https://localhost:3000), hurray?
4976

50-
Consider [issue tracker](https://github.com/moonlitgrace/space/issues) if you see any problem setting it up, happy coding!
77+
> Next.js on container is not fun imho.\
78+
> recommended: local setup

db/seed/seed.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dotenv/config';
12
import { db } from '@/db';
23
import { posts } from '@/db/schema';
34
import { postsMockData } from './mock/posts';
@@ -18,4 +19,4 @@ async function main() {
1819
}
1920
}
2021

21-
main();
22+
// main();

docker-compose.db.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: '3'
2+
3+
services:
4+
db:
5+
image: postgres:16.4-alpine
6+
restart: always
7+
environment:
8+
POSTGRES_USER: postgres
9+
POSTGRES_PASSWORD: postgres
10+
POSTGRES_DB: postgres
11+
ports:
12+
- 5432:5432
13+
volumes:
14+
- pgdata:/var/lib/postgresql/data
15+
16+
volumes:
17+
pgdata: {}

0 commit comments

Comments
 (0)