Skip to content

Commit

Permalink
Setup docker (#9)
Browse files Browse the repository at this point in the history
* Setup docker

Setup Docker image and hosted it on Docker Hub

* [Finishes #187584909] Completed to setup docker
  • Loading branch information
ndahimana154 authored May 17, 2024
1 parent 8dc854a commit bab5704
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 1 deletion.
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;

0 comments on commit bab5704

Please sign in to comment.