diff --git a/templates/mern/javascript/client/Dockerfile b/templates/mern/javascript/client/Dockerfile new file mode 100644 index 0000000..7f380af --- /dev/null +++ b/templates/mern/javascript/client/Dockerfile @@ -0,0 +1,20 @@ +# Use an official Node.js runtime as a parent image +FROM node:20-alpine + +# Set the working directory in the container +WORKDIR /usr/src/app + +# Copy package.json and package-lock.json to the working directory +COPY package*.json ./ + +# Install application dependencies +RUN npm install + +# Copy the rest of the application source code +COPY . . + +# The client app runs on port 3000, so we expose that +EXPOSE 3000 + +# Define the command to run the application +CMD [ "npm", "run", "dev" ] \ No newline at end of file diff --git a/templates/mern/javascript/client/package.json b/templates/mern/javascript/client/package.json index e96ee22..8af4c8e 100644 --- a/templates/mern/javascript/client/package.json +++ b/templates/mern/javascript/client/package.json @@ -4,7 +4,7 @@ "version": "0.0.0", "type": "module", "scripts": { - "dev": "vite", + "dev": "vite --host", "build": "vite build", "lint": "eslint .", "preview": "vite preview" diff --git a/templates/mern/javascript/docker-compose.yml b/templates/mern/javascript/docker-compose.yml new file mode 100644 index 0000000..8e7f9b7 --- /dev/null +++ b/templates/mern/javascript/docker-compose.yml @@ -0,0 +1,47 @@ +# Specifies the Docker Compose file format version +version: '3.8' + +# Defines the services (containers) that make up your app +services: + # The backend Express server + server: + # Tells Docker to build an image from the Dockerfile in the ./server directory + build: ./server + # Names the container so it's easy to identify + container_name: celtrix-mern-server + # Sets environment variables for the server, like the database connection string + environment: + - MONGO_URI=mongodb://mongodb:27017/celtrix-db + # Maps port 4000 on your computer to port 4000 in the container + ports: + - "4000:4000" + # Makes this service depend on the 'mongodb' service. It will wait for mongodb to start. + depends_on: + - mongodb + + # The frontend React client + client: + build: ./client + container_name: celtrix-mern-client + # Maps port 3000 on your computer to port 3000 in the container + ports: + - "3000:5173" + # Makes the client depend on the server, ensuring the backend starts first + depends_on: + - server + + # The MongoDB database + mongodb: + # Pulls the official MongoDB image from Docker Hub + image: mongo:latest + container_name: celtrix-mern-mongodb + # Maps the default MongoDB port + ports: + - "27017:27017" + # Creates a volume to persist database data even if the container is removed + volumes: + - mongo-data:/data/db + +# Defines a named volume for persisting database data +volumes: + mongo-data: \ No newline at end of file diff --git a/templates/mern/javascript/server/Dockerfile b/templates/mern/javascript/server/Dockerfile new file mode 100644 index 0000000..a7320d7 --- /dev/null +++ b/templates/mern/javascript/server/Dockerfile @@ -0,0 +1,20 @@ +# Use an official Node.js runtime as a parent image +FROM node:18-alpine + +# Set the working directory in the container +WORKDIR /usr/src/app + +# Copy package.json and package-lock.json to the working directory +COPY package*.json ./ + +# Install application dependencies +RUN npm install + +# Copy the rest of the application source code +COPY . . + +# Expose the port the app runs on +EXPOSE 4000 + +# Define the command to run the application +CMD [ "npm", "start" ] \ No newline at end of file