Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup docker #9

Merged
merged 2 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile.database
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM postgres:latest
13 changes: 13 additions & 0 deletions Dockerfile.server
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:20-alpine

WORKDIR /app

COPY ./package.json .

RUN npm install

COPY . .

EXPOSE 3000

CMD ["npm", "start"]
22 changes: 22 additions & 0 deletions README.Docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
### Building and running your application

When you're ready, start your application by running:
`docker compose up --build`.

Your application will be available at http://localhost:3000.

### Deploying your application to the cloud

First, build your image, e.g.: `docker build -t myapp .`.
If your cloud uses a different CPU architecture than your development
machine (e.g., you are on a Mac M1 and your cloud provider is amd64),
you'll want to build the image for that platform, e.g.:
`docker build --platform=linux/amd64 -t myapp .`.

Then, push it to your registry, e.g. `docker push myregistry.com/myapp`.

Consult Docker's [getting started](https://docs.docker.com/go/get-started-sharing/)
docs for more detail on building and pushing.

### References
* [Docker's Node.js guide](https://docs.docker.com/language/nodejs/)
28 changes: 28 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: "3"

services:
server:
build:
context: .
dockerfile: Dockerfile.server
ports:
- "3000:3000"
env_file:
- .env
depends_on:
- database

database:
build:
context: .
dockerfile: Dockerfile.database
ports:
- "5432:5432"
environment:
DATABASE_USER: ${DOCKER_DATABASE_USER}
DATABASE_NAME: ${DOCKER_DATABASE_NAME}
DATABASE_PASSWORD: ${DOCKER_DATABASE_PASSWORD}
POSTGRES_USER: ${DOCKER_DATABASE_USER}
POSTGRES_NAME: ${DOCKER_DATABASE_NAME}
POSTGRES_PASSWORD: ${DOCKER_DATABASE_PASSWORD}
POSTGRES_HOST_AUTH_METHOD: ${DOCKER_DATABASE_HOST_AUTH_METHOD}
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/databases/config/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ export const syncDatabase = async () => {
sequelize.sync({ force: true });
};

export default sequelize;
export default sequelize;
Loading