Skip to content
Merged
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
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.github/
.next/
.vscode/

node_modules/

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ yarn-error.log*
.env*.local
.env
.env.local
.env.production

# vercel
.vercel
Expand Down
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Build
FROM node:18-alpine AS builder
WORKDIR /app

COPY package*.json ./
COPY . .

RUN npm install
RUN cd src && npx prisma generate && cd ..
RUN npm run build

# Production stage
FROM node:18-alpine AS runner
WORKDIR /app

ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}

COPY --from=builder /app/next.config.ts ./
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/pnpm-lock.yaml ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/src ./src

EXPOSE 3000

CMD ["sh", "-c", "env | grep DATABASE && npm start"]
24 changes: 24 additions & 0 deletions docker-compose-init.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '3'

services:
nginx:
image: nginx:alpine
container_name: nginx-init
ports:
- '80:80'
volumes:
- certbot-www:/var/www/certbot
- ./nginx/init.conf:/etc/nginx/conf.d/default.conf
command: [nginx-debug, '-g', 'daemon off;']

certbot:
image: certbot/certbot
container_name: certbot
volumes:
- certbot-etc:/etc/letsencrypt
- certbot-www:/var/www/certbot
command: certonly --webroot -w /var/www/certbot --email minjing.chen.21@ucl.ac.uk --agree-tos --no-eff-email -d team3docker.uksouth.cloudapp.azure.com

volumes:
certbot-etc:
certbot-www:
59 changes: 59 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
services:
nextapp:
build:
context: .
dockerfile: Dockerfile
ports:
- '3000:3000'
container_name: nextapp
restart: always
env_file:
- .env.production
environment:
- NODE_ENV=production
depends_on:
- postgres
command: sh -c "cd src && npx prisma migrate deploy && npx prisma db seed && cd .. && npm start"
networks:
- app-network
volumes:
- ./src:/app/src

postgres:
image: postgres:15
container_name: postgres
restart: always
ports:
- '5432:5432'
env_file:
- .env.production
volumes:
- pgdata:/var/lib/postgresql/data
networks:
- app-network

nginx:
build: ./nginx
container_name: nginx-main
ports:
- '80:80'
- '443:443'
volumes:
- certbot-etc:/etc/letsencrypt
- certbot-www:/var/www/certbot
environment:
DOMAIN_NAME: team3docker.uksouth.cloudapp.azure.com
depends_on:
- nextapp
networks:
- app-network

networks:
app-network:

volumes:
pgdata:
certbot-etc:
name: comp0067_2025_team3_certbot-etc
certbot-www:
name: comp0067_2025_team3_certbot-www
5 changes: 5 additions & 0 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM nginx:alpine

COPY default.conf /etc/nginx/conf.d/default.conf

CMD ["nginx", "-g", "daemon off;"]
32 changes: 32 additions & 0 deletions nginx/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
server {
listen 80;
server_name team3docker.uksouth.cloudapp.azure.com;

location /.well-known/acme-challenge/ {
root /var/www/certbot;
}

location / {
return 301 https://$host$request_uri; # Corrected $request_url to $request_uri
}
}

server {
listen 443 ssl;
server_name team3docker.uksouth.cloudapp.azure.com;

ssl_certificate /etc/letsencrypt/live/team3docker.uksouth.cloudapp.azure.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/team3docker.uksouth.cloudapp.azure.com/privkey.pem;

location / {
proxy_pass http://nextapp:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
}
}
13 changes: 13 additions & 0 deletions nginx/init.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
server {
listen 80;
server_name team3docker.uksouth.cloudapp.azure.com;

location /.well-known/acme-challenge/ {
root /var/www/certbot;
}

location / {
return 200 'Init server is running!';
add_header Content-Type text/plain;
}
}
5 changes: 4 additions & 1 deletion src/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,10 @@ async function initialiseQuestions() {

async function main() {
await initialiseQuestions()
await initialiseUsersAndResponses()

if (process.env.NODE_ENV === 'development') {
await initialiseUsersAndResponses()
}
}

main()
Expand Down