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

Migrate database to localhost #92

Merged
merged 6 commits into from
Apr 16, 2023
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
3 changes: 1 addition & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ SERVER_NAME=yourdomainename.com # your domain name, for the nginx configuration

# mongodb setup
DB_NAME=XXX
DB_USER=XXX
DB_PASSWORD=XXX
DB_PORT=XXX

# cors
CLIENT_ORIGIN=http://localhost:$REACT_PORT # URL of the frontend, to make a cors exception
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ cp .env.example .env.development

After copying the example config of `.env`, you must fill in the missing information in this file. Check the example for more information.

> If you don't know how to deploy your database, consider using [Atlas](https://www.mongodb.com/atlas/database).

#### Backend

From the root directory of the repository, do the following:
Expand Down
7 changes: 3 additions & 4 deletions backend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const articleRoutes = require('./routes/articles')
const httpServer = createServer(app)
require('dotenv').config({ path: `../.env.${process.env.NODE_ENV}` })

const { DB_USER, DB_PASSWORD, DB_NAME, NODE_PORT, CLIENT_ORIGIN } = process.env
const { DB_PORT, DB_NAME, NODE_PORT, CLIENT_ORIGIN } = process.env

app.use(cors({ origin: CLIENT_ORIGIN || 'http://localhost:3000' }))
app.use(express.json({ limit: '1MB' }))
Expand All @@ -19,10 +19,9 @@ app.get('/', (req, res) => {
res.send('iscsc.fr is running')
})

uri = `mongodb://mongodb:${DB_PORT}/${DB_NAME}?retryWrites=true&w=majority`
mongoose
.connect(
`mongodb+srv://${DB_USER}:${DB_PASSWORD}@iscsc.a11re32.mongodb.net/${DB_NAME}?retryWrites=true&w=majority`
)
.connect(uri)
.then(() => {
httpServer.listen(NODE_PORT || 3001, () => {
console.log(`Server listening: http://localhost:${NODE_PORT}`)
Expand Down
25 changes: 25 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
version: "3.8"

services:
mongodb:
image: docker.io/bitnami/mongodb:4.4
networks:
- database
restart: always
env_file: ./.env.production
ports:
- $DB_PORT:$DB_PORT
volumes:
- "./mongodb:/data/db"

node-app:
depends_on:
- mongodb
networks:
- proxy
- database
build: ./backend
restart: unless-stopped
env_file: ./.env.production
Expand All @@ -11,6 +27,8 @@ services:
react-app:
depends_on:
- node-app
networks:
- proxy
env_file: ./.env.production
build:
context: ./frontend
Expand All @@ -19,9 +37,12 @@ services:

nginx:
restart: always
networks:
- proxy
depends_on:
- react-app
- node-app
- mongodb
build:
context: ./nginx
args:
Expand All @@ -40,3 +61,7 @@ services:
volumes:
- ./certbot/www/:/var/www/certbot/:rw
- ./certbot/conf/:/etc/letsencrypt/:rw

networks:
proxy:
database: