diff --git a/app.js b/app.js index 483f4de..bbe0e00 100644 --- a/app.js +++ b/app.js @@ -15,7 +15,6 @@ app.use(express.static(path.join(__dirname, "public"))); try { const mongoDB = process.env.DB_URI || "mongodb://127.0.0.1:27017/a11y-req"; - //const mongoDB = 'mongodb://127.0.0.1:27017/a11y-req'; mongoose.connect(mongoDB, { useNewUrlParser: true, useUnifiedTopology: true, diff --git a/OLD-docker-compose.yml b/docker-compose.yml similarity index 56% rename from OLD-docker-compose.yml rename to docker-compose.yml index 9ad164a..d45a373 100644 --- a/OLD-docker-compose.yml +++ b/docker-compose.yml @@ -1,20 +1,26 @@ -# not to be used in production +# THIS IS NOT USED IN PRODUCTIOIN. +# IN PRODUCTION THE APP USES AZURE COSMOS DB and AZURE DEVOPS PIPELINE version: "3" services: a11y: build: . ports: - - 3000:80 + - 3000:3000 environment: - - MONGODB_URI=mongodb://mongo/a11y-req + - DB_URI=mongodb://mongo:27017/a11y-req - BASIC_AUTH_USERNAME=admin - BASIC_AUTH_PASSWORD=password - POPULATE_DB=$${POPULATE_DB} - WAIT_HOSTS=mongo:27017 - WAIT_FOR_MONGO=true + depends_on: + - mongo + mongo: - image: mongo:3.3 + image: mongo:4.4 + ports: + - "27017:27017" restart: always mongoexpress: @@ -22,4 +28,6 @@ services: restart: always ports: - 3005:8081 + depends_on: + - mongo diff --git a/local_Dockerfile b/local_Dockerfile new file mode 100644 index 0000000..3bd15f1 --- /dev/null +++ b/local_Dockerfile @@ -0,0 +1,82 @@ +# Rename this file to Dockerfile and run docker-compose up. +# Ideally, we should use a single Dockerfile for both local and production environments. However, since we don’t control the infrastructure, we need to maintain two separate Dockerfiles. For deployment, we’ll have to fall back on this dual Dockerfile approach. +FROM node:22 + +ENV NODE_ENV "production" +ENV POPULATE_DB "true" + +# Change me in production +ENV DB_URI "_DBURI_" +ENV BASIC_AUTH_USERNAME "_BASICAUTHUSERNAME_" +ENV BASIC_AUTH_PASSWORD "_BASICAUTHPASSWORD_" +ENV WAIT_FOR_MONGO "_WAITFORMONGO_" +ENV WAIT_HOSTS "_WAITHOSTS_" + +# Installing NGINX for reverse proxy +RUN apt update && \ + apt install -y nginx && \ + rm /etc/nginx/sites-available/default && \ + rm /etc/nginx/sites-enabled/default + +RUN apt-get install -y net-tools + +# Add the MongoDB repository and install the latest MongoDB +RUN wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | apt-key add - && \ + echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/debian bullseye/mongodb-org/6.0 main" | tee /etc/apt/sources.list.d/mongodb-org-6.0.list && \ + echo "deb http://deb.debian.org/debian bullseye main" > /etc/apt/sources.list.d/bullseye.list && \ + apt-get update && \ + apt-get install -y libssl1.1 && \ + apt-get install -y mongodb-org + +# dos2unix used to convert scripts written on windows systems to unix formats +RUN apt-get install -y dos2unix +RUN mkdir /home/app + +# install node process manager pm2 +RUN npm install -g pm2 + +WORKDIR /home/app +SHELL ["/bin/bash", "-c"] + +RUN wget -q https://fastdl.mongodb.org/tools/db/mongodb-database-tools-debian92-x86_64-100.0.2.tgz && \ + tar -xzf mongodb-database-tools-debian92-x86_64-100.0.2.tgz && \ + mv mongodb-database-tools-debian92-x86_64-100.0.2 mongotools && \ + chmod 777 ./mongotools/bin/mongorestore + +RUN apt-get install -y netcat +ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.2.1/wait ./wait +RUN chmod +x ./wait + +COPY ./nginx ./nginx + +# copying over nginx vhost to appropriate location and testing configuration +RUN dos2unix ./nginx/default.conf && \ + mv ./nginx/default.conf /etc/nginx/sites-enabled/default + +RUN dos2unix ./nginx/nginx.conf && \ + mv ./nginx/nginx.conf /etc/nginx/nginx.conf && \ + nginx -t + +RUN dos2unix ./nginx/mongodb.conf && \ + mv ./nginx/mongodb.conf /etc/mongodb.conf + +# copy over application files +COPY . . + +# install dependencies +RUN npm install + +RUN apt-get update && apt-get install -y vim +RUN apt-get update && apt-get install -y ssh +RUN echo "root:Docker!" | chpasswd +RUN mkdir /run/sshd +COPY sshd_config /etc/ssh/ + +RUN dos2unix ./scripts/start.sh + +# make startup script executable +RUN chmod 777 ./scripts/start.sh + +# make the script to be the entrypoint +ENTRYPOINT [ "/bin/bash", "scripts/start.sh" ] +EXPOSE 3000 443 2222