Skip to content

Commit

Permalink
setting up docker worked
Browse files Browse the repository at this point in the history
  • Loading branch information
devout-coder committed Nov 13, 2023
1 parent fce4974 commit 55e3bc2
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 4,645 deletions.
24 changes: 24 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/charts
**/docker-compose*
**/compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
node_modules
.env
.env
data/
.vscode/
yarn-error.log
yarn.lock
package-lock.json
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM node:lts-alpine
ENV NODE_ENV=production
WORKDIR /usr/src/app
COPY ["package.json", "package-lock.json*", "npm-shrinkwrap.json*", "./"]
RUN npm install --production --silent && mv node_modules ../
COPY . .
EXPOSE 3000
RUN chown -R node /usr/src/app
USER node
CMD ["npm", "start"]
47 changes: 47 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
version: '3'

services:
doneify:
build:
context: .
dockerfile: Dockerfile
container_name: doneify_cunt
volumes:
- ./app:/app
ports:
- 3000:3000
environment:
- PORT=${PORT}
- JWT_SECRET=${JWT_SECRET}
- MONGO_ROOT_USER=${MONGO_ROOT_USER}
- MONGO_ROOT_PASSWORD=${MONGO_ROOT_PASSWORD}
- SERVER_URL=${SERVER_URL}
depends_on:
- mongo

mongo:
image: mongo
container_name: mongo_db
environment:
- MONGO_INITDB_ROOT_USERNAME=${MONGO_ROOT_USER}
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_ROOT_PASSWORD}
- MONGO_INITDB_DATABASE=project
ports:
- 27017:27017

mongo-express:
image: mongo-express
container_name: mongo_web_gui
environment:
- ME_CONFIG_MONGODB_SERVER=mongo
- ME_CONFIG_MONGODB_PORT=27017
- ME_CONFIG_MONGODB_ENABLE_ADMIN=false
- ME_CONFIG_MONGODB_AUTH_DATABASE=admin
- ME_CONFIG_MONGODB_AUTH_USERNAME=${MONGO_ROOT_USER}
- ME_CONFIG_MONGODB_AUTH_PASSWORD=${MONGO_ROOT_PASSWORD}
- ME_CONFIG_BASICAUTH_USERNAME=${MONGOEXPRESS_LOGIN}
- ME_CONFIG_BASICAUTH_PASSWORD=${MONGOEXPRESS_PASSWORD}
depends_on:
- mongo
ports:
- "8888:8081"
1 change: 0 additions & 1 deletion notes.md

This file was deleted.

13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"start": "ts-node-dev --respawn --transpile-only src/index.ts"
},
"devDependencies": {
"@types/bcrypt": "^5.0.0",
"@types/bcryptjs": "^2.4.2",
"@types/bcrypt": "^5.0.2",
"@types/config": "^3.3.0",
"@types/cookie-parser": "^1.4.3",
"@types/cors": "^2.8.13",
Expand All @@ -26,19 +25,19 @@
},
"dependencies": {
"@typegoose/typegoose": "^10.0.0",
"bcrypt": "^5.1.0",
"bcryptjs": "^2.4.3",
"bcrypt": "5.1.1",
"config": "^3.3.9",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"debug": "^4.3.4",
"dotenv": "^16.0.3",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"jsonwebtoken": "^9.0.0",
"lodash": "^4.17.21",
"mongoose": "^6.9.0",
"mongoose": "^6.8.0",
"redis": "^4.6.2",
"socket.io": "^4.6.0",
"socket.io": "^4.7.2",
"socketio": "^1.0.0",
"ts-node-dev": "^2.0.0",
"zod": "^3.20.2"
}
Expand Down
21 changes: 10 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import todoController from "./controllers/todo.controller";
import labelController from "./controllers/label.controller";

const app: Express = express();
dotenv.config({});
app.use(express.json());
app.use(cors());

const PORT = process.env.PORT || 8000;
if (process.env.DEBUG) {
process.on("unhandledRejection", function (reason) {
Expand All @@ -23,32 +23,31 @@ if (process.env.DEBUG) {
} else {
}

//routes
app.get("/", (req: Request, res: Response) => {
res.send("Fuck this world");
});
todoRoutes(app);
authRoutes(app);
todoRoutes(app);

const server: http.Server = http.createServer(app);

export const io = new Server(server);

const mongooseOptions = {
useNewUrlParser: true,
useUnifiedTopology: true,
serverSelectionTimeoutMS: 5000,
// // serverSelectionTimeoutMS: 5000,
// directConnection: true,
// useNewUrlParser: true,
// useUnifiedTopology: true,
user: process.env.MONGO_ROOT_USER, // MongoDB username
pass: process.env.MONGO_ROOT_PASSWORD, // MongoDB password
};

const MONGODB_URI = process.env.MONGODB_URI;

mongoose
.set("strictQuery", true)
.connect(MONGODB_URI!, mongooseOptions)
.connect(process.env.SERVER_URL ?? "", mongooseOptions)
.then(() => {
server.listen(PORT, () => {
console.log(`Server is running on ${PORT}`);

io.use((socket, next) => {
const token = socket.handshake.auth.auth_token;
// console.log("token is " + token);
Expand Down Expand Up @@ -105,5 +104,5 @@ mongoose
});
})
.catch((err) => {
console.log(`something fucked up `, err);
console.log(`something's fucked`, err);
});
2 changes: 1 addition & 1 deletion src/services/password.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import bcrypt from 'bcrypt';
import bcrypt from "bcrypt";

export class Password {
static toHash(password: string) {
Expand Down
5 changes: 5 additions & 0 deletions status.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
setting up docker worked
look into whether its important to use volums for persistent mongo db data storage
push docker build on dockerhub

[auth tut](https://codevoweb.com/node-typescript-mongodb-jwt-authentication/)
Loading

0 comments on commit 55e3bc2

Please sign in to comment.