Skip to content

Commit

Permalink
feat: improve docker compose (EddieHubCommunity#2515)
Browse files Browse the repository at this point in the history
* chore: improve docker dev

* fix: docker compose file

* add ending line in Dockerfile
  • Loading branch information
Pradumnasaraf authored Dec 28, 2022
1 parent 769eef7 commit c06fcd5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .env.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
LINKFREE_MONGO_CONNECTION_STRING="mongodb://mongodb:27017/linkfree"
NEXT_PUBLIC_GA_MEASUREMENT_ID=""
NEXT_PUBLIC_BASE_URL="http://localhost:3000"
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ LABEL org.opencontainers.image.source https://github.com/eddiehubcommunity/LinkF
WORKDIR /usr/src/app

COPY package*.json ./
RUN npm install --omit=dev --ignore-scripts
ARG NODE_ENV
RUN if [ "$NODE_ENV" = "development" ]; then npm install --ignore-scripts; else npm install --omit=dev --ignore-scripts; fi
COPY . .

RUN sed -i 's/0.0.0/'`npm pkg get version | tr -d '"'`'/g' config/app.json
Expand Down
2 changes: 1 addition & 1 deletion config/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const connectMongo = async () => {
fs.writeFileSync("cert.pem", process.env.CA_CERT);
}

mongoose.connect(process.env.LINKFREE_MONGO_CONNECTION_STRING);
await mongoose.connect(process.env.LINKFREE_MONGO_CONNECTION_STRING);
hasConnection = true;
console.log("DB connected");
} catch (err) {
Expand Down
31 changes: 28 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
version: "3.9"

services:
mongodb:
image: mongo
linkfree:
container_name: linkfree
build:
context: .
dockerfile: Dockerfile
args:
- NODE_ENV=development
image: linkfree-app
ports:
- "27017:27017"
- "3000:3000"
depends_on:
- mongodb
command: npm run dev:docker
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
networks:
- linkfree-network

mongodb:
image: mongo:5.0
container_name: mongodb
networks:
- linkfree-network

networks:
linkfree-network:
driver: bridge
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
},
"scripts": {
"dev": "next dev",
"dev:docker": "ncp ./.env.docker ./.env && next dev",
"dev-wsl": "HOST=$(hostname -I | awk '{print $1}') && next dev --hostname ${HOST}",
"build": "next build",
"test": "npx playwright test --trace on",
Expand Down

0 comments on commit c06fcd5

Please sign in to comment.