README
All checks were successful
Publish Docker Image / Publish Docker Image (push) Successful in 1m1s

This commit is contained in:
Ahmed Al-Taiar
2024-10-08 21:21:06 -04:00
parent e2dfb6f237
commit 74db2e1034
4 changed files with 114 additions and 237 deletions

182
README.md
View File

@ -1,122 +1,72 @@
# README
# Portfolio Website
## Setup
### Domain Records
Create two A records, one for the web side of the website and one for the api side of the website. Ideally, the records should look something like `myportfolio.example.com` for the web side and `api.myportfolio.example.com`, but it is not important.
### Reverse Proxy
- It doesn't matter what reverse proxy you use (Nginx, Apache, Traefik, Caddy, etc)
1. Point the web domain to the web port (default: 8910)
2. Point the api domain to the api port (default: 8911)
### Gmail App Password
1. Go to your Google [account dashboard](https://myaccount.google.com)
2. Go to Security > 2-Step Verification > App Passwords > Create a new app password
3. Copy the 16 character password
### [Docker Compose](./docker-compose.yml)
```yaml
version: '3.8'
Welcome to [RedwoodJS](https://redwoodjs.com)!
services:
portfolio:
container_name: portfolio
image: git.altaiar.dev/ahmed/portfolio:latest
environment:
- NODE_ENV=production
- API_PROXY_TARGET=http://localhost:8911
- MAX_HTTP_CONNECTIONS_PER_MINUTE=60
- SESSION_SECRET=super_secret_session_key_change_me_in_production_please
- DATABASE_URL=postgresql://redwood:redwood@db:5432/portfolio
- FIRST_NAME=first name # Your first name
- LAST_NAME=lastname # Your last name
- GMAIL=example@gmail.com # The Gmail address associated with the app password created earlier
- GMAIL_SMTP_PASSWORD=aaaa bbbb cccc dddd # The app password created earlier
- DOMAIN=portfolio.example.com
- API_DOMAIN=api.portfolio.example.com
# Careful, addresses below must not end with a '/'
- ADDRESS_PROD=https://portfolio.example.com # https://DOMAIN
- API_ADDRESS_PROD=https://api.portfolio.example.com # https://API_DOMAIN
ports:
- '8910:8910' # Web
- '8911:8911' # API
depends_on:
- db
command: >
/bin/sh -c "
yarn rw build &&
yarn rw prisma migrate deploy &&
yarn rw prisma db seed &&
yarn rw serve"
> **Prerequisites**
>
> - Redwood requires [Node.js](https://nodejs.org/en/) (=20.x) and [Yarn](https://yarnpkg.com/)
> - Are you on Windows? For best results, follow our [Windows development setup](https://redwoodjs.com/docs/how-to/windows-development-setup) guide
Start by installing dependencies:
db:
container_name: portfolio-db
image: postgres:16-bookworm
environment:
POSTGRES_USER: redwood
POSTGRES_PASSWORD: redwood
POSTGRES_DB: portfolio
ports:
- '5432:5432'
volumes:
- postgres:/var/lib/postgresql/data
volumes:
postgres:
```
yarn install
```
## Logging In
- Once the container is up and running, head to `/login` (`https://portfolio.example.com/login`), default credentials are below
- If you would like to change the password, head to `/forgot-password` (`https://portfolio.example.com/forgot-password`), the username is `admin`
- If you correctly set up the Gmail app password, you should receive an email from yourself
- It contains the link needed to change your password
### Default Credentials
**Username:** `admin`
Then start the development server:
```
yarn redwood dev
```
Your browser should automatically open to [http://localhost:8910](http://localhost:8910) where you'll see the Welcome Page, which links out to many great resources.
> **The Redwood CLI**
>
> Congratulations on running your first Redwood CLI command! From dev to deploy, the CLI is with you the whole way. And there's quite a few commands at your disposal:
>
> ```
> yarn redwood --help
> ```
>
> For all the details, see the [CLI reference](https://redwoodjs.com/docs/cli-commands).
## Prisma and the database
Redwood wouldn't be a full-stack framework without a database. It all starts with the schema. Open the [`schema.prisma`](api/db/schema.prisma) file in `api/db` and replace the `UserExample` model with the following `Post` model:
```prisma
model Post {
id Int @id @default(autoincrement())
title String
body String
createdAt DateTime @default(now())
}
```
Redwood uses [Prisma](https://www.prisma.io/), a next-gen Node.js and TypeScript ORM, to talk to the database. Prisma's schema offers a declarative way of defining your app's data models. And Prisma [Migrate](https://www.prisma.io/migrate) uses that schema to make database migrations hassle-free:
```
yarn rw prisma migrate dev
# ...
? Enter a name for the new migration: create posts
```
> `rw` is short for `redwood`
You'll be prompted for the name of your migration. `create posts` will do.
Now let's generate everything we need to perform all the CRUD (Create, Retrieve, Update, Delete) actions on our `Post` model:
```
yarn redwood generate scaffold post
```
Navigate to [http://localhost:8910/posts/new](http://localhost:8910/posts/new), fill in the title and body, and click "Save".
Did we just create a post in the database? Yup! With `yarn rw generate scaffold <model>`, Redwood created all the pages, components, and services necessary to perform all CRUD actions on our posts table.
## Frontend first with Storybook
Don't know what your data models look like? That's more than ok—Redwood integrates Storybook so that you can work on design without worrying about data. Mockup, build, and verify your React components, even in complete isolation from the backend:
```
yarn rw storybook
```
Seeing "Couldn't find any stories"? That's because you need a `*.stories.{tsx,jsx}` file. The Redwood CLI makes getting one easy enough—try generating a [Cell](https://redwoodjs.com/docs/cells), Redwood's data-fetching abstraction:
```
yarn rw generate cell examplePosts
```
The Storybook server should hot reload and now you'll have four stories to work with. They'll probably look a little bland since there's no styling. See if the Redwood CLI's `setup ui` command has your favorite styling library:
```
yarn rw setup ui --help
```
## Testing with Jest
It'd be hard to scale from side project to startup without a few tests. Redwood fully integrates Jest with both the front- and back-ends, and makes it easy to keep your whole app covered by generating test files with all your components and services:
```
yarn rw test
```
To make the integration even more seamless, Redwood augments Jest with database [scenarios](https://redwoodjs.com/docs/testing#scenarios) and [GraphQL mocking](https://redwoodjs.com/docs/testing#mocking-graphql-calls).
## Ship it
Redwood is designed for both serverless deploy targets like Netlify and Vercel and serverful deploy targets like Render and AWS:
```
yarn rw setup deploy --help
```
Don't go live without auth! Lock down your app with Redwood's built-in, database-backed authentication system ([dbAuth](https://redwoodjs.com/docs/authentication#self-hosted-auth-installation-and-setup)), or integrate with nearly a dozen third-party auth providers:
```
yarn rw setup auth --help
```
## Next Steps
The best way to learn Redwood is by going through the comprehensive [tutorial](https://redwoodjs.com/docs/tutorial/foreword) and joining the community (via the [Discourse forum](https://community.redwoodjs.com) or the [Discord server](https://discord.gg/redwoodjs)).
## Quick Links
- Stay updated: read [Forum announcements](https://community.redwoodjs.com/c/announcements/5), follow us on [Twitter](https://twitter.com/redwoodjs), and subscribe to the [newsletter](https://redwoodjs.com/newsletter)
- [Learn how to contribute](https://redwoodjs.com/docs/contributing)
**Password:** [`GMAIL_SMTP_PASSWORD`](#gmail-app-password)

View File

@ -1,58 +0,0 @@
services:
redwood:
build:
context: .
dockerfile: ./Dockerfile
target: base
command: yarn rw dev
volumes:
- .:/home/node/app
- node_modules:/home/node/app/node_modules
ports:
- '8910:8910'
depends_on:
- db
environment:
- DATABASE_URL=postgresql://redwood:redwood@db:5432/redwood
- TEST_DATABASE_URL=postgresql://redwood:redwood@db:5432/redwood_test
- SESSION_SECRET=super_secret_session_key_change_me_in_production_please
- CI=
- NODE_ENV=development
- REDWOOD_API_HOST=0.0.0.0
db:
image: postgres:16-bookworm
environment:
POSTGRES_USER: redwood
POSTGRES_PASSWORD: redwood
POSTGRES_DB: redwood
ports:
- '5432:5432'
volumes:
- postgres:/var/lib/postgresql/data
# After starting with `docker compose -f ./docker-compose.dev.yml up`,
# use the console to run commands in the container:
#
# ```
# docker compose -f ./docker-compose.dev.yml run --rm -it console /bin/bash
# root@...:/home/node/app# yarn rw prisma migrate dev
# ```
console:
user: root
build:
context: .
dockerfile: ./Dockerfile
target: console
tmpfs:
- /tmp
command: 'true'
environment:
- DATABASE_URL=postgresql://redwood:redwood@db:5432/redwood
- TEST_DATABASE_URL=postgresql://redwood:redwood@db:5432/redwood_test
depends_on:
- db
volumes:
node_modules:
postgres:

View File

@ -1,63 +0,0 @@
services:
api:
build:
context: .
dockerfile: ./Dockerfile
target: api_serve
# Without a command specified, the Dockerfile's api_serve CMD will be used.
# If you are using a custom server file, you should either use the following
# command to launch your server or update the Dockerfile to do so.
# This is important if you intend to configure GraphQL to use Realtime.
# command: "./api/dist/server.js"
ports:
- '8911:8911'
depends_on:
- db
environment:
- DATABASE_URL=postgresql://redwood:redwood@db:5432/redwood
- TEST_DATABASE_URL=postgresql://redwood:redwood@db:5432/redwood_test
- SESSION_SECRET=super_secret_session_key_change_me_in_production_please
web:
build:
context: .
dockerfile: ./Dockerfile
target: web_serve
ports:
- '8910:8910'
depends_on:
- api
environment:
- API_PROXY_TARGET=http://api:8911
db:
image: postgres:16-bookworm
environment:
POSTGRES_USER: redwood
POSTGRES_PASSWORD: redwood
POSTGRES_DB: redwood
ports:
- '5432:5432'
volumes:
- ./postgres:/var/lib/postgresql/data
# After starting with `docker compose -f ./docker-compose.prod.yml up`,
# use the console to run commands in the container:
#
# ```
# docker compose -f ./docker-compose.prod.yml run --rm -it console /bin/bash
# ```
console:
user: root
build:
context: .
dockerfile: ./Dockerfile
target: console
tmpfs:
- /tmp
command: 'true'
environment:
- DATABASE_URL=postgresql://redwood:redwood@db:5432/redwood
- TEST_DATABASE_URL=postgresql://redwood:redwood@db:5432/redwood_test
depends_on:
- db

48
docker-compose.yml Normal file
View File

@ -0,0 +1,48 @@
version: '3.8'
services:
portfolio:
container_name: portfolio
image: git.altaiar.dev/ahmed/portfolio:latest
environment:
- NODE_ENV=production
- API_PROXY_TARGET=http://localhost:8911
- MAX_HTTP_CONNECTIONS_PER_MINUTE=60
- SESSION_SECRET=super_secret_session_key_change_me_in_production_please
- DATABASE_URL=postgresql://redwood:redwood@db:5432/portfolio
- FIRST_NAME=first name # Your first name
- LAST_NAME=lastname # Your last name
- GMAIL=example@gmail.com # The Gmail address associated with the app password created earlier
- GMAIL_SMTP_PASSWORD=aaaa bbbb cccc dddd # The app password created earlier
- DOMAIN=portfolio.example.com
- API_DOMAIN=api.portfolio.example.com
# Careful, addresses below must not end with a '/'
- ADDRESS_PROD=https://portfolio.example.com # https://DOMAIN
- API_ADDRESS_PROD=https://api.portfolio.example.com # https://API_DOMAIN
ports:
- '8910:8910' # Web
- '8911:8911' # API
depends_on:
- db
command: >
/bin/sh -c "
yarn rw build &&
yarn rw prisma migrate deploy &&
yarn rw prisma db seed &&
yarn rw serve"
db:
container_name: portfolio-db
image: postgres:16-bookworm
environment:
POSTGRES_USER: redwood
POSTGRES_PASSWORD: redwood
POSTGRES_DB: portfolio
ports:
- '5432:5432'
volumes:
- postgres:/var/lib/postgresql/data
volumes:
postgres: