Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Commit

Permalink
feat: docker and compose support (#55)
Browse files Browse the repository at this point in the history
* chore: Add Docker configuration files and compose.yaml for local development

* feat: add start command to Dockerfile

* chore: Update Docker configuration and compose.yaml for local development

* Update Docker configuration and compose.yaml for local development

* chore: Add container_name to server service in compose.yaml

* chore: Update Dockerfile image source URL

* chore: Update Docker configuration and compose.yaml for local development

* chore: Update Docker configuration and compose.yaml for local development

* chore: Update Docker configuration and compose.yaml for local development

* Update Docker configuration and compose.yaml for local development

* chore: Update Docker configuration and compose.yaml for local development

* chore: Update Docker configuration and compose.yaml for local development

* chore: add a blank line in the end
  • Loading branch information
Pradumnasaraf authored Jun 20, 2024
1 parent da1f71b commit 6ec6312
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 25 deletions.
33 changes: 33 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Include any files or directories that you don't want to be copied to your
# container here (e.g., local build artifacts, temporary files, etc.).
#
# For more help, visit the .dockerignore file reference guide at
# https://docs.docker.com/go/build-context-dockerignore/

**/.classpath
**/.dockerignore
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/.next
**/.cache
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/charts
**/docker-compose*
**/compose.y*ml
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
**/build
**/dist
LICENSE
README.md
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ARG NODE_VERSION=20

FROM node:${NODE_VERSION}
LABEL org.opencontainers.image.source https://github.com/eddiehubcommunity/CreatorsRegistry

WORKDIR /usr/src/app

COPY . .

RUN npm ci

EXPOSE 3000

CMD npm run db:prod:migrate && npm run build && npm run start
39 changes: 25 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ All contributions welcome, not just code.
- Postgres
- LinkedIn OAuth

### Requirements
### Local development

- NodeJS
- Postgres
- LinkedIn OAuth
This environment is fully on your computer and requires each dependency to be installed and set up, but it gives you the most flexibility for customisation.

### Local development
#### Prerequisites

NodeJS, Postgres and LinkedIn OAuth

1. Copy `.env.example` to `.env` and fill out the parameters.
- For LinkedIn parameters, create a developer app [here](https://developer.linkedin.com).

#### Environment Variables

| ENVIRONMENT VARIABLE | EXAMPLE VALUE | DESCRIPTION |
| :--------------------- | :--------------------------------------------------------------------- | :------------------------------------------ |
Expand All @@ -40,17 +42,26 @@ All contributions welcome, not just code.
<img alt="LinkedIn OAuth screenshot of settings" src="https://github.com/EddieHubCommunity/CreatorsRegistry/assets/624760/c61a50eb-363e-4dcb-b208-405e256f7238">
</details>

2. Install the dependencies using `npm ci` from the package lock file (do not use `npm install` unless for a specific reason).
3. Ensure your Postgres server is running on `localhost:5432` with the default username and `POSTGRES_PASSWORD` set as `password`.
4. Create the database tables by running `npm run db:dev:migrate` (for production, use `npm run db:prod:migrate`).
5. Seed the database by inserting example data with `npm run db:dev:seed` (if you need to reset the database, use `npm run db:dev:reset`).
6. Start the local development server with `npm run dev`.
1. Install the dependencies using `npm ci` from the package lock file (do not use `npm install` unless for a specific reason).
2. Ensure your Postgres server is running on `localhost:5432` with the default username and `POSTGRES_PASSWORD` set as `password`. To start a Postgres server using Docker and Compose, use `docker compose -f postgres.compose.yaml up`.
3. Create the database tables by running `npm run db:dev:migrate` (for production, use `npm run db:prod:migrate`).
4. Seed the database by inserting example data with `npm run db:dev:seed` (if you need to reset the database, use `npm run db:dev:reset`).
5. Start the local development server with `npm run dev`.

### Local Development with Docker Compose

### Postgres using Docker Compose
This will allow you to use your favorite IDE without having to install any dependencies on your computer.

Note: you must have docker installed
#### Prerequisites

Run the docker command `docker compose up -d`
Docker and Docker Compose

1. Clone the repository and navigate to the root of the directory.
2. Copy `.env.example` to `.env` and fill out the parameters. Please refer to the [Environment Variables](#environment-variables) section.
- For LinkedIn parameters, create a developer app [here](https://developer.linkedin.com).
- There is no need to change the Postgres URL as it's already set in the [compose.yaml](compose.yaml) file.
3. Run `docker compose up`.
4. In your browser, go to `localhost:3000`, and you should see the project up and running.

## Join the EddieHub community
Discord http://discord.eddiehub.org
Discord http://discord.eddiehub.org
46 changes: 35 additions & 11 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,40 @@
version: '3.9'

services:

server:
build:
context: .
env_file:
- .env
environment: # To override the DB URL in the .env file
- DATABASE_URL=postgres://postgres:password@db:5432/contentcreator?schema=public
depends_on:
- db
ports:
- 3000:3000
networks:
- creators-registry
container_name: server
db:
image: postgres
container_name: creator_registry_db
image: postgres:16
container_name: db
networks:
- creators-registry
restart: always
shm_size: 128mb
user: postgres
volumes:
- db-data:/var/lib/postgresql/data
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: password
POSTGRES_DB: contentcreator
ports:
- "5432:5432"
- POSTGRES_PASSWORD=password
expose:
- 5432
healthcheck:
test: [ "CMD", "pg_isready" ]
interval: 10s
timeout: 5s
retries: 5

networks:
creators-registry:
driver: bridge

volumes:
db-data:
22 changes: 22 additions & 0 deletions postgres.compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
services:
db:
image: postgres:16
container_name: creator_registry_db
restart: always
user: postgres
volumes:
- db-data:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=password
expose:
- 5432
ports:
- "5432:5432"
healthcheck:
test: [ "CMD", "pg_isready" ]
interval: 10s
timeout: 5s
retries: 5

volumes:
db-data:

0 comments on commit 6ec6312

Please sign in to comment.