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

Fix Docker support for the app #88

Open
wants to merge 2 commits into
base: 2025
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 12 additions & 4 deletions OLD-docker-compose.yml → docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
# 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:
image: mongo-express
restart: always
ports:
- 3005:8081
depends_on:
- mongo

82 changes: 82 additions & 0 deletions local_Dockerfile
Original file line number Diff line number Diff line change
@@ -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